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
The logic in this PR is slightly intense but all it does is check for
the Next.js version and if we are on a version that included [this
change](vercel/next.js#68853) which stabilized
`instrumentation.ts` we no longer inject the
`experimental.instrumentationHook` option in `next.config.js`.
This is necessary because otherwise Next.js prints scary warnings and
users may be confused why.
'[@sentry/nextjs] You turned off the `instrumentationHook` option. Note that Sentry will not be initialized if you did not set it up inside `instrumentation.ts`.',
79
-
);
80
-
}
81
-
incomingUserNextConfigObject.experimental={
82
-
instrumentationHook: true,
83
-
...incomingUserNextConfigObject.experimental,
84
-
};
76
+
constnextJsVersion=getNextjsVersion();
85
77
86
78
// Add the `clientTraceMetadata` experimental option based on Next.js version. The option got introduced in Next.js version 15.0.0 (actually 14.3.0-canary.64).
87
79
// Adding the option on lower versions will cause Next.js to print nasty warnings we wouldn't confront our users with.
@@ -99,10 +90,76 @@ function getFinalConfigObject(
99
90
}else{
100
91
// eslint-disable-next-line no-console
101
92
console.log(
102
-
"[@sentry/nextjs] The Sentry SDK was not able to determine your Next.js version. If you are using Next.js 15 or greater, please add `experimental.clientTraceMetadata: ['sentry-trace', 'baggage']` to your Next.js config to enable pageload tracing for App Router.",
93
+
"[@sentry/nextjs] The Sentry SDK was not able to determine your Next.js version. If you are using Next.js version 15 or greater, please add `experimental.clientTraceMetadata: ['sentry-trace', 'baggage']` to your Next.js config to enable pageload tracing for App Router.",
103
94
);
104
95
}
105
96
97
+
// From Next.js version (15.0.0-canary.124) onwards, Next.js does no longer require the `experimental.instrumentationHook` option and will
98
+
// print a warning when it is set, so we need to conditionally provide it for lower versions.
'[@sentry/nextjs] You turned off the `experimental.instrumentationHook` option. Note that Sentry will not be initialized if you did not set it up inside `instrumentation.(js|ts)`.',
132
+
);
133
+
}
134
+
incomingUserNextConfigObject.experimental={
135
+
instrumentationHook: true,
136
+
...incomingUserNextConfigObject.experimental,
137
+
};
138
+
}
139
+
}else{
140
+
// If we cannot detect a Next.js version for whatever reason, the sensible default is to set the `experimental.instrumentationHook`, even though it may create a warning.
'[@sentry/nextjs] You set `experimental.instrumentationHook` to `false`. If you are using Next.js version 15 or greater, you can remove that option. If you are using Next.js version 14 or lower, you need to set `experimental.instrumentationHook` in your `next.config.(js|mjs)` to `true` for the SDK to be properly initialized in combination with `instrumentation.(js|ts)`.',
149
+
);
150
+
}
151
+
}else{
152
+
// eslint-disable-next-line no-console
153
+
console.log(
154
+
"[@sentry/nextjs] The Sentry SDK was not able to determine your Next.js version. If you are using Next.js version 15 or greater, Next.js will probably show you a warning about the `experimental.instrumentationHook` being set. To silence Next.js' warning, explicitly set the `experimental.instrumentationHook` option in your `next.config.(js|mjs|ts)` to `undefined`. If you are on Next.js version 14 or lower, you can silence this particular warning by explicitly setting the `experimental.instrumentationHook` option in your `next.config.(js|mjs)` to `true`.",
0 commit comments