Skip to content

ref(node): Stop mutating OTel RPC metadata to set http.route#21193

Open
mydea wants to merge 1 commit into
developfrom
fn/drop-rpc-metadata-writes
Open

ref(node): Stop mutating OTel RPC metadata to set http.route#21193
mydea wants to merge 1 commit into
developfrom
fn/drop-rpc-metadata-writes

Conversation

@mydea
Copy link
Copy Markdown
Member

@mydea mydea commented May 27, 2026

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 to http.route on the span.

This PR cuts out the middle step for our own write sites: instead of mutating RPC metadata, framework instrumentations now write http.route directly onto the root http.server span 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

  • Added packages/node/src/utils/setHttpServerSpanRouteAttribute.ts. Resolves the root span via getActiveSpan / getRootSpan, guards on op === 'http.server' so it can't accidentally mutate non-HTTP root spans, and sets the http.route attribute.
  • Switched the following Sentry-owned and vendored framework instrumentations to use it instead of writing to RPC metadata:
    • packages/node/src/integrations/tracing/express.ts
    • packages/node/src/integrations/tracing/fastify/v3/instrumentation.ts
    • packages/node/src/integrations/tracing/fastify/vendored/instrumentation.ts
    • packages/node/src/integrations/tracing/connect/vendored/instrumentation.ts
    • packages/node/src/integrations/tracing/hapi/vendored/instrumentation.ts
    • packages/node/src/integrations/tracing/koa/vendored/instrumentation.ts
  • packages/react-router/src/server/createServerInstrumentation.ts and wrapSentryHandleRequest.ts already set http.route on the span directly; dropped the redundant rpcMetadata.route = ... (and the no-longer-needed @opentelemetry/api + @opentelemetry/core imports there).

Test updates

packages/react-router/test/server/{wrapSentryHandleRequest,getMetaTagTransformer}.test.ts were mocking @opentelemetry/core's getRPCMetadata. Mocks and the RPCType import are removed; the assertions now just verify the span-attribute path that was already being asserted.

🤖 Generated with Claude Code

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>
@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.27 kB - -
@sentry/browser - with treeshaking flags 25.69 kB - -
@sentry/browser (incl. Tracing) 45.25 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.49 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.23 kB - -
@sentry/browser (incl. Tracing, Replay) 84.86 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.36 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.57 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.18 kB - -
@sentry/browser (incl. Feedback) 44.46 kB - -
@sentry/browser (incl. sendFeedback) 32.09 kB - -
@sentry/browser (incl. FeedbackAsync) 37.21 kB - -
@sentry/browser (incl. Metrics) 28.37 kB - -
@sentry/browser (incl. Logs) 28.59 kB - -
@sentry/browser (incl. Metrics & Logs) 29.29 kB - -
@sentry/react 29.01 kB - -
@sentry/react (incl. Tracing) 47.49 kB - -
@sentry/vue 32.19 kB - -
@sentry/vue (incl. Tracing) 47.12 kB - -
@sentry/svelte 27.3 kB - -
CDN Bundle 29.68 kB - -
CDN Bundle (incl. Tracing) 47.78 kB - -
CDN Bundle (incl. Logs, Metrics) 31.17 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.03 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.48 kB - -
CDN Bundle (incl. Tracing, Replay) 85.28 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.43 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.15 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.31 kB - -
CDN Bundle - uncompressed 87.69 kB - -
CDN Bundle (incl. Tracing) - uncompressed 144.15 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 92.18 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 147.91 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 216.91 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.93 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.67 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 276.62 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 280.36 kB - -
@sentry/nextjs (client) 49.98 kB - -
@sentry/sveltekit (client) 45.73 kB - -
@sentry/core/server 76.42 kB - -
@sentry/core/browser 63.17 kB - -
@sentry/node-core 62.26 kB - -
@sentry/node 130.63 kB -0.08% -101 B 🔽
@sentry/node - without tracing 74.7 kB +0.01% +1 B 🔺
@sentry/aws-serverless 86.91 kB +0.01% +1 B 🔺
@sentry/cloudflare (withSentry) - minified 172.42 kB - -
@sentry/cloudflare (withSentry) 430.68 kB - -

View base workflow run

@mydea mydea marked this pull request as ready for review May 27, 2026 14:25
@mydea mydea requested review from a team as code owners May 27, 2026 14:25
@mydea mydea requested review from JPeer264, andreiborza, nicohrubec and s1gr1d and removed request for a team May 27, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant