Skip to content

feat(nextjs): Warn when the instrumentation file is in the wrong folder - #25603

Open
s1gr1d wants to merge 1 commit into
developfrom
sig/js-734-trpc-server-errors-not-sent-from-vercel-deployment-local
Open

s1gr1d wants to merge 1 commit into
developfrom
sig/js-734-trpc-server-errors-not-sent-from-vercel-deployment-local

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

With src/app and a root instrumentation.ts (or app/ and src/instrumentation.ts), next build does not pick up the file. It still runs in dev and in next start with Turbopack, so local testing passes. But on Vercel and in standalone output, the server SDK never initializes.

  • Adds a build-time warning that uses the same lookup as Next.js (the parent of pages/app, with pageExtensions).
  • Runs with webpack and Turbopack. The existing webpack-only check accepted both locations.
  • Warns once, even when Next.js loads the config in child processes.

This is only a warning because Next.js decides which file it deploys, we can only warn users.

Upstream: vercel/next.js#68740 (other users hit the same cause)

Fixes #17024
Docs: getsentry/sentry-docs#20125

@s1gr1d
s1gr1d requested a review from a team as a code owner October 21, 2026 09:36
@s1gr1d
s1gr1d requested review from chargome and nicohrubec and removed request for a team October 21, 2026 09:36
@linear-code

linear-code Bot commented Oct 21, 2026

Copy link
Copy Markdown

JS-734

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 7e1b13b (PR test merge using develop at a01cfca)

Against: a01cfca (develop) · base run #62876

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 29.91 kB - -
@sentry/browser - with treeshaking flags 28.04 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.95 kB - -
@sentry/browser (incl. Tracing) 52.1 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.1 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.04 kB - -
@sentry/browser (incl. Tracing, Replay) 91.85 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.72 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 96.58 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 109.52 kB - -
@sentry/browser (incl. Feedback) 47.42 kB - -
@sentry/browser (incl. sendFeedback) 34.97 kB - -
@sentry/browser (incl. FeedbackAsync) 40.07 kB - -
@sentry/browser (incl. Metrics) 30.93 kB - -
@sentry/browser (incl. Logs) 31.21 kB - -
@sentry/browser (incl. Metrics & Logs) 31.84 kB - -
@sentry/react 31.73 kB - -
@sentry/react (incl. Tracing) 54.41 kB - -
@sentry/vue 38.06 kB - -
@sentry/vue (incl. Tracing) 55.03 kB - -
@sentry/svelte 29.93 kB - -
@sentry/remix (Remix 3 client bundle) 57.11 kB - -
CDN Bundle 31.67 kB - -
CDN Bundle (incl. Tracing) 52.61 kB - -
CDN Bundle (incl. Logs, Metrics) 33.87 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.55 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.79 kB - -
CDN Bundle (incl. Tracing, Replay) 90.28 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 92.21 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.42 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.37 kB - -
CDN Bundle - uncompressed 93.29 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.14 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.83 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 162.1 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.87 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 276.31 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 282.25 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 290.01 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 295.94 kB - -
@sentry/nextjs (client) 57.3 kB - -
@sentry/sveltekit (client) 52.48 kB - -
@sentry/core/server 41.8 kB - -
@sentry/core/browser 13.81 kB - -
@sentry/node 155.31 kB -0.01% -1 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 84.06 kB - -
@sentry/node - without tracing 96.95 kB -0.01% -1 B 🔽
@sentry/node - without channel injection 133.29 kB -0.01% -1 B 🔽
@sentry/aws-serverless 105.12 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 211.11 kB - -
@sentry/cloudflare (withSentry) 523.83 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 230.74 kB - -

View base workflow run

@s1gr1d

s1gr1d commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 26e519d. Configure here.

getBuildLogger(userSentryOptions.silent).warn(
`[@sentry/nextjs] Found ${misplacedFile}, but Next.js production builds only pick up the instrumentation file next to your ${routerDir} directory. Move it to ${path.join(loadedDir, path.basename(misplacedFile))}, or the Sentry SDK may not be initialized on the server in production.`,
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feat lacks integration or E2E test

Low Severity

This feat is covered only by unit tests that call warnIfMisplacedInstrumentationFile against a temp fixture. This is flagged because the review rules ask feat PRs to include at least one integration or E2E test, for example asserting that next build actually emits the warning for a misplaced instrumentation.ts.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 26e519d. Configure here.

@nicohrubec nicohrubec left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there also seems to be a build time log for webpack that checks for missing instrumentation files. we could probably remove this check then and only keep this one so we don't get double warnings?

const exists = (relativePath: string): boolean => fs.existsSync(path.join(projectDir, relativePath));

// Same lookup as Next.js' `findPagesDir`: `pages` before `app`, and `<name>` before `src/<name>`.
const routerDir = ['pages', 'app'].flatMap(name => [name, path.join('src', name)]).find(exists);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const routerDir = ['pages', 'app'].flatMap(name => [name, path.join('src', name)]).find(exists);
const routerDir = ['pages', path.join('src', 'pages'), 'app', path.join('src', 'app')].find(exists);

just a suggestion for readability, imo this is a bit more explicit and easier to understand at first glance

return;
}

const loadedDir = path.dirname(routerDir);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to show the user in what wrong location the instrumentation file is? as in could we not just simplify this logic to:

  1. get the path where we expect the instrumentation file to live
  2. check whether its there
  3. if not log something like "Could not find a server instrumentation file next to {router_dir}. Create {router_dir}/instrumentation.{extension}, or move your existing instrumentation file there."

I'd assume a user will know where he placed this file or can easily find out and less logic that might be buggy

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tRPC server errors not sent from vercel deployment. Local works fine

2 participants