diff --git a/docs/platforms/javascript/guides/nextjs/configuration/build/index.mdx b/docs/platforms/javascript/guides/nextjs/configuration/build/index.mdx index d0826b91ef670..7ec0aff39f6bb 100644 --- a/docs/platforms/javascript/guides/nextjs/configuration/build/index.mdx +++ b/docs/platforms/javascript/guides/nextjs/configuration/build/index.mdx @@ -208,20 +208,24 @@ excludeServerRoutes: [ - + This feature requires **Next.js version 11+** and doesn't currently work with self-hosted Sentry instances. Tunnel Sentry requests through this route on your Next.js server to prevent ad-blockers from blocking Sentry events from being sent. -This route should be a path, like `/error-monitoring`, as it adds an API endpoint within your application. + +This option can be set to: + +- `true` for auto-generated routes, which are unpredictable and change with each deployment. +- A custom static string path like `/error-monitoring`. Learn more about tunneling in the troubleshooting section. - - Client-side event recording will fail if your Next.js middleware intercepts - the configured route. To prevent this, exclude the tunnel route by adding a - negative matcher to your middleware like `(?!monitoring-tunnel)`. + + 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. + + If you're not using Turbopack, Sentry will automatically skip the tunnel route in your middleware. diff --git a/docs/platforms/javascript/guides/nextjs/manual-setup.mdx b/docs/platforms/javascript/guides/nextjs/manual-setup.mdx index b83a6d23d19a3..8af7ad484a963 100644 --- a/docs/platforms/javascript/guides/nextjs/manual-setup.mdx +++ b/docs/platforms/javascript/guides/nextjs/manual-setup.mdx @@ -449,14 +449,16 @@ Make sure to keep your auth token secret and out of version control. 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. -Update `withSentryConfig` in your `next.config.(js|mjs)` file with the following options: +For better ad-blocker evasion, you can either: +- 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 +- Set `tunnelRoute: "/my-tunnel-route"` to use a static route of your choosing ```javascript {tabTitle:ESM} {filename:next.config.mjs} export default withSentryConfig(nextConfig, { // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. // This can increase your server load as well as your hosting bill. // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-side errors will fail. - tunnelRoute: "/monitoring", + tunnelRoute: true, // Generates a random route for each build (recommended) }); ``` @@ -465,15 +467,15 @@ module.exports = withSentryConfig(nextConfig, { // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. // This can increase your server load as well as your hosting bill. // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-side errors will fail. - tunnelRoute: "/monitoring", + tunnelRoute: true, // Generates a random route for each build (recommended) }); ``` - - Client-side event recording will fail if your Next.js middleware intercepts - the configured route. To prevent this, exclude the tunnel route by adding a - negative matcher to your middleware like `(?!monitoring-tunnel)`. - + + 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. + + If you're not using Turbopack, Sentry will automatically skip the tunnel route in your middleware. + ## Step 6: Instrument Vercel Cron Jobs (Optional)