Skip to content

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

Open
jojinkb wants to merge 3 commits into
open-telemetry:mainfrom
jojinkb:fix-grpc-suppress-instrumentation
Open

opentelemetry-instrumentation-grpc: respect suppressed instrumentation in server interceptors#4870
jojinkb wants to merge 3 commits 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
@emdneto emdneto moved this to Ready for review in Python PR digest Jul 31, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Approved PRs in Python PR digest Jul 31, 2026
@emdneto emdneto moved this from Approved PRs to Ready for merge in Python PR digest Jul 31, 2026
@github-project-automation github-project-automation Bot moved this from Ready for merge to Approved PRs in Python PR digest Jul 31, 2026
@aabmass
aabmass enabled auto-merge July 31, 2026 16:29
@aabmass
aabmass added this pull request to the merge queue Jul 31, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

gRPC instrumentation not checking for suppress_instrumentation in context

3 participants