Repository navigation
feat(nextjs): Emit the tunnel route handler - #25424
Conversation
size-limit report 📦Compared: 02b3743 (PR test merge using develop at 1873c1d) Against: 1873c1d (develop) · base run #65687 ✅ Baseline matches: this diff contains only this PR's changes.
|
|
bugbot run |
0bd8edd to
a0d5655
Compare
|
bugbot run |
a0d5655 to
bff33ce
Compare
|
bugbot run |
bff33ce to
61392db
Compare
|
bugbot run |
5472088 to
ae51678
Compare
ae51678 to
9c50125
Compare
9c50125 to
e94f25d
Compare
e94f25d to
efc9b07
Compare
efc9b07 to
2e8e2b3
Compare
2e8e2b3 to
2c6c3d8
Compare
5bc562c to
ef27f39
Compare
Optional E2E testsSome optional checks were not successful. They do not block the merge. 4 not successful, 53 successful. See the run.
Successful checks
|
|
One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check. |
…equest` The tunnel route handler now leaves DSN normalization, the allowlist and tracing suppression to core. As in every other SDK, `allowedDsns` adds to the server's own DSN, and the default `POST` accepts the DSNs `serveTunnelIntegration` allows.
…ePath` `tunnel: true` in the browser now sends to `<basePath>/<hash>`, like the SvelteKit and React Router SDKs do with their base paths. A `basePath` the user set and a `tunnel` URL stay as written.
…the server `withSentryConfig` now injects `basePath` into production server and edge builds, not only in dev, and the server, edge and Cloudflare inits pass it to `setManagedTunnelDefaults`. `serveTunnelIntegration` then matches `/<basePath>/<hash>`, like the browser sends.
Vercel serves unknown paths from its CDN without running the app, so the runtime never sees managed tunnel requests there. On Vercel builds without `tunnelRoute`, `withSentryConfig` writes the tunnel route handler and rewrites envelope requests to the DSN-derived paths there. The handler answers only when `serveTunnelIntegration` is set up, and on a cold start too. Pages Router apps get an `app` directory with only this route.
`tunnel: true` in the browser and `serveTunnelIntegration` on the server serve the tunnel on every Next.js deployment, so `tunnelRoute` and the `@sentry/nextjs/tunnel` route handlers are deprecated. `withSentryConfig` warns when `tunnelRoute` is set.
With `trailingSlash: true` Next redirected the browser's POST to the tunnel path without the slash.
…and preview builds
The deprecated `tunnelRoute` now turns on the managed tunnel, like `tunnel: true` with `serveTunnelIntegration()`: a string is its fixed path, `true` the path derived from the DSN. The proxy rewrite to sentry.io, which forwarded every header including cookies, and the handler mode rewrite are gone. On Vercel, the generated route also serves the fixed path.
The route `withSentryConfig` generates on Vercel re-exports it, so it stays.
…ercel tunnel route A fixed tunnel `path` set in `Sentry.init` now reaches the route on Vercel too, without `tunnelRoute`. The envelope content type keeps other requests out, and the handler forwards only envelopes for allowed DSNs.
…t type The browser sends `application/x-sentry-envelope` only for a managed tunnel given as `true` or options. A fixed path injected as a string went out as `text/plain`, which the Vercel rewrite doesn't match.
…erived from the DSN The Next.js span filters only knew a fixed `tunnelRoute` path, and the `url.path` filters of the managed tunnel don't match Next.js request spans, which carry only `http.target` at start. A proxy that runs outside of the server, like on Vercel, sent its spans of tunnel requests. The filters now come from the paths the client serves.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a128721. Configure here.

This overhauls the tunnel implementation of Next.js by doing a few things:
omitfor the transport options.The way it works varies depeding on how the user deploys their application.
On Conventional Servers/Platforms
Our runtime patchers introduced in this stack handle the tunnel request, the user's Next.js app never handles any of these.
On Vercel
We utilize the two-hop idea we did in #25456 by writing a small idempotent app router file. The re-write rules move traffic to the new handler, and the file exports a
POSThandler for the route.Vercel applies certain rules and responds with 404 for tunnel requests that aren't present in re-writes or app router, so our runtime patchers will never trigger. Which is why this workaround was needed.
For everyone else, the runtime patchers will work.