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
feat(nextjs): Add excludeServerRoutes option to manual setup page (#5789)
This adds the new `excludeServerRoutes` option in the nextjs SDK (added in getsentry/sentry-javascript#6207) to the docs. It also pulls all of the auto-instrumentation config into its own section in the manual setup page.
(Note: The only part of this which is actually new content is the `Opt Out of Auto-instrumentation on Specific Routes` section. Everything else is just stuff moving around.)
In that case you can also skip the `sentry-cli` configuration step below.
221
224
222
-
### Automatic Instrumentation of API Routes and Data Fetching Methods
223
-
224
-
_(New in version 7.14.0)_
225
-
226
-
The SDK will automatically instrument API routes and server-side [Next.js data fetching methods](https://nextjs.org/docs/basic-features/data-fetching/overview) with error and performance monitoring To disable it, set the `autoInstrumentServerFunctions` to `false`.
227
-
228
-
```javascript {filename:next.config.js}
229
-
constmoduleExports= {
230
-
sentry: {
231
-
autoInstrumentServerFunctions:false,
232
-
},
233
-
};
234
-
```
235
-
236
-
Under the hood, when using this option, the SDK is using a Webpack loader to wrap all your API route handlers and data fetching methods.
237
-
238
-
If the automatic instrumentation doesn't work for your use case, API routes can also be wrapped manually using the `withSentry` function:
Data fetching methods can also be manually wrapped using the following functions:
262
-
263
-
-`withSentryServerSideGetInitialProps` for `getInitialProps`
264
-
-`withSentryGetServerSideProps` for `getServerSideProps`
265
-
-`withSentryGetStaticProps` for `getStaticProps`
266
-
-`withSentryServerSideErrorGetInitialProps` for `getInitialProps` in [custom Error pages](https://nextjs.org/docs/advanced-features/custom-error-page)
267
-
-`withSentryServerSideAppGetInitialProps` for `getInitialProps` in [custom `App` components](https://nextjs.org/docs/advanced-features/custom-app)
268
-
-`withSentryServerSideDocumentGetInitialProps` for `getInitialProps` in [custom `Document` components](https://nextjs.org/docs/advanced-features/custom-document)
269
-
270
225
### Use `hidden-source-map`
271
226
272
227
_(New in version 6.17.1, will default to `true` in 8.0.0 and beyond.)_
@@ -355,3 +310,82 @@ const moduleExports = {
355
310
```
356
311
357
312
(This assumes you are using [the `next.config.js` setup shown above](#extend-nextjs-configuration).)
313
+
314
+
## Configure Server-side Auto-instrumentation
315
+
316
+
The SDK will automatically instrument API routes and server-side [Next.js data fetching methods](https://nextjs.org/docs/basic-features/data-fetching/overview) with error and performance monitoring.
317
+
318
+
### Disable API Route and Data Fetching Auto-instrumentation Entirely
319
+
320
+
_(New in version 7.14.0)_
321
+
322
+
To disable the automatic instrumentation of API route handlers and server-side data fetching functions, set the `autoInstrumentServerFunctions` to `false`.
323
+
324
+
```javascript {filename:next.config.js}
325
+
constmoduleExports= {
326
+
sentry: {
327
+
autoInstrumentServerFunctions:false,
328
+
},
329
+
};
330
+
```
331
+
332
+
With this option, under the hood, the SDK is using a Webpack loader to wrap all your API route handlers and data fetching methods.
333
+
334
+
### Opt In to Auto-instrumentation on Specific Routes
335
+
336
+
_(New in version 7.14.0)_
337
+
338
+
If the automatic instrumentation doesn't work for your use case, you can turn it off globally and choose to only wrap specific API route handlers or data fetching functions instead.
For data fetching methods, use the following functions:
364
+
365
+
-`withSentryServerSideGetInitialProps` for `getInitialProps`
366
+
-`withSentryGetServerSideProps` for `getServerSideProps`
367
+
-`withSentryGetStaticProps` for `getStaticProps`
368
+
-`withSentryServerSideErrorGetInitialProps` for `getInitialProps` in [custom Error pages](https://nextjs.org/docs/advanced-features/custom-error-page)
369
+
-`withSentryServerSideAppGetInitialProps` for `getInitialProps` in [custom `App` components](https://nextjs.org/docs/advanced-features/custom-app)
370
+
-`withSentryServerSideDocumentGetInitialProps` for `getInitialProps` in [custom `Document` components](https://nextjs.org/docs/advanced-features/custom-document)
371
+
372
+
### Opt Out of Auto-instrumentation on Specific Routes
373
+
374
+
_(New in version 7.20.0)_
375
+
376
+
If you want auto-instrumenatation to apply by default, but want to exclude certain routes, use the `excludeServerRoutes` option in the `sentry` object in your `next.config.js`:
377
+
378
+
```javascript {filename:next.config.js}
379
+
constmoduleExports= {
380
+
sentry: {
381
+
excludeServerRoutes: [
382
+
"/some/excluded/route",
383
+
"/excluded/route/with/[parameter]",
384
+
/^\/route\/beginning\/with\/some\/prefix/,
385
+
/\/routeContainingASpecificPathSegment\/?/,
386
+
],
387
+
},
388
+
};
389
+
```
390
+
391
+
Excluded routes can be specified either as regexes or strings. When using a string, make sure that it matches the route exactly, and has a leading slash but no trailing one.
0 commit comments