Skip to content

docs(nextjs): Remove sentry.server.config and sentry.edge.config #10040

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

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.ts`.
- For Node.js, add integrations to `sentry.server.config.ts`.
- For the Edge runtime, add integrations to `sentry.edge.config.ts`.
- 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)`.

</PlatformSection>

84 changes: 35 additions & 49 deletions docs/platforms/javascript/guides/nextjs/manual-setup.mdx
Original file line number Diff line number Diff line change
@@ -68,11 +68,9 @@ export default withSentryConfig(nextConfig, {
});
```

## Create Initialization Config Files
## Create Client Initialization Config File

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!
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.

<SignInNote />

@@ -102,64 +100,52 @@ Sentry.init({
});
```

```javascript {tabTitle:Server} {filename:sentry.server.config.(js|ts)}
import * as Sentry from "@sentry/nextjs";

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,

// ...

// 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";

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,

// ...

// 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
});
```

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`.

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.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:
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:

```javascript {filename:instrumentation.(js|ts)}
import * as Sentry from "@sentry/nextjs";

export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
await import("./sentry.server.config");
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,

// ...

// 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");
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,

// ...

// 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
});
}
}
```

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.
@@ -610,9 +596,9 @@ 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 emptying `sentry.server.config.js`.
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)`.

You cannot delete the respective config files because the SDK requires you to have it.
You cannot delete the client config file because the SDK requires you to have it.

## Disable the Sentry SDK Debug Logger to Save Bundle Size

3 changes: 1 addition & 2 deletions platform-includes/metrics/configure/javascript.nextjs.mdx
Original file line number Diff line number Diff line change
@@ -10,10 +10,9 @@ Sentry.init({
});
```

To configure metrics for your server-side code, add the `metricsAggregator` experimental option to your `Sentry.init` call in your `sentry.server.config.js` and `sentry.edge.config.js` files.
To configure metrics for your server-side code, add the `metricsAggregator` experimental option to your `Sentry.init` call in your `instrumentation.(js|ts)` file.

```JavaScript
// sentry.server.config.js AND/OR sentry.edge.config.js
Sentry.init({
dsn: '___PUBLIC_DSN___',
_experiments: {
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In both, `sentry.server.config.js` and `sentry.client.config.js`, set:
Set `tracesSampleRate` in `sentry.client.config.js`, as well as in the Sentry setup in `instrumentation.(js|ts)`:

<SignInNote />

This file was deleted.