ref(node): Stop mutating OTel RPC metadata to set http.route#21193
Open
mydea wants to merge 1 commit into
Open
ref(node): Stop mutating OTel RPC metadata to set http.route#21193mydea wants to merge 1 commit into
http.route#21193mydea wants to merge 1 commit into
Conversation
Where Sentry's HTTP framework integrations previously wrote `route` onto the OTel RPC-metadata context object, they now set the `http.route` attribute directly on the root `http.server` span via the new `setHttpServerSpanRouteAttribute` helper in `@sentry/node`. The helper guards on the root span being `op=http.server` so it's safe to call from any framework instrumentation. `@sentry/node-core`'s HTTP server-span integration continues to read RPC metadata at response time, so third-party OTel instrumentations that set it still get their route picked up. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
size-limit report 📦
|
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.
Summary
Sentry's framework instrumentations used to write the matched route by mutating OpenTelemetry's RPC-metadata context object (
getRPCMetadata(ctx).route = ...). The HTTP server-span integration then read that value at response time and copied it tohttp.routeon the span.This PR cuts out the middle step for our own write sites: instead of mutating RPC metadata, framework instrumentations now write
http.routedirectly onto the roothttp.serverspan via a small new helper,setHttpServerSpanRouteAttribute(route)in@sentry/node.@sentry/node-core's HTTP server-span integration still reads RPC metadata at response time, so any third-party OTel instrumentation that follows the upstream pattern (e.g.@opentelemetry/instrumentation-*) keeps working unchanged.What changed
packages/node/src/utils/setHttpServerSpanRouteAttribute.ts. Resolves the root span viagetActiveSpan/getRootSpan, guards onop === 'http.server'so it can't accidentally mutate non-HTTP root spans, and sets thehttp.routeattribute.packages/node/src/integrations/tracing/express.tspackages/node/src/integrations/tracing/fastify/v3/instrumentation.tspackages/node/src/integrations/tracing/fastify/vendored/instrumentation.tspackages/node/src/integrations/tracing/connect/vendored/instrumentation.tspackages/node/src/integrations/tracing/hapi/vendored/instrumentation.tspackages/node/src/integrations/tracing/koa/vendored/instrumentation.tspackages/react-router/src/server/createServerInstrumentation.tsandwrapSentryHandleRequest.tsalready sethttp.routeon the span directly; dropped the redundantrpcMetadata.route = ...(and the no-longer-needed@opentelemetry/api+@opentelemetry/coreimports there).Test updates
packages/react-router/test/server/{wrapSentryHandleRequest,getMetaTagTransformer}.test.tswere mocking@opentelemetry/core'sgetRPCMetadata. Mocks and theRPCTypeimport are removed; the assertions now just verify the span-attribute path that was already being asserted.🤖 Generated with Claude Code