You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a Next.js 16 app deployed on Netlify via @netlify/plugin-nextjs, the Next.js instrumentation.ts hook never fires on serverless function cold-starts. As a result, Sentry.init() (called from inside register()) never runs, Sentry.getClient() returns undefined in API route handlers, and Sentry.captureException(...) calls return an event ID but Sentry.flush() returns false — events are dropped before transport.
The Sentry project receives events from other paths (Sentry CLI synthetic test, dashboard "Send Test Event"), so DSN config and network reachability are confirmed. Only in-app captures via the SDK fail.
The DSN env var is set on Netlify and accessible to the function (hasDSN: true), but Sentry.getClient() returns undefined → Sentry.init() was never executed in this Lambda's cold-start.
What I tried
Static imports in instrumentation.ts (per the OpenNext common-issues recommendation):
sentry.server.config.ts and sentry.edge.config.ts were refactored to export named init functions instead of calling Sentry.init() at module top-level. Did not fix.
outputFileTracingIncludes in next.config.ts to force-include the files in the Lambda bundle:
After this, sentryClientPresent: true, flushed: true, and events land in Sentry within seconds. This confirms the SDK, the DSN, and the network path are all functional — the only failure is instrumentation.ts's register() not being invoked.
Hypothesis
@netlify/plugin-nextjs (built on opennextjs-netlify) bundles each Next.js route as an independent Lambda. The cold-start of those Lambdas appears to load the route handler directly without invoking Next.js's instrumentation hook, even though Next.js 15+ documents instrumentation.ts as auto-invoked at server startup.
This may need either:
A change in the Netlify adapter to call register() on cold-start, or
Documentation guidance recommending a different init pattern for users on Netlify
Reference
OpenNext common-issues page calls out dropped dynamic imports in instrumentation.ts (which I addressed via the static-import refactor in #1 above). The static-import fix alone, however, was insufficient in this case — the file appears not to be evaluated at all on Lambda cold-start.
Summary
In a Next.js 16 app deployed on Netlify via
@netlify/plugin-nextjs, the Next.jsinstrumentation.tshook never fires on serverless function cold-starts. As a result,Sentry.init()(called from insideregister()) never runs,Sentry.getClient()returnsundefinedin API route handlers, andSentry.captureException(...)calls return an event ID butSentry.flush()returnsfalse— events are dropped before transport.The Sentry project receives events from other paths (Sentry CLI synthetic test, dashboard "Send Test Event"), so DSN config and network reachability are confirmed. Only in-app captures via the SDK fail.
Stack
^16.2.4@sentry/nextjs^10.51.0@netlify/plugin-nextjs^5.15.10process.env.NEXT_RUNTIME)nodejsSymptom
A diagnostic API route handler returned:
{ "runtime": "nodejs", "nodeEnv": "production", "hasDSN": true, "dsnMasked": "o....ingest.us.sentry.io/projects/...", "sentryClientPresent": false, "sentryEnabled": false, "sentryDsnInClient": false, "captureResult": "eventId=<uuid> flushed=false" }The DSN env var is set on Netlify and accessible to the function (
hasDSN: true), butSentry.getClient()returns undefined →Sentry.init()was never executed in this Lambda's cold-start.What I tried
Static imports in
instrumentation.ts(per the OpenNext common-issues recommendation):sentry.server.config.tsandsentry.edge.config.tswere refactored to export named init functions instead of callingSentry.init()at module top-level. Did not fix.outputFileTracingIncludesinnext.config.tsto force-include the files in the Lambda bundle:Did not fix when applied alongside Add in next on netlify banner, some copy changes for the plugin #1.
withSentryConfigwrapper withorg,project,silent,widenClientFileUpload— present and correct; source maps upload successfully on deploy.Workaround that works
Adding an explicit
Sentry.init()at the top of the route file makes everything work:After this,
sentryClientPresent: true,flushed: true, and events land in Sentry within seconds. This confirms the SDK, the DSN, and the network path are all functional — the only failure isinstrumentation.ts'sregister()not being invoked.Hypothesis
@netlify/plugin-nextjs(built onopennextjs-netlify) bundles each Next.js route as an independent Lambda. The cold-start of those Lambdas appears to load the route handler directly without invoking Next.js's instrumentation hook, even though Next.js 15+ documentsinstrumentation.tsas auto-invoked at server startup.This may need either:
register()on cold-start, orReference
OpenNext common-issues page calls out dropped dynamic imports in
instrumentation.ts(which I addressed via the static-import refactor in #1 above). The static-import fix alone, however, was insufficient in this case — the file appears not to be evaluated at all on Lambda cold-start.Happy to provide a minimal repro repo if useful.