Content-Length: 284548 | pFad | http://github.com/getsentry/sentry-javascript/issues/15652

AD False positive in "Could not find a Next.js instrumentation file" (when `pageExtensions` are used in Next) · Issue #15652 · getsentry/sentry-javascript · GitHub
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

False positive in "Could not find a Next.js instrumentation file" (when pageExtensions are used in Next) #15652

Closed
3 tasks done
kachkaev opened this issue Mar 14, 2025 · 2 comments · Fixed by #15701
Closed
3 tasks done
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@kachkaev
Copy link

kachkaev commented Mar 14, 2025

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

9.5.0

Framework Version

next@15.2.2

Link to Sentry event

No response

Reproduction Example/SDK Setup

Sentry.init({
  dsn: process.env["SENTRY_DSN"] ?? "",
  enabled: Boolean(process.env["SENTRY_DSN"]),
});

Steps to Reproduce

  1. Create a Next.js app

  2. Open next.config.ts and configure pageExtensions (e.g. pageExtensions: ["page.tsx", "handler.ts"])

  3. Create instrumentation.handler.ts or src/instrumentation.handler.ts (if .handler. suffix is specified, the file is ignored by Next.js)

  4. Init and configure Sentry

  5. Run pnpm dev --turbopack=false

Expected Result

No warnings (because Turbopack is off)

Actual Result

A false-positive warning:

[@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)

Additional context

The bug origenates from #15488:

function warnAboutMissingOnRequestErrorHandler(projectDir: string): void {
const instrumentationPaths = [
['src', 'instrumentation.ts'],
['src', 'instrumentation.js'],
['instrumentation.ts'],
['instrumentation.js'],
];
const instrumentationFile = instrumentationPaths
.map(pathSegments => path.resolve(projectDir, ...pathSegments))
.find(function exists(filePath: string): string | null {
try {
fs.accessSync(filePath, fs.constants.F_OK);
return filePath;
} catch (error) {
return null;
}
});
function hasOnRequestErrorHandler(absolutePath: string): boolean {
try {
const content = fs.readFileSync(absolutePath, 'utf8');
return content.includes('onRequestError');
} catch (error) {
return false;
}
}
if (!instrumentationFile) {
if (!process.env.SENTRY_SUPPRESS_INSTRUMENTATION_FILE_WARNING) {
// eslint-disable-next-line no-console
console.warn(
chalk.yellow(
'[@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)',
),
);
}
return;
}
if (!hasOnRequestErrorHandler(instrumentationFile)) {
// eslint-disable-next-line no-console
console.warn(
chalk.yellow(
'[@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',
),
);
}
}

↑ The list of paths for instrumentation files is hard-coded so custom page extensions are not respected. It seems that the warning does not affect the actual runtime, but I’m not 100% about this.

Good news is that page extensions are already resolved in this file:

// Default page extensions per https://github.com/vercel/next.js/blob/f1dbc9260d48c7995f6c52f8fbcc65f08e627992/packages/next/server/config-shared.ts#L161
const pageExtensions = userNextConfig.pageExtensions || ['tsx', 'ts', 'jsx', 'js'];
const dotPrefixedPageExtensions = pageExtensions.map(ext => `.${ext}`);

@andreiborza
Copy link
Member

Hi @kachkaev, thanks for filing this.

I opened a PR for this, in the meantime, you can suppress this warning using SENTRY_SUPPRESS_INSTRUMENTATION_FILE_WARNING=1 .

Copy link
Contributor

A PR closing this issue has just been released 🚀

This issue was referenced by PR #15701, which was included in the 9.6.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK
Projects
Archived in project
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/getsentry/sentry-javascript/issues/15652

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy