Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make async gRPC less noisy #2507

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion sentry_sdk/integrations/grpc/aio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
try:
import grpc
from grpc import HandlerCallDetails, RpcMethodHandler
from grpc.aio import ServicerContext
from grpc.aio import AbortError, ServicerContext

Check warning on line 16 in sentry_sdk/integrations/grpc/aio/server.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/grpc/aio/server.py#L16

Added line #L16 was not covered by tests
except ImportError:
raise DidNotEnable("grpcio is not installed")

Expand Down Expand Up @@ -52,6 +52,8 @@
with hub.start_transaction(transaction=transaction):
try:
return await handler.unary_unary(request, context)
except AbortError:
raise

Check warning on line 56 in sentry_sdk/integrations/grpc/aio/server.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/grpc/aio/server.py#L56

Added line #L56 was not covered by tests
except Exception as exc:
event, hint = event_from_exception(
exc,
Expand Down
18 changes: 18 additions & 0 deletions tests/integrations/grpc/test_grpc_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ async def test_grpc_server_exception(capture_events, grpc_server):
assert event["exception"]["values"][0]["mechanism"]["type"] == "grpc"


@pytest.mark.asyncio
async def test_grpc_server_abort(capture_events, grpc_server):
events = capture_events()

async with grpc.aio.insecure_channel("localhost:{}".format(AIO_PORT)) as channel:
stub = gRPCTestServiceStub(channel)
try:
await stub.TestServe(gRPCTestMessage(text="abort"))
raise AssertionError()
except Exception:
pass

assert len(events) == 1


@pytest.mark.asyncio
async def test_grpc_client_starts_span(
grpc_server, sentry_init, capture_events_forksafe
Expand Down Expand Up @@ -218,6 +233,9 @@ async def TestServe(cls, request, context): # noqa: N802
if request.text == "exception":
raise cls.TestException()

if request.text == "abort":
await context.abort(grpc.StatusCode.ABORTED)

return gRPCTestMessage(text=request.text)

@classmethod
Expand Down
Loading