Skip to content

The documented interceptor order puts Sentry outside the exception handler; sentry.py and the dishka provider put it inside #49

Closed

Description

@AlexeyShalaev

Version: grpc-server-kit 0.2.0.

The module docstring of grpc_server_kit/aio/interceptors/__init__.py gives the "canonical execution order (outermost first)" as:

5. AsyncSentryInterceptor             (error tracking)
6. AsyncExceptionHandlerInterceptor   (exception → gRPC status mapping)

That puts Sentry outside the exception handler. The rest of the package says the opposite:

  • AsyncSentryInterceptor's docstring: "Place this interceptor INSIDE the exception handler in the chain (later in the interceptor list) so it observes raw handler exceptions before they are mapped into grpc.aio.AbortError."
  • GrpcServerInterceptorsProvider (aio/dishka/interceptors.py) appends the exception handler first and Sentry after it, with a comment saying why.

Following the module docstring loses error reports: with Sentry outside, the reporter only sees the AbortError the handler produced, never the original exception. We reproduced this against a real server: an internal ValueError reaches the client as INTERNAL, and the reporter captures nothing.

Fix

Swap items 5 and 6 in the module docstring, ideally with the reason ("inside the handler, so it sees the original exception").

Activity

  1. AlexeyShalaev commented on Oct 16, 2026

    @AlexeyShalaev
    MemberAuthor

    Confirmed. I went through every place that states the order: the AsyncSentryInterceptor docstring, GrpcServerInterceptorsProvider, the README, the quickstart, interceptors and observability guides, docs/agents.md and examples/observability_chain.py all put Sentry inside the exception handler. The module docstring of grpc_server_kit/aio/interceptors/__init__.py is the only one that disagrees.

    Plan:

    • Swap items 5 and 6 there and add the reason in one line (inside the handler, so it sees the original exception, not the AbortError the handler turns it into).
    • Add a unit test that reads the numbered list out of the module docstring and compares it with the chain GrpcServerInterceptorsProvider actually builds. It fails on master. The docstring and the provider drifted apart once already; this keeps them together.

    Not doing anything beyond that: the code and the rest of the docs are right, so this stays a docs: change.

  2. AlexeyShalaev commented on Oct 16, 2026

    @AlexeyShalaev
    MemberAuthor

    Fixed in #51: items 5 and 6 are swapped, with a line on why Sentry sits inside the handler. A unit test now compares the numbered list in the module docstring with the chain GrpcServerInterceptorsProvider builds, so the two can't drift apart again. The rest of the docs already had the right order.

  3. added a commit that references this issue on Oct 16, 2026
    d2f6181
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions