Sentry question
Why does Sentry not capture server errors in my Next.js app on Vercel?
Sentry sends nothing from the server of a Next.js app when instrumentation.ts is not in the folder Next.js loads it from, and it misses errors thrown in nested Server Components when that file does not export onRequestError. Next.js reads instrumentation.ts only from the project root, or from src when the app uses a src folder, next to app. Its register function must load the Sentry server config, and the file must export onRequestError = Sentry.captureRequestError, which Sentry says needs @sentry/nextjs 8.28.0 or later and Next.js 15. Rebuild, throw a test error inside a nested Server Component, and look for it in Sentry. Reproduced with @sentry/nextjs 11.10.0 and next 15.5.28 on 2026-10-31.
Sentry logs nothing on the server: "Could not find an instrumentation file"
When next build cannot find instrumentation.ts next to your app folder, @sentry/nextjs prints a warning and the server SDK is never started. In our run the file sat in src/ while app/ was in the project root. The build warned, the server logged no "Initializing SDK" line, and a Server Component, a route handler and a middleware that all threw sent no event to a local stub endpoint. The Next.js docs say the file goes in the root of the project, or inside src next to app and pages, and not inside app or pages.
[@sentry/nextjs] Could not find an instrumentation file next to your app directory. Next.js production builds only load it from there, so the Sentry SDK will not be initialized on the server. Create instrumentation.ts, or move your existing instrumentation file there: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#register-server-side-sdkSome server errors arrive and others do not
The SDK wraps pages, route handlers and middleware itself. An error thrown by a component rendered inside a page is not covered by those wrappers; Next.js reports it to the onRequestError export of instrumentation.ts, and the Sentry docs name Server Components, middleware and proxies as what that hook captures. The build prints a warning when the file has no onRequestError (the real message wraps the name in backticks). Our results in a production build of next 15.5.28, with the stub endpoint counting events:
instrumentation.ts without onRequestError
page throws captured (auto.function.nextjs.server_component)
route handler throws captured (auto.function.nextjs.route_handler)
middleware throws captured (auto.function.nextjs.wrap_middleware)
nested component throws NOT captured
instrumentation.ts with onRequestError = Sentry.captureRequestError
nested component throws captured (auto.function.nextjs.on_request_error)
build warning without the export:
[@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 hookBoth files are right and the server is still silent
The server config still needs a DSN at runtime, and on Vercel a variable added after the last deploy only reaches new deployments. Set the DSN for Production and Preview, redeploy, and turn on debug: true in the server init for one deploy: a working init logs "Initializing SDK" in the server output. The build also prints "It seems like you don't have a global error handler set up" when app/global-error.tsx is missing, which is where React render errors in the App Router are reported. For a DSN that is read but arrives as text, see the Invalid Sentry Dsn page.
Checklist
How to fix it, then check the fix
- 01Find where your app folder is and where instrumentation.ts is. They must sit in the same parent folder:
ls -d app src/app 2>/dev/null; ls instrumentation.* src/instrumentation.* 2>/dev/null - 02Move the file next to app, and make it load the Sentry configs and export the hook. This is the shape from Sentry's manual setup guide:
import * as Sentry from "@sentry/nextjs"; export async function register() { if (process.env.NEXT_RUNTIME === "nodejs") { await import("./sentry.server.config"); } if (process.env.NEXT_RUNTIME === "edge") { await import("./sentry.edge.config"); } } export const onRequestError = Sentry.captureRequestError; - 03Set the DSN the server config reads in Vercel for Production and Preview, then redeploy.
- 04Build and read what Sentry says. A clean setup prints no "Could not find" lines:
npm run build 2>&1 | grep "@sentry/nextjs" - 05Throw a test error from a component rendered inside a page, then from a route handler, on the deployed app. Both should appear in the Sentry project; errors thrown before the fix are not recovered.
Related
Related guides
Sources
Official docs behind this checklist
Browse all launch guides · Read resources · How to make and check your next change
FAQ
FAQ for builders before launch
Do I need onRequestError on Next.js 14?
No. The Next.js docs list onRequestError as introduced in v15.0.0, and Sentry's guide says the hook requires @sentry/nextjs 8.28.0 or higher and Next.js 15.
Why did my route handler error show up but a Server Component error did not?
In our run the SDK wrapped the page, the route handler and the middleware, and only a component rendered inside the page needed the onRequestError export. Add the export and the nested error is reported.
Does the file name change if I use pageExtensions?
Yes. The Next.js docs say that if you add a suffix with the pageExtensions option, the instrumentation file name has to match it.