opentelemetry-instrumentation-grpc: respect suppressed instrumentation in server interceptors - #4870
Open
jojinkb wants to merge 1 commit into
Open
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 toOpenTelemetryServerInterceptorandOpenTelemetryAioServerInterceptor, sointercept_serviceskips the telemetry wrapper and returns the original handler while_SUPPRESS_INSTRUMENTATION_KEYis 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
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.2ruff check/ruff format --check(0.14.1) clean on changed files;pylint --rcfile .pylintrc opentelemetry-instrumentation-grpc(4.0.5) 10.00/10Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.