Skip to content

GRPC client_interceptor does not allow the user to cancel streamed responses #2014

@bkrmalick

Description

@bkrmalick

Environment
Python 3.9
opentelemetry-sdk 1.20.0
opentelemetry-instrumentation 0.41b0
opentelemetry-instrumentation-grpc 0.41b0
grpcio = "==1.48.2 || ==1.49.1"

Steps to reproduce

import grpc
from opentelemetry.instrumentation.grpc import client_interceptor

chan = grpc.insecure_channel(MY_GRPC_SERVICE_ADDRESS)
chan = intercept_channel(chan, client_interceptor()))

response = chan.MyStreamRPC(....)  # Server streamed RPC where the client sends a request to the server and gets a stream to read a sequence of messages back.

for idx, item in enumerate(response):
      print(item)
      if idx == 4:
           response.cancel() # this works with standard grpc but throws an attribute error when the otel client_interceptor is added above
      
chan.close()

What is the expected behavior?
Being able to cancel the streamed response client side part-way

What is the actual behavior?
Throws an attribute error

Additional context
The interceptor seems to be modifying the return type for streamed rpc responses to be of type of standard generator

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions