Skip to content

Commit 6d06a5e

Browse files
author
Luca Forstner
authored
Add Next.js edge runtime and middleware documentation (#6081)
1 parent 63771f5 commit 6d06a5e

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

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

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ If you can't (or prefer not to) run the [configuration step](/platforms/javascri
88

99
## Create Initialization Config Files
1010

11-
Create two files in the root directory of your project, `sentry.client.config.js` and `sentry.server.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.
11+
Create three files in the root directory of your project, `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.
1212

1313
For each configuration:
1414

15-
```javascript {filename:sentry.server.config.js/sentry.client.config.js}
15+
```javascript {filename:sentry.server.config.js/sentry.client.config.js/sentry.edge.config.js}
1616
import * as Sentry from "@sentry/nextjs";
1717

1818
const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
@@ -29,7 +29,7 @@ Sentry.init({
2929
});
3030
```
3131

32-
```typescript {filename:sentry.server.config.ts/sentry.client.config.ts}
32+
```typescript {filename:sentry.server.config.ts/sentry.client.config.ts/sentry.edge.config.ts}
3333
import * as Sentry from "@sentry/nextjs";
3434

3535
const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
@@ -319,7 +319,7 @@ const moduleExports = {
319319

320320
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.
321321

322-
### Disable API Route and Data Fetching Auto-instrumentation Entirely
322+
### Disable API Route, Middleware and Data Fetching Auto-instrumentation Entirely
323323

324324
_(New in version 7.14.0)_
325325

@@ -341,7 +341,7 @@ _(New in version 7.14.0)_
341341

342342
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.
343343

344-
For API routes, use the `withSentry` function:
344+
For API routes, use the `wrapApiHandlerWithSentry` function:
345345

346346
```javascript {filename:pages/api/*}
347347
import { withSentry } from "@sentry/nextjs";
@@ -350,7 +350,7 @@ const handler = (req, res) => {
350350
res.status(200).json({ name: "John Doe" });
351351
};
352352

353-
export default withSentry(handler);
353+
export default wrapApiHandlerWithSentry(handler, "/api/myRoute");
354354
```
355355

356356
```typescript {filename:pages/api/*}
@@ -361,17 +361,17 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
361361
res.status(200).json({ name: "John Doe" });
362362
};
363363

364-
export default withSentry(handler);
364+
export default wrapApiHandlerWithSentry(handler, "/api/myRoute");
365365
```
366366

367367
For data fetching methods, use the following functions:
368368

369-
- `withSentryServerSideGetInitialProps` for `getInitialProps`
370-
- `withSentryGetServerSideProps` for `getServerSideProps`
371-
- `withSentryGetStaticProps` for `getStaticProps`
372-
- `withSentryServerSideErrorGetInitialProps` for `getInitialProps` in [custom Error pages](https://nextjs.org/docs/advanced-features/custom-error-page)
373-
- `withSentryServerSideAppGetInitialProps` for `getInitialProps` in [custom `App` components](https://nextjs.org/docs/advanced-features/custom-app)
374-
- `withSentryServerSideDocumentGetInitialProps` for `getInitialProps` in [custom `Document` components](https://nextjs.org/docs/advanced-features/custom-document)
369+
- `wrapGetInitialPropsWithSentry` for `getInitialProps`
370+
- `wrapGetServerSidePropsWithSentry` for `getServerSideProps`
371+
- `wrapGetStaticPropsWithSentry` for `getStaticProps`
372+
- `wrapErrorGetInitialPropsWithSentry` for `getInitialProps` in [custom Error pages](https://nextjs.org/docs/advanced-features/custom-error-page)
373+
- `wrapAppGetInitialPropsWithSentry` for `getInitialProps` in [custom `App` components](https://nextjs.org/docs/advanced-features/custom-app)
374+
- `wrapDocumentGetInitialPropsWithSentry` for `getInitialProps` in [custom `Document` components](https://nextjs.org/docs/advanced-features/custom-document)
375375

376376
### Opt Out of Auto-instrumentation on Specific Routes
377377

@@ -394,6 +394,20 @@ const moduleExports = {
394394

395395
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.
396396

397+
### Opt Out of Auto-instrumentation on Middleware
398+
399+
_(New in version 7.31.0)_
400+
401+
To disable the automatic instrumentation of Next.js middleware, set the `autoInstrumentMiddleware` option to `false`.
402+
403+
```javascript {filename:next.config.js}
404+
const moduleExports = {
405+
sentry: {
406+
autoInstrumentMiddleware: false,
407+
},
408+
};
409+
```
410+
397411
## Configure Tunneling to avoid Ad-Blockers
398412

399413
_(New in version 7.26.0)_

0 commit comments

Comments
 (0)