Skip to content

gRPC sync ServerInterceptor._find_name broken with grpcio >= 1.76 #5520

@yeung108

Description

@yeung108

Problem

The sync ServerInterceptor._find_name in sentry_sdk/integrations/grpc/server.py is broken with grpcio >= 1.76.

Root Cause

grpcio 1.76 introduced registered method handlers (add_registered_method_handlers) which resolve RPC methods at the C-core level by tag. For these registered methods:

  • context._rpc_event.call_details.methodempty (the Cython-compiled cygrpc._ServicerContext doesn't populate this field)
  • handler_call_details.methodalways populated (set by grpcio's _find_method_handler)

The current sync implementation reads from the empty field:

@staticmethod
def _find_name(context: "ServicerContext") -> str:
    return context._rpc_event.call_details.method.decode()

Impact

When _find_name returns an empty string, no Sentry transaction is created, meaning:

  • No traces
  • No spans
  • No trace ID in logs

The exception from accessing the empty method is caught by upstream interceptors, so requests still succeed — but tracing is silently broken.

The Fix Already Exists in Async Version

The async version (sentry_sdk/integrations/grpc/aio/server.py) already uses the correct approach:

async def intercept_service(self, continuation, handler_call_details):
    self._handler_call_details = handler_call_details  # Stores it
    # ...

def _find_name(self, context: "ServicerContext") -> str:
    return self._handler_call_details.method  # Reads from stored details

Suggested Fix

Align the sync version with the async implementation:

  1. Store handler_call_details in intercept_service
  2. Change _find_name from @staticmethod to instance method
  3. Read from self._handler_call_details.method

Environment

  • sentry-sdk version: 2.52.0 (and earlier)
  • grpcio version: >= 1.76.0
  • Python version: 3.12

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions