Skip to content

Commit 7be1306

Browse files
committed
Set nicer transaction name for async server interceptor
1 parent afacd37 commit 7be1306

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

sentry_sdk/integrations/grpc/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ def patched_aio_server(
127127
interceptors: Optional[Sequence[grpc.ServerInterceptor]] = None,
128128
**kwargs: P.kwargs,
129129
) -> Server:
130-
server_interceptor = AsyncServerInterceptor(
131-
find_name=lambda request: request.__class__
132-
)
130+
server_interceptor = AsyncServerInterceptor()
133131
interceptors = [server_interceptor, *(interceptors or [])]
134132
return func(*args, interceptors=interceptors, **kwargs) # type: ignore
135133

sentry_sdk/integrations/grpc/aio/server.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
class ServerInterceptor(grpc.aio.ServerInterceptor): # type: ignore
2222
def __init__(self, find_name=None):
2323
# type: (ServerInterceptor, Callable[[ServicerContext], str] | None) -> None
24-
self._find_method_name = find_name or ServerInterceptor._find_name
24+
self._find_method_name = find_name or self._find_name
2525

2626
super(ServerInterceptor, self).__init__()
2727

2828
async def intercept_service(self, continuation, handler_call_details):
2929
# type: (ServerInterceptor, Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler]], HandlerCallDetails) -> Awaitable[RpcMethodHandler]
30+
self._handler_call_details = handler_call_details
3031
handler = await continuation(handler_call_details)
3132

3233
if not handler.request_streaming and not handler.response_streaming:
@@ -89,7 +90,5 @@ async def wrapped(request, context): # type: ignore
8990
response_serializer=handler.response_serializer,
9091
)
9192

92-
@staticmethod
93-
def _find_name(context):
94-
# type: (ServicerContext) -> str
95-
return context._rpc_event.call_details.method.decode()
93+
def _find_name(self, context):
94+
return self._handler_call_details.method

0 commit comments

Comments
 (0)