Skip to content

Commit d95ef57

Browse files
authored
feat(nextjs): Allow silencing of instrumentation warning (#15555)
1 parent f5cccfb commit d95ef57

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,20 +477,23 @@ function warnAboutMissingOnRequestErrorHandler(projectDir: string): void {
477477
}
478478

479479
if (!instrumentationFile) {
480-
// eslint-disable-next-line no-console
481-
return console.warn(
482-
`${chalk.yellow(
483-
'[@sentry/nextjs]',
484-
)} Could not find a Next.js instrumentation file. This indicates an incomplete configuration of the Sentry SDK. An instrumentation file is required for the Sentry SDK to be initialized on the server: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#create-initialization-config-files`,
485-
);
480+
if (!process.env.SENTRY_SUPPRESS_INSTRUMENTATION_FILE_WARNING) {
481+
// eslint-disable-next-line no-console
482+
console.warn(
483+
chalk.yellow(
484+
'[@sentry/nextjs] Could not find a Next.js instrumentation file. This indicates an incomplete configuration of the Sentry SDK. An instrumentation file is required for the Sentry SDK to be initialized on the server: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#create-initialization-config-files (you can suppress this warning by setting SENTRY_SUPPRESS_INSTRUMENTATION_FILE_WARNING=1 as environment variable)',
485+
),
486+
);
487+
}
488+
return;
486489
}
487490

488491
if (!hasOnRequestErrorHandler(instrumentationFile)) {
489492
// eslint-disable-next-line no-console
490493
console.warn(
491-
`${chalk.yellow(
492-
'[@sentry/nextjs]',
493-
)} Could not find \`onRequestError\` hook in instrumentation file. This indicates outdated configuration of the Sentry SDK. Use \`Sentry.captureRequestError\` to instrument the \`onRequestError\` hook: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#errors-from-nested-react-server-components`,
494+
chalk.yellow(
495+
'[@sentry/nextjs] Could not find `onRequestError` hook in instrumentation file. This indicates outdated configuration of the Sentry SDK. Use `Sentry.captureRequestError` to instrument the `onRequestError` hook: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#errors-from-nested-react-server-components',
496+
),
494497
);
495498
}
496499
}

0 commit comments

Comments
 (0)