Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions sentry_sdk/integrations/grpc/aio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(
self: "ServerInterceptor",
find_name: "Callable[[ServicerContext], str] | None" = None,
) -> None:
self._find_method_name = find_name or self._find_name
self._custom_find_name = find_name

super().__init__()

Expand All @@ -34,17 +34,21 @@ async def intercept_service(
continuation: "Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler]]",
handler_call_details: "HandlerCallDetails",
) -> "Optional[Awaitable[RpcMethodHandler]]":
self._handler_call_details = handler_call_details
handler = await continuation(handler_call_details)
if handler is None:
return None

method_name = handler_call_details.method
custom_find_name = self._custom_find_name

if not handler.request_streaming and not handler.response_streaming:
handler_factory = grpc.unary_unary_rpc_method_handler

async def wrapped(request: "Any", context: "ServicerContext") -> "Any":
with sentry_sdk.isolation_scope():
name = self._find_method_name(context)
name = (
custom_find_name(context) if custom_find_name else method_name
)
if not name:
return await handler(request, context)

Expand Down Expand Up @@ -96,6 +100,3 @@ async def wrapped(request: "Any", context: "ServicerContext") -> "Any": # type:
request_deserializer=handler.request_deserializer,
response_serializer=handler.response_serializer,
)

def _find_name(self, context: "ServicerContext") -> str:
return self._handler_call_details.method
Loading