Skip to content

Send trace context from middleware so pageloads connect on Vercel #24947

Description

@chargome

Background

On Vercel the cached shell is served by the CDN without running app code. The server function only renders the fresh part, and response headers were already sent with the shell. So a Server-Timing header set by the function never reaches the browser.

Middleware runs before the CDN cache on every request, so it is the one place on Vercel that can add a header to every response.

What this ticket does

  1. Spike on a real Vercel deployment. Confirm that:
    • a Server-Timing header set by middleware reaches the browser when the shell comes from the CDN
    • a sentry-trace request header set by middleware reaches the server function (via NextResponse.next({ request: { headers } }))
  2. If both hold, extend wrapMiddlewareWithSentry to add the Server-Timing response header and forward sentry-trace and baggage to the downstream request.

The middleware span starts the trace, the server render joins it through the forwarded header, and the pageload joins it through the response header.

Caveat

Only works for apps with a proxy.ts file. Document a one-line empty proxy as the opt-in.

If the spike fails, write down what was tested and why, and close the ticket.

Activity

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

Metadata

Metadata

Assignees

Labels

javascriptPull requests that update javascript code

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions