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: platform-includes/migration/javascript-v8/important-changes/javascript.nextjs.mdx
+9-18Lines changed: 9 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -12,48 +12,39 @@ If you need to support older versions of Node.js or Next.js, please use Sentry N
12
12
13
13
### Updated SDK initialization
14
14
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).
16
17
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:
18
19
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)
20
21
21
22
```JavaScript {filename:next.config.js} {2-4}
22
23
module.exports= {
23
24
experimental: {
24
-
instrumentationHook:true,
25
+
instrumentationHook:true,// Not required on Next.js 15+
25
26
},
26
27
}
27
28
```
28
29
29
30
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).
30
31
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:
32
33
33
34
```JavaScript {filename:instrumentation.js}
34
35
import*asSentryfrom'@sentry/nextjs';
35
36
36
-
exportfunctionregister() {
37
+
exportasyncfunctionregister() {
37
38
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
+
awaitimport('./sentry.server.config');
43
40
}
44
41
45
-
// This is your Sentry.init call from `sentry.edge.config.js|ts`
46
42
if (process.env.NEXT_RUNTIME==='edge') {
47
-
Sentry.init({
48
-
dsn:'___PUBLIC_DSN___',
49
-
// Your Edge Runtime Sentry configuration...
50
-
});
43
+
awaitimport('./sentry.edge.config');
51
44
}
52
45
}
53
46
```
54
47
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
-
57
48
<Alertlevel="warning">
58
49
59
50
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