Skip to content

Next.js: Connect proxy and render by emitting and accepting traceparent in the trace handover #27064

Backlog

Description

@chargome

Since Next.js 16.4.3 the proxy hands its trace context to the render (vercel/next.js#100294). With the Sentry SDK this handover does nothing, so a document request still produces two traces: one for the proxy and one for the render and pageload.

Why

  • The proxy adapter calls propagation.inject() and keeps only traceparent and tracestate. It forwards them to the render as request header overrides.
  • SentryPropagator.inject writes traceparent only when propagateTraceparent is enabled. By default Next.js gets nothing to forward.
  • SentryPropagator.extract reads only sentry-trace and baggage. A forwarded traceparent would be ignored.

In a production app on Next.js 16.4.5, every sampled trace that starts at a Next.request root contains exactly one segment. The render never joins.

To do

  • Emit traceparent when Next.js asks for the trace context. Limit it to the case where the active span is a Next.js request span (Next.request, BaseServer.handleRequest), so outgoing requests are not affected.
  • Accept traceparent on extract when no sentry-trace header is present. sentryTraceFromTraceparent in @sentry/core already does the conversion.
  • Apply both on the Node.js and the edge SDK.
  • Cover it with the E2E assertions from Next.js: Verify the new single-trace shape for proxy/middleware requests and cover it in E2E #26980 (shared trace ID, parent span ID).

Expected result

GET (Next.request, root)
 ├─ middleware GET
 └─ GET /page
     └─ pageload
Agent notes
  • Next.js side: packages/next/src/server/web/adapter.ts, forward-trace-context.ts, and getTraceContextHeaders in server/lib/trace/tracer.ts.
  • SDK side: packages/opentelemetry/src/propagator.ts.
  • On next start, Next.js writes the context onto the request in its middleware pass, using the same getTraceContextHeaders call. The same fix should apply, but this was not measured.

Activity

  1. linear-code commented on Dec 2, 2026

    @linear-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions