Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nextjs): Un experimentify clientInstrumentationHook #15992

Merged
merged 3 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Work in this release was contributed by @Page-. Thank you for your contribution!

- **feat(nextjs): Support `instrumentation-client.ts` ([#15705](https://github.com/getsentry/sentry-javascript/pull/15705))**

Next.js recently added a feature to support [client-side (browser) instrumentation via the `experimental.clientInstrumentationHook` flag and the `instrumentation-client.ts` file](https://nextjs.org/docs/app/api-reference/config/next-config-js/clientInstrumentationHook).
Next.js recently added a feature to support [client-side (browser) instrumentation via a `instrumentation-client.ts` file](https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client).

To be forwards compatible, the Sentry Next.js SDK will now pick up `instrumentation-client.ts` files even on older Next.js versions and add them to your client bundles.
It is suggested that you either rename your `sentry.client.config.ts` file to `instrumentation-client.ts`, or if you already happen to have a `instrumentation-client.ts` file move the contents of `sentry.client.config.ts` to `instrumentation-client.ts`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/node": "^18.19.1",
"@types/react": "18.0.26",
"@types/react-dom": "18.0.9",
"next": "15.3.0-canary.26",
"next": "15.3.0-canary.40",
"react": "rc",
"react-dom": "rc",
"typescript": "~5.0.0"
Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export type NextConfigObject = {
// Next.js experimental options
experimental?: {
instrumentationHook?: boolean;
clientInstrumentationHook?: boolean;
clientTraceMetadata?: string[];
};
productionBrowserSourceMaps?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export function constructWebpackConfigFunction(
if (clientSentryConfigFileName) {
// eslint-disable-next-line no-console
console.warn(
`[@sentry/nextjs] DEPRECATION WARNING: It is recommended renaming your \`${clientSentryConfigFileName}\` file, or moving its content to \`instrumentation-client.ts\`. When using Turbopack \`${clientSentryConfigFileName}\` will no longer work. Read more about the \`instrumentation-client.ts\` file: https://nextjs.org/docs/app/api-reference/config/next-config-js/clientInstrumentationHook`,
`[@sentry/nextjs] DEPRECATION WARNING: It is recommended renaming your \`${clientSentryConfigFileName}\` file, or moving its content to \`instrumentation-client.ts\`. When using Turbopack \`${clientSentryConfigFileName}\` will no longer work. Read more about the \`instrumentation-client.ts\` file: https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client`,
);
}
}
Expand Down
22 changes: 2 additions & 20 deletions packages/nextjs/src/config/withSentryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,10 @@ function getFinalConfigObject(
minor === 3 &&
patch === 0 &&
prerelease.startsWith('canary.') &&
parseInt(prerelease.split('.')[1] || '', 10) >= 8;
parseInt(prerelease.split('.')[1] || '', 10) >= 28;
const supportsClientInstrumentation = isSupportedCanary || isSupportedVersion;

if (supportsClientInstrumentation) {
incomingUserNextConfigObject.experimental = {
clientInstrumentationHook: true,
...incomingUserNextConfigObject.experimental,
};
} else if (process.env.TURBOPACK) {
if (!supportsClientInstrumentation && process.env.TURBOPACK) {
if (process.env.NODE_ENV === 'development') {
// eslint-disable-next-line no-console
console.warn(
Expand All @@ -194,19 +189,6 @@ function getFinalConfigObject(
);
}
}
} else {
// If we cannot detect a Next.js version for whatever reason, the sensible default is still to set the `experimental.instrumentationHook`.
incomingUserNextConfigObject.experimental = {
clientInstrumentationHook: true,
...incomingUserNextConfigObject.experimental,
};
}

if (incomingUserNextConfigObject.experimental?.clientInstrumentationHook === false) {
// eslint-disable-next-line no-console
console.warn(
'[@sentry/nextjs] WARNING: You set the `experimental.clientInstrumentationHook` option to `false`. Note that Sentry will not be initialized if you did not set it up inside `instrumentation-client.(js|ts)`.',
);
}

return {
Expand Down
Loading