Skip to content

Commit ed8d23c

Browse files
authored
docs: Fix Next.js migration guide for v8 (#14817)
1 parent b8c83be commit ed8d23c

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

MIGRATION.md

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -870,53 +870,35 @@ 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.**
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).
877875
878-
The following is an example of how to initialize the serverside SDK in a Next.js instrumentation hook:
876+
To start using the Next.js instrumentation hook, follow these steps:
879877
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:
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)
885879
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-
}
880+
```JavaScript {filename:next.config.js} {2-4}
881+
module.exports = {
882+
experimental: {
883+
instrumentationHook: true, // Not required on Next.js 15+
884+
},
903885
}
904886
```
905887
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:
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:
909891
910-
```ts
892+
```JavaScript {filename:instrumentation.js}
911893
import * as Sentry from '@sentry/nextjs';
912894

913895
export async function register() {
914896
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-
});
897+
await import('./sentry.server.config');
898+
}
899+
900+
if (process.env.NEXT_RUNTIME === 'edge') {
901+
await import('./sentry.edge.config');
920902
}
921903
}
922904
```

0 commit comments

Comments
 (0)