Skip to content

Commit 8566650

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 captures `handler_call_details.method` in the closure scope to avoid both the grpcio 1.76 issue and race conditions from shared instance state in the ThreadPoolExecutor. Fixes #5520
1 parent 594dce5 commit 8566650

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

sentry_sdk/integrations/grpc/server.py

Lines changed: 5 additions & 6 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._custom_find_name = find_name
2626

2727
super().__init__()
2828

@@ -35,9 +35,12 @@ def intercept_service(
3535
if not handler or not handler.unary_unary:
3636
return handler
3737

38+
method_name = handler_call_details.method
39+
custom_find_name = self._custom_find_name
40+
3841
def behavior(request: "Message", context: "ServicerContext") -> "Message":
3942
with sentry_sdk.isolation_scope():
40-
name = self._find_method_name(context)
43+
name = custom_find_name(context) if custom_find_name else method_name
4144

4245
if name:
4346
metadata = dict(context.invocation_metadata())
@@ -63,7 +66,3 @@ def behavior(request: "Message", context: "ServicerContext") -> "Message":
6366
request_deserializer=handler.request_deserializer,
6467
response_serializer=handler.response_serializer,
6568
)
66-
67-
@staticmethod
68-
def _find_name(context: "ServicerContext") -> str:
69-
return context._rpc_event.call_details.method.decode()

0 commit comments

Comments
 (0)