Skip to content

Commit 903a8f7

Browse files
author
Luca Forstner
authored
Fix v8 migration guide for Next.js to align with wizard (#12195)
1 parent 837e0f9 commit 903a8f7

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

platform-includes/migration/javascript-v8/important-changes/javascript.nextjs.mdx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,39 @@ If you need to support older versions of Node.js or Next.js, please use Sentry N
1212

1313
### Updated SDK initialization
1414

15-
With `8.x` the Next.js SDK will no longer support the use of `sentry.server.config.js|ts` and `sentry.edge.config.js|ts` files. Instead, please initialize the Sentry Next.js SDK for the server-side in a Next.js [instrumentation hook](https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation). Usage of `sentry.client.config.ts|js` is still supported and encouraged for initializing the client-side SDK.
15+
With `8.x` the Next.js SDK will require an additional `instrumentation.ts` file to execute the `sentry.server.config.js|ts` and `sentry.edge.config.js|ts` modules to initialize the SDK for the server-side.
16+
The `instrumentation.ts` file is a Next.js native API called [instrumentation hook](https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation).
1617

17-
To start using the Next.js built-in hooks, follow these steps:
18+
To start using the Next.js instrumentation hook, follow these steps:
1819

19-
1. First, enable the Next.js instrumentation hook by setting the [`experimental.instrumentationHook`](https://nextjs.org/docs/app/api-reference/next-config-js/instrumentationHook) to true in your `next.config.js`.
20+
1. First, enable the Next.js instrumentation hook by setting the [`experimental.instrumentationHook`](https://nextjs.org/docs/app/api-reference/next-config-js/instrumentationHook) to true in your `next.config.js`. (This step is no longer required with Next.js 15)
2021

2122
```JavaScript {filename:next.config.js} {2-4}
2223
module.exports = {
2324
experimental: {
24-
instrumentationHook: true,
25+
instrumentationHook: true, // Not required on Next.js 15+
2526
},
2627
}
2728
```
2829

2930
2. Next, create a `instrumentation.ts|js` file in the root directory of your project (or in the src folder if you have have one).
3031

31-
3. Now, export a register function from the `instrumentation.ts|js` file and call `Sentry.init()` inside of it:
32+
3. Now, export a register function from the `instrumentation.ts|js` file and import your `sentry.server.config.js|ts` and `sentry.edge.config.js|ts` modules:
3233

3334
```JavaScript {filename:instrumentation.js}
3435
import * as Sentry from '@sentry/nextjs';
3536

36-
export function register() {
37+
export async function register() {
3738
if (process.env.NEXT_RUNTIME === 'nodejs') {
38-
// this is your Sentry.init call from `sentry.server.config.js|ts`
39-
Sentry.init({
40-
dsn: '___PUBLIC_DSN___',
41-
// Your Node.js Sentry configuration...
42-
});
39+
await import('./sentry.server.config');
4340
}
4441

45-
// This is your Sentry.init call from `sentry.edge.config.js|ts`
4642
if (process.env.NEXT_RUNTIME === 'edge') {
47-
Sentry.init({
48-
dsn: '___PUBLIC_DSN___',
49-
// Your Edge Runtime Sentry configuration...
50-
});
43+
await import('./sentry.edge.config');
5144
}
5245
}
5346
```
5447

55-
4. Last, you can delete the `sentry.server.config.js|ts` and `sentry.edge.config.js|ts` files. Please remember to keep your `sentry.client.config.ts|js` file for client-side SDK initialization.
56-
5748
<Alert level="warning">
5849

5950
If you are using a [Next.js custom server](https://nextjs.org/docs/pages/building-your-application/configuring/custom-server), the `instrumentation.ts|js` hook is not called by Next.js so SDK instrumentation will not work as expected. See the [troubleshooting section](#nextjs-custom-server) for more information.

0 commit comments

Comments
 (0)