Repository navigation
Conversation
Since Next.js 16.4.3, the proxy hands its trace over to the render in the W3C `traceparent` and `tracestate` request headers. The SDK now writes and reads this hand-off, so the render segment becomes a child of the proxy segment, with `next start` and where the proxy runs on its own (Vercel). Fixes #26980 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
size-limit report 📦Compared: 990c723 (PR test merge using develop at 29e62cd) Against: 1c10c6f (develop) · base run #68574
|
|
@sentry-junior review |
Optional E2E testsAll optional checks were successful. 7 successful. See the run. Successful checks
|
A browser trace with Replay needs about 290 characters of dynamic sampling context, more than one tracestate entry may hold. Instead of dropping keys, split it into entries of at most 128 characters, which vendors keep when they truncate tracestate. A missing entry continues the trace without it. Refs #26980 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
||
| /** @inheritDoc */ | ||
| public extract(ctx: Context, carrier: unknown, getter: TextMapGetter): Context { | ||
| const handOff = extractTraceHandOff(getter.get(carrier, 'traceparent'), getter.get(carrier, 'tracestate')); |
There was a problem hiding this comment.
[m] packages/nextjs/src/server/nextSentryPropagator.ts:76: A proxy that forwards its request headers reparents the downstream service
In next start, the middleware-invoke pass writes the hand-off traceparent/tracestate onto req.headers before the proxy runs, so they are in the proxy's request.headers. If the proxy does fetch(url, { headers: request.headers }) (or rewrites) to another service running @sentry/nextjs, the hand-off survives: Sentry's outgoing fetch instrumentation adds sentry-trace, but it never overwrites an existing traceparent and never touches tracestate (packages/node/src/utils/outgoingFetchRequest.ts:98, packages/core/src/fetch.ts:233). The downstream extract then prefers the hand-off over the sentry-trace of the http.client span, as the test prefers the hand-off over an incoming sentry-trace header asserts. The result is that the downstream request gets parented to the upstream BaseServer.handleRequest span instead of the outgoing request span. That also goes against the description line "only continues a traceparent that carries that entry, so incoming traces from other services behave as before".
With next start, the hand-off is on the request headers the proxy sees. A proxy that forwards them to another service sent the hand-off along with the sentry-trace of its outgoing request, and the service continued the hand-off. The hand-off now names the parent of the proxy span, and a sentry-trace other than that parent wins over it. Refs #26980 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
With Next.js 16.4.3 and later, a request that goes through the proxy now ends up in one trace, with
next startand where the proxy runs on its own, such as on Vercel. When the request brings no trace, as for a page load,
the proxy's root span now also parents the render. With an incoming trace, proxy and render continue it as
siblings, as before.
A request through the proxy on Vercel, in Sentry: the render (
GET /api/endpoint-behind-proxy) is a child of the proxy's root span, next to the middleware span.Why
Since 16.4.3, Next.js hands the proxy's trace to the render only in the W3C
traceparentandtracestateheaders, which the SDK neither wrote nor read, so proxy and render ended up in two traces. The SDK now puts
the Sentry trace and sampling context in its own
tracestateentries and only continues atraceparentthatcarries them, so incoming traces from other services behave as before.
A browser trace with Replay needs about 290 characters of sampling context, more than one
tracestateentrymay hold (256). Instead of dropping keys, the SDK splits it into entries of at most 128 characters, which the
spec says vendors keep longest when they truncate the header. If an entry gets lost, the render continues the
trace without the sampling context. Not covered: edge-runtime middleware, and custom adapters that run the
proxy under a span of their own.
Closes: #26980