Skip to content

Commit 741b6d2

Browse files
lforstvivianyentran
authored andcommitted
Adjust Next.js manual setup docs to be in line with wizard (#10156)
Co-authored-by: vivianyentran <[email protected]>
1 parent 49354d4 commit 741b6d2

File tree

4 files changed

+54
-64
lines changed

4 files changed

+54
-64
lines changed

docs/platforms/javascript/common/configuration/integrations/index.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ However, it's important to note that not all integrations are compatible with al
1515

1616
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:
1717

18-
- For the browser runtime, add integrations to `sentry.client.config.(js|ts)`.
19-
- For Node.js, add integrations to your Sentry setup in `instrumentation.(js|ts)`.
20-
- For the Edge runtime, add integrations to your Sentry setup in `instrumentation.(js|ts)`.
18+
- For the browser runtime, add integrations to `sentry.client.config.ts`.
19+
- For Node.js, add integrations to `sentry.server.config.ts`.
20+
- For the Edge runtime, add integrations to `sentry.edge.config.ts`.
2121

2222
</PlatformSection>
2323

docs/platforms/javascript/guides/nextjs/manual-setup.mdx

+50-37
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ export default withSentryConfig(nextConfig, {
6868
});
6969
```
7070

71-
## Create Client Initialization Config File
71+
## Create Initialization Config Files
7272

73-
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.
73+
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.
74+
75+
Please note that there are slight differences between these files since they run in different places (browser, server, edge), so copy them carefully!
7476

7577
<SignInNote />
7678

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

103-
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`.
105+
```javascript {tabTitle:Server} {filename:sentry.server.config.(js|ts)}
106+
import * as Sentry from "@sentry/nextjs";
104107

105-
While the client initialization code will be injected into your application's client bundle by `withSentryConfig` which we set up earlier,
106-
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).
107-
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:
108+
Sentry.init({
109+
dsn: "___PUBLIC_DSN___",
108110

109-
```javascript {filename:instrumentation.(js|ts)}
111+
// Set tracesSampleRate to 1.0 to capture 100%
112+
// of transactions for performance monitoring.
113+
// We recommend adjusting this value in production
114+
tracesSampleRate: 1.0,
115+
116+
// ...
117+
118+
// Note: if you want to override the automatic release value, do not set a
119+
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
120+
// that it will also get attached to your source maps
121+
});
122+
```
123+
124+
```javascript {tabTitle:Edge} {filename:sentry.edge.config.(js|ts)}
110125
import * as Sentry from "@sentry/nextjs";
111126

112-
export async function register() {
113-
if (process.env.NEXT_RUNTIME === "nodejs") {
114-
Sentry.init({
115-
dsn: "___PUBLIC_DSN___",
127+
Sentry.init({
128+
dsn: "___PUBLIC_DSN___",
116129

117-
// Set tracesSampleRate to 1.0 to capture 100%
118-
// of transactions for performance monitoring.
119-
// We recommend adjusting this value in production
120-
tracesSampleRate: 1.0,
130+
// Set tracesSampleRate to 1.0 to capture 100%
131+
// of transactions for performance monitoring.
132+
// We recommend adjusting this value in production
133+
tracesSampleRate: 1.0,
121134

122-
// ...
135+
// ...
123136

124-
// Note: if you want to override the automatic release value, do not set a
125-
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
126-
// that it will also get attached to your source maps
127-
});
128-
}
137+
// Note: if you want to override the automatic release value, do not set a
138+
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
139+
// that it will also get attached to your source maps
140+
});
141+
```
129142

130-
if (process.env.NEXT_RUNTIME === "edge") {
131-
Sentry.init({
132-
dsn: "___PUBLIC_DSN___",
143+
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`.
133144

134-
// Set tracesSampleRate to 1.0 to capture 100%
135-
// of transactions for performance monitoring.
136-
// We recommend adjusting this value in production
137-
tracesSampleRate: 1.0,
145+
While the client initialization code will be injected into your application's client bundle by `withSentryConfig` which we set up earlier,
146+
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).
147+
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:
138148

139-
// ...
149+
```javascript {filename:instrumentation.(js|ts)}
150+
export async function register() {
151+
if (process.env.NEXT_RUNTIME === "nodejs") {
152+
await import("./sentry.server.config");
153+
}
140154

141-
// Note: if you want to override the automatic release value, do not set a
142-
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
143-
// that it will also get attached to your source maps
144-
});
155+
if (process.env.NEXT_RUNTIME === "edge") {
156+
await import("./sentry.edge.config");
145157
}
146158
}
147159
```
148160

161+
Make sure that the `import` statements point to your newly created `sentry.server.config.(js|ts)` and `sentry.edge.config.(js|ts)` files.
162+
149163
## Report React Component Render Errors
150164

151165
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, {
594608
});
595609
```
596610

597-
### Opt Out of Sentry SDK bundling in Client or Server side
598-
599-
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)`.
611+
### Opt Out of Sentry SDK bundling in Client- or Server-Side
600612

601-
You cannot delete the client config file because the SDK requires you to have it.
613+
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.
614+
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`.
602615

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

platform-includes/metrics/configure/javascript.nextjs.mdx

-23
This file was deleted.

platform-includes/performance/configure-sample-rate/javascript.nextjs.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Set `tracesSampleRate` in `sentry.client.config.js`, as well as in the Sentry setup in `instrumentation.(js|ts)`:
1+
Set `tracesSampleRate` in your config files, `sentry.server.config.js`, `sentry.client.config.js`, and `sentry.edge.config.js`:
22

33
<SignInNote />
44

0 commit comments

Comments
 (0)