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
- 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 } }))
- 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.
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-Timingheader 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
Server-Timingheader set by middleware reaches the browser when the shell comes from the CDNsentry-tracerequest header set by middleware reaches the server function (viaNextResponse.next({ request: { headers } }))wrapMiddlewareWithSentryto add theServer-Timingresponse header and forwardsentry-traceandbaggageto 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.tsfile. 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.