Skip to content

opentelemetry-instrumentation-grpc: respect suppressed instrumentation in server interceptors - #4870

Open
jojinkb wants to merge 1 commit into
open-telemetry:mainfrom
jojinkb:fix-grpc-suppress-instrumentation
Open

opentelemetry-instrumentation-grpc: respect suppressed instrumentation in server interceptors#4870
jojinkb wants to merge 1 commit into
open-telemetry:mainfrom
jojinkb:fix-grpc-suppress-instrumentation

Conversation

@jojinkb

@jojinkb jojinkb commented Jul 25, 2026

Copy link
Copy Markdown

Description

The gRPC server interceptors create SERVER spans even when instrumentation is suppressed in the current context. The client-side interceptors were fixed in #559; this applies the same is_instrumentation_enabled() check to OpenTelemetryServerInterceptor and OpenTelemetryAioServerInterceptor, so intercept_service skips the telemetry wrapper and returns the original handler while _SUPPRESS_INSTRUMENTATION_KEY is set.

The check runs per-RPC at handler-resolution time, before the existing filter check. Suppressing from inside a servicer method (after the span has started) is a separate design question raised in the issue thread and is intentionally out of scope.

Fixes #476

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added tests for the sync and asyncio servers (unary and server-streaming) that run an RPC through a real test server with a preceding interceptor that suppresses instrumentation for the rest of the interceptor chain, and assert that no spans are exported. All six new test cases fail without this change.

  • pytest instrumentation/opentelemetry-instrumentation-grpc/tests — 156 passed, on Python 3.12 against grpcio 1.62.0 and 1.75.1, wrapt 1.17.3 and 2.1.2
  • ruff check / ruff format --check (0.14.1) clean on changed files; pylint --rcfile .pylintrc opentelemetry-instrumentation-grpc (4.0.5) 10.00/10

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

…n in server interceptors

Check is_instrumentation_enabled() in the sync and asyncio server
interceptors before wrapping RPC handlers with telemetry, so no server
spans are created while instrumentation is suppressed in the current
context. This mirrors the client-side check added in open-telemetry#559 and covers
the remaining server half of open-telemetry#476.

Signed-off-by: Jojin <jojin.kb@gmail.com>
@jojinkb
jojinkb requested a review from a team as a code owner July 25, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

gRPC instrumentation not checking for suppress_instrumentation in context

1 participant