-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(nextjs): universal random tunnel path support #18257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
fix(nextjs): universal random tunnel path support #18257
Conversation
a230c8b to
dd615c6
Compare
size-limit report 📦
|
795af30 to
f787df1
Compare
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
4fab2f0 to
856a4d1
Compare
dev-packages/e2e-tests/test-applications/nextjs-16-tunnel/tests/tunnel-route.test.ts
Dismissed
Show dismissed
Hide dismissed
d5442a6 to
b332e39
Compare
b332e39 to
981121c
Compare
| }) satisfies EventProcessor, | ||
| { id: 'NextLowQualityTransactionsFilter' }, | ||
| ), | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Edge runtime missing tunnel route transaction filter
The event processor on the edge runtime only filters transactions based on the TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION attribute, but lacks the explicit tunnel route transaction name check present in the server-side event processor. This asymmetry creates a defensive gap: if span marking fails for any reason, server-side transactions are still filtered by name, but edge-side transactions would slip through. For consistency and robustness, the edge-side event processor should include the same explicit tunnel route check that filters POST requests to the tunnel path.
When using Next.js with Turbopack and the Sentry tunnel route feature (
tunnelRoute: true), several issues prevented events from being sent properly:1. Tunnel Route Consistency (Turbopack)
Problem: Random tunnel routes were generated separately for client and server builds in Turbopack.
Solution: Implemented processs-level caching in
withSentryConfig.ts:resolveTunnelRoute()functionprocess.envto store the random tunnel value across server/client builds.2. Filter Tunnel Request Spans
Problem: Requests to the tunnel route (before rewrite) and to Sentry ingest URLs (after rewrite) were creating spans that polluted Sentry with internal instrumentation noise, spans were being created by the middleware and OTEL node.js fetch instrumentation.
Solution: Implemented server-side span filtering:
dropMiddlewareTunnelRequests()utility to detect and drop tunnel-related spansMiddleware.execute(Next.js middleware)auto.http.otel.node_fetch(Node.js fetch instrumentation)isSentryRequestSpanfrom@sentry/opentelemetry)TRANSACTION_ATTR_SHOULD_DROP_TRANSACTIONto prevent them from being sentbeforeSamplinghook but it didn't work for some reason, so I stuck with the drop attribute.The final issue was excluding the tunnel requests from the middleware/proxy, but there are many blockers for a solution:
configmust be statically analyzable, so we cannot exposewithSentryMiddlewareConfigwrapper of any kind.I may explore this further later with a loader for both webpack/turbopack, and figure out a reliable way to inject the negative matchers into the user expressions.