Skip to content

feat(nextjs): Warn when Next.js production builds miss the instrumentation file - #25603

Merged
s1gr1d merged 2 commits into
developfrom
sig/js-734-trpc-server-errors-not-sent-from-vercel-deployment-local
Oct 23, 2026
Merged

s1gr1d merged 2 commits 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. Dev and next start with Turbopack still load it, so local testing passes. But on Vercel and in standalone output, the server SDK never initializes.

  • Warns at build time when there is no instrumentation file next to pages/app. It uses the same lookup as Next.js (next build, with pageExtensions).
  • Replaces the webpack-only "Could not find a Next.js instrumentation file" warning, which accepted both folders. Turbopack builds now get the warning too. SENTRY_SUPPRESS_INSTRUMENTATION_FILE_WARNING still turns it off.
  • 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

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 9ac677a (PR test merge using develop at 9927b7c)

Against: 9927b7c (develop) · base run #63346

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

Path Size % Change Change
@sentry/browser 29.98 kB - -
@sentry/browser - with treeshaking flags 28.12 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.02 kB - -
@sentry/browser (incl. Tracing) 52.16 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.16 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.11 kB - -
@sentry/browser (incl. Tracing, Replay) 91.95 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.84 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 96.69 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 109.62 kB - -
@sentry/browser (incl. Feedback) 47.5 kB - -
@sentry/browser (incl. sendFeedback) 35.04 kB - -
@sentry/browser (incl. FeedbackAsync) 40.15 kB - -
@sentry/browser (incl. Metrics) 31 kB - -
@sentry/browser (incl. Logs) 31.27 kB - -
@sentry/browser (incl. Metrics & Logs) 31.93 kB - -
@sentry/react 31.8 kB - -
@sentry/react (incl. Tracing) 54.49 kB - -
@sentry/vue 38.13 kB - -
@sentry/vue (incl. Tracing) 55.1 kB - -
@sentry/svelte 30 kB - -
@sentry/remix (Remix 3 client bundle) 57.19 kB - -
CDN Bundle 31.74 kB - -
CDN Bundle (incl. Tracing) 52.7 kB - -
CDN Bundle (incl. Logs, Metrics) 33.94 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.65 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.92 kB - -
CDN Bundle (incl. Tracing, Replay) 90.4 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 92.32 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.54 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.49 kB - -
CDN Bundle - uncompressed 93.49 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.34 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.04 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 162.31 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 230.25 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 276.69 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 282.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 290.39 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 296.33 kB - -
@sentry/nextjs (client) 57.38 kB - -
@sentry/sveltekit (client) 52.54 kB - -
@sentry/core/server 41.87 kB - -
@sentry/core/browser 13.81 kB - -
@sentry/node 153.13 kB +0.01% +2 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.58 kB - -
@sentry/node - without tracing 94.72 kB - -
@sentry/node - without channel injection 133.76 kB - -
@sentry/aws-serverless 102.88 kB - -
@sentry/cloudflare (withSentry) - minified 193.71 kB - -
@sentry/cloudflare (withSentry) 481.82 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 214.38 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?

Comment thread packages/nextjs/src/config/withSentryConfig/getFinalConfigObjectUtils.ts Outdated
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

@logaretm logaretm 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.

Seems fine to me, although it feels like something Vercel should do.

@s1gr1d s1gr1d changed the title feat(nextjs): Warn when the instrumentation file is in the wrong folder feat(nextjs): Warn when Next.js production builds miss the instrumentation file Oct 23, 2026
@s1gr1d
s1gr1d enabled auto-merge (squash) October 23, 2026 12:13
@s1gr1d
s1gr1d merged commit aa9ffcc into develop Oct 23, 2026
615 of 619 checks passed
@s1gr1d
s1gr1d deleted the sig/js-734-trpc-server-errors-not-sent-from-vercel-deployment-local branch October 23, 2026 13:01
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

3 participants