diff --git a/docs/platforms/javascript/common/configuration/integrations/index.mdx b/docs/platforms/javascript/common/configuration/integrations/index.mdx index 3f1959f6cb91e7..46ba0d46450ae7 100644 --- a/docs/platforms/javascript/common/configuration/integrations/index.mdx +++ b/docs/platforms/javascript/common/configuration/integrations/index.mdx @@ -15,9 +15,9 @@ However, it's important to note that not all integrations are compatible with al Depending on whether an integration enhances the functionality of a particular runtime, such as the BrowserTracing integration for the browser runtime or the RequestData integration for the Node.js runtime, you can only include these integrations in their respective configuration files: -- For the browser runtime, add integrations to `sentry.client.config.(js|ts)`. -- For Node.js, add integrations to your Sentry setup in `instrumentation.(js|ts)`. -- For the Edge runtime, add integrations to your Sentry setup in `instrumentation.(js|ts)`. +- For the browser runtime, add integrations to `sentry.client.config.ts`. +- For Node.js, add integrations to `sentry.server.config.ts`. +- For the Edge runtime, add integrations to `sentry.edge.config.ts`. diff --git a/docs/platforms/javascript/guides/nextjs/manual-setup.mdx b/docs/platforms/javascript/guides/nextjs/manual-setup.mdx index feb7cbddedb550..ed2c3790e2884b 100644 --- a/docs/platforms/javascript/guides/nextjs/manual-setup.mdx +++ b/docs/platforms/javascript/guides/nextjs/manual-setup.mdx @@ -68,9 +68,11 @@ export default withSentryConfig(nextConfig, { }); ``` -## Create Client Initialization Config File +## Create Initialization Config Files -Create this file in the root directory of your Next.js application: `sentry.client.config.js`. In this file, add your initialization code for the client-side SDK. The setup for browser-side initialization is explained below. +Create three files in the root directory of your Next.js application: `sentry.client.config.js`, `sentry.server.config.js` and `sentry.edge.config.js`. In these files, add your initialization code for the client-side SDK and server-side SDK, respectively. We've included some examples below. + +Please note that there are slight differences between these files since they run in different places (browser, server, edge), so copy them carefully! @@ -100,52 +102,64 @@ Sentry.init({ }); ``` -We recommend you include your DSN directly in these three files. Alternatively you can pass the DSN via a _public_ environment variable like `NEXT_PUBLIC_SENTRY_DSN`. +```javascript {tabTitle:Server} {filename:sentry.server.config.(js|ts)} +import * as Sentry from "@sentry/nextjs"; -While the client initialization code will be injected into your application's client bundle by `withSentryConfig` which we set up earlier, -the configuration for the server and edge runtime needs to be imported from a [Next.js Instrumentation file](https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation). -You can set this file up by adding a `instrumentation.(js|ts)` file to the root directory of your Next.js application (or inside the `src` folder if you are using one) and adding the following content: +Sentry.init({ + dsn: "___PUBLIC_DSN___", -```javascript {filename:instrumentation.(js|ts)} + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for performance monitoring. + // We recommend adjusting this value in production + tracesSampleRate: 1.0, + + // ... + + // Note: if you want to override the automatic release value, do not set a + // `release` value here - use the environment variable `SENTRY_RELEASE`, so + // that it will also get attached to your source maps +}); +``` + +```javascript {tabTitle:Edge} {filename:sentry.edge.config.(js|ts)} import * as Sentry from "@sentry/nextjs"; -export async function register() { - if (process.env.NEXT_RUNTIME === "nodejs") { - Sentry.init({ - dsn: "___PUBLIC_DSN___", +Sentry.init({ + dsn: "___PUBLIC_DSN___", - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for performance monitoring. - // We recommend adjusting this value in production - tracesSampleRate: 1.0, + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for performance monitoring. + // We recommend adjusting this value in production + tracesSampleRate: 1.0, - // ... + // ... - // Note: if you want to override the automatic release value, do not set a - // `release` value here - use the environment variable `SENTRY_RELEASE`, so - // that it will also get attached to your source maps - }); - } + // Note: if you want to override the automatic release value, do not set a + // `release` value here - use the environment variable `SENTRY_RELEASE`, so + // that it will also get attached to your source maps +}); +``` - if (process.env.NEXT_RUNTIME === "edge") { - Sentry.init({ - dsn: "___PUBLIC_DSN___", +We recommend you include your DSN directly in these three files. Alternatively you can pass the DSN via a _public_ environment variable like `NEXT_PUBLIC_SENTRY_DSN`. - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for performance monitoring. - // We recommend adjusting this value in production - tracesSampleRate: 1.0, +While the client initialization code will be injected into your application's client bundle by `withSentryConfig` which we set up earlier, +the configuration for the server and edge runtime needs to be imported from a [Next.js Instrumentation file](https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation). +To set up this file, add a `instrumentation.ts` file to the root directory of your Next.js application (or inside the `src` folder if you're using one) and add the following content: - // ... +```javascript {filename:instrumentation.(js|ts)} +export async function register() { + if (process.env.NEXT_RUNTIME === "nodejs") { + await import("./sentry.server.config"); + } - // Note: if you want to override the automatic release value, do not set a - // `release` value here - use the environment variable `SENTRY_RELEASE`, so - // that it will also get attached to your source maps - }); + if (process.env.NEXT_RUNTIME === "edge") { + await import("./sentry.edge.config"); } } ``` +Make sure that the `import` statements point to your newly created `sentry.server.config.(js|ts)` and `sentry.edge.config.(js|ts)` files. + ## Report React Component Render Errors To capture React render errors you need to add Error components for the App Router and the Pages Router respectively. @@ -594,11 +608,10 @@ module.exports = withSentryConfig(nextConfig, { }); ``` -### Opt Out of Sentry SDK bundling in Client or Server side - -If you want the `sentry` to be available in your server side & not in client side, you can make your `sentry.client.config.js` empty. This will prevent webpack from pulling in the Sentry related files when generating the browser bundle. The same goes the opposite for opting out of server side bundle by not initializing Sentry inside `instrumentation.(js|ts)`. +### Opt Out of Sentry SDK bundling in Client- or Server-Side -You cannot delete the client config file because the SDK requires you to have it. +If you want the Sentry SDK to be available in your server-side & not in client-side, you can simply delete `sentry.client.config.js`. This will prevent webpack from pulling in the Sentry related files when generating the browser bundle. +Similarly, to opt out of server-side SDK bundling, you can simply delete the `sentry.server.config.js` and `sentry.edge.config.js` files. Make sure to remove any any imports of these files from `instrumentation.ts`. ## Disable the Sentry SDK Debug Logger to Save Bundle Size diff --git a/platform-includes/metrics/configure/javascript.nextjs.mdx b/platform-includes/metrics/configure/javascript.nextjs.mdx deleted file mode 100644 index 6d0d484097156c..00000000000000 --- a/platform-includes/metrics/configure/javascript.nextjs.mdx +++ /dev/null @@ -1,23 +0,0 @@ -Metrics work out of the box by calling `Sentry.init`, no further setup is required. - -```JavaScript -// sentry.client.config.js -Sentry.init({ - dsn: '___PUBLIC_DSN___', - // Only needed for SDK versions < 8.0.0 - // integrations: [ - // Sentry.metrics.metricsAggregatorIntegration(), - // ], -}); -``` - -```JavaScript -// instrumentation.js -Sentry.init({ - dsn: '___PUBLIC_DSN___', - // Only needed for SDK versions < 8.0.0 - // _experiments: { - // metricsAggregator: true, - // }, -}); -``` diff --git a/platform-includes/performance/configure-sample-rate/javascript.nextjs.mdx b/platform-includes/performance/configure-sample-rate/javascript.nextjs.mdx index a6bbe58b90772c..f470b241b5b9d8 100644 --- a/platform-includes/performance/configure-sample-rate/javascript.nextjs.mdx +++ b/platform-includes/performance/configure-sample-rate/javascript.nextjs.mdx @@ -1,4 +1,4 @@ -Set `tracesSampleRate` in `sentry.client.config.js`, as well as in the Sentry setup in `instrumentation.(js|ts)`: +Set `tracesSampleRate` in your config files, `sentry.server.config.js`, `sentry.client.config.js`, and `sentry.edge.config.js`: