Skip to content

gRPC: only first created channel is instrumented? #5183

@aburch

Description

@aburch

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.46.0

Steps to Reproduce

  1. Enable Sentry's GRPCIntegration()
  2. Create multiple gRPC channels with channel = grpc.secure_channel(...) (e.g., for talking to different services) within a single application.
  3. Do gRPC calls over these channels.

Expected Result

All gRPC calls are instrumented and show up in traces.

Actual Result

Spans are only created for some gRPC calls. Distributed tracing also does not work correctly, that is, the traces on the gRPC server are not connected with the gRPC client (in a Django app).

I suspect the problem is in the gRPC instumentation code:

@wraps(func)
def patched_channel(*args: Any, **kwargs: Any) -> Channel:
channel = func(*args, **kwargs)
if not ClientInterceptor._is_intercepted:
ClientInterceptor._is_intercepted = True
return intercept_channel(channel, ClientInterceptor())
else:
return channel

The global variable ClientInterceptor._is_intercepted is used to do instrumentation only once. But this way only the first gRPC channel created will be instrumented: from the second secure_channel(...) call on, this variable is already true and instrumentation will be skipped.

I guess this is to avoid adding the interceptor twice when using grpc.secure_channel and grpc.intercept_channel? The integration does not use the ClientInterceptor._is_intercepted global variable for instrumenting grpc.aio.secure_channel after all.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions