Skip to content

Commit 482ee29

Browse files
committed
fix(grpc): Read method from handler_call_details for grpcio >= 1.76 compat
grpcio 1.76 introduced registered method handlers which resolve RPC methods at the C-core level. For these methods, `context._rpc_event.call_details.method` is empty, breaking tracing. This fix aligns the sync ServerInterceptor with the async version by: 1. Storing handler_call_details in intercept_service 2. Reading method from handler_call_details instead of context._rpc_event The async ServerInterceptor already uses this approach and works correctly. Fixes #5520
1 parent 594dce5 commit 482ee29

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sentry_sdk/integrations/grpc/server.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(
2222
self: "ServerInterceptor",
2323
find_name: "Optional[Callable[[ServicerContext], str]]" = None,
2424
) -> None:
25-
self._find_method_name = find_name or ServerInterceptor._find_name
25+
self._find_method_name = find_name or self._find_name
2626

2727
super().__init__()
2828

@@ -31,6 +31,7 @@ def intercept_service(
3131
continuation: "Callable[[HandlerCallDetails], RpcMethodHandler]",
3232
handler_call_details: "HandlerCallDetails",
3333
) -> "RpcMethodHandler":
34+
self._handler_call_details = handler_call_details
3435
handler = continuation(handler_call_details)
3536
if not handler or not handler.unary_unary:
3637
return handler
@@ -64,6 +65,9 @@ def behavior(request: "Message", context: "ServicerContext") -> "Message":
6465
response_serializer=handler.response_serializer,
6566
)
6667

67-
@staticmethod
68-
def _find_name(context: "ServicerContext") -> str:
69-
return context._rpc_event.call_details.method.decode()
68+
def _find_name(self: "ServerInterceptor", context: "ServicerContext") -> str:
69+
# type: ignore[override]
70+
# Read method from handler_call_details instead of context._rpc_event
71+
# because grpcio >= 1.76 returns empty method for registered handlers
72+
# via context._rpc_event.call_details.method
73+
return self._handler_call_details.method

0 commit comments

Comments
 (0)