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
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/configuration/integrations/index.mdx
+3-3
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
15
15
16
16
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:
17
17
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`.
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!
74
76
75
77
<SignInNote />
76
78
@@ -100,52 +102,64 @@ Sentry.init({
100
102
});
101
103
```
102
104
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`.
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___",
108
110
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
// 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,
121
134
122
-
// ...
135
+
// ...
123
136
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
+
```
129
142
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`.
133
144
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:
138
148
139
-
// ...
149
+
```javascript {filename:instrumentation.(js|ts)}
150
+
exportasyncfunctionregister() {
151
+
if (process.env.NEXT_RUNTIME==="nodejs") {
152
+
awaitimport("./sentry.server.config");
153
+
}
140
154
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
+
awaitimport("./sentry.edge.config");
145
157
}
146
158
}
147
159
```
148
160
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
+
149
163
## Report React Component Render Errors
150
164
151
165
To capture React render errors you need to add Error components for the App Router and the Pages Router respectively.
### 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
600
612
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`.
602
615
603
616
## Disable the Sentry SDK Debug Logger to Save Bundle Size
0 commit comments