You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This feature requires **Next.js version 11+** and doesn't currently work with self-hosted Sentry instances.
232
232
</Alert>
233
233
234
234
Tunnel Sentry requests through this route on your Next.js server to prevent ad-blockers from blocking Sentry events from being sent.
235
-
This route should be a path, like `/error-monitoring`, as it adds an API endpoint within your application.
235
+
236
+
This option can be set to:
237
+
238
+
-`true` for auto-generated routes, which are unpredictable and change with each deployment.
239
+
- A custom static string path like `/error-monitoring`.
236
240
237
241
Learn more about tunneling in the <PlatformLinkto="/troubleshooting/#dealing-with-ad-blockers">troubleshooting section</PlatformLink>.
238
242
239
-
<Expandablelevel="warning"title="Complications with Next.js middleware">
240
-
Client-side event recording will fail if your Next.js middleware intercepts
241
-
the configured route. To prevent this, exclude the tunnel route by adding a
242
-
negative matcher to your middleware like `(?!monitoring-tunnel)`.
243
+
<Expandablelevel="warning"title="Using Next.js middleware on Turbopack">
244
+
If you're using Turbopack, client-side event recording will fail if your Next.js middleware intercepts the configured tunnel route. To fix this, set the route to a fixed string (like `/error-monitoring`) and add a negative matcher like `(?!error-monitoring)` in your middleware to exclude the tunnel route.
245
+
246
+
If you're not using Turbopack, Sentry will automatically skip the tunnel route in your middleware.
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/nextjs/manual-setup.mdx
+10-8Lines changed: 10 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -449,14 +449,16 @@ Make sure to keep your auth token secret and out of version control.
449
449
450
450
You can prevent ad blockers from blocking Sentry events using tunneling. Use the `tunnelRoute` option to add an API endpoint in your application that forwards Sentry events to Sentry servers.
451
451
452
-
Update `withSentryConfig` in your `next.config.(js|mjs)` file with the following options:
452
+
For better ad-blocker evasion, you can either:
453
+
- Set `tunnelRoute: true` to automatically generate a random tunnel route for each build, making it harder for ad-blockers to detect and block monitoring requests
454
+
- Set `tunnelRoute: "/my-tunnel-route"` to use a static route of your choosing
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
466
468
// This can increase your server load as well as your hosting bill.
467
469
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-side errors will fail.
468
-
tunnelRoute:"/monitoring",
470
+
tunnelRoute:true, // Generates a random route for each build (recommended)
469
471
});
470
472
```
471
473
472
-
<Alertlevel="warning"title="Complications with Next.js middleware">
473
-
Client-side event recording will fail if your Next.js middleware intercepts
474
-
the configured route. To prevent this, exclude the tunnel route by adding a
475
-
negative matcher to your middleware like `(?!monitoring-tunnel)`.
476
-
</Alert>
474
+
<Expandablelevel="warning"title="Using Next.js middleware on Turbopack">
475
+
If you're using Turbopack, client-side event recording will fail if your Next.js middleware intercepts the configured tunnel route. To fix this, set the route to a fixed string (like `/error-monitoring`) and add a negative matcher like `(?!error-monitoring)` in your middleware to exclude the tunnel route.
476
+
477
+
If you're not using Turbopack, Sentry will automatically skip the tunnel route in your middleware.
0 commit comments