ref(node): Stop mutating OTel RPC metadata to set `http.route` (#21193)
## 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](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> F
Francesco Gringl-Novy committed
a48e4e9774998da99fe0cc42cc60c6d6bbff7b5d
Parent: 4a73176
Committed by GitHub <noreply@github.com>
on 5/29/2026, 6:32:48 AM