Skip to content

Commit c77b66e

Browse files
author
Luca Forstner
committed
docs: Fix Next.js migration guide for v8
1 parent 25874a9 commit c77b66e

File tree

1 file changed

+34
-52
lines changed

1 file changed

+34
-52
lines changed

MIGRATION.md

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -870,58 +870,40 @@ or look at the TypeScript type definitions of `withSentryConfig`.
870870
871871
#### Updated the recommended way of calling `Sentry.init()`
872872
873-
With version 8 of the SDK we will no longer support the use of `sentry.server.config.ts` and `sentry.edge.config.ts`
874-
files. Instead, please initialize the Sentry Next.js SDK for the serverside in a
875-
[Next.js instrumentation hook](https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation).
876-
**`sentry.client.config.ts|js` is still supported and encouraged for initializing the clientside SDK.**
877-
878-
The following is an example of how to initialize the serverside SDK in a Next.js instrumentation hook:
879-
880-
1. First, enable the Next.js instrumentation hook by setting the `experimental.instrumentationHook` to `true` in your
881-
`next.config.js`.
882-
2. Next, create a `instrumentation.ts|js` file in the root directory of your project (or in the `src` folder if you have
883-
have one).
884-
3. Now, export a `register` function from the `instrumentation.ts|js` file and call `Sentry.init()` inside of it:
885-
886-
```ts
887-
import * as Sentry from '@sentry/nextjs';
888-
889-
export function register() {
890-
if (process.env.NEXT_RUNTIME === 'nodejs') {
891-
Sentry.init({
892-
dsn: 'YOUR_DSN',
893-
// Your Node.js Sentry configuration...
894-
});
895-
}
896-
897-
if (process.env.NEXT_RUNTIME === 'edge') {
898-
Sentry.init({
899-
dsn: 'YOUR_DSN',
900-
// Your Edge Runtime Sentry configuration...
901-
});
902-
}
903-
}
904-
```
905-
906-
If you need to import a Node.js specific integration (like for example `@sentry/profiling-node`), you will have to
907-
import the package using a dynamic import to prevent Next.js from bundling Node.js APIs into bundles for other
908-
runtime environments (like the Browser or the Edge runtime). You can do so as follows:
909-
910-
```ts
911-
import * as Sentry from '@sentry/nextjs';
912-
913-
export async function register() {
914-
if (process.env.NEXT_RUNTIME === 'nodejs') {
915-
const { nodeProfilingIntegration } = await import('@sentry/profiling-node');
916-
Sentry.init({
917-
dsn: 'YOUR_DSN',
918-
integrations: [nodeProfilingIntegration()],
919-
});
920-
}
921-
}
922-
```
923-
924-
Note that you can initialize the SDK differently depending on which server runtime is being used.
873+
Version 8 of 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.
874+
The `instrumentation.ts` file is a Next.js native API called [instrumentation hook](https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation).
875+
876+
To start using the Next.js instrumentation hook, follow these steps:
877+
878+
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)
879+
880+
```JavaScript {filename:next.config.js} {2-4}
881+
module.exports = {
882+
experimental: {
883+
instrumentationHook: true, // Not required on Next.js 15+
884+
},
885+
}
886+
```
887+
888+
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).
889+
890+
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:
891+
892+
```JavaScript {filename:instrumentation.js}
893+
import * as Sentry from '@sentry/nextjs';
894+
895+
export async function register() {
896+
if (process.env.NEXT_RUNTIME === 'nodejs') {
897+
await import('./sentry.server.config');
898+
}
899+
900+
if (process.env.NEXT_RUNTIME === 'edge') {
901+
await import('./sentry.edge.config');
902+
}
903+
}
904+
```
905+
906+
Note that you can initialize the SDK differently depending on which server runtime is being used.
925907
926908
If you are using a
927909
[Next.js custom server](https://nextjs.org/docs/pages/building-your-application/configuring/custom-server), the

0 commit comments

Comments
 (0)