instrumentation.ts hook. It does not
patch Next.js internals and does not read NEXT_PRIVATE_* variables.
Registration path
stacknext devstarts the collector and the project’sdevscript.- Next.js loads
instrumentation.tsand callsregister(). registerStackNext()checks for an existing OpenTelemetry provider.- StackNext attaches a span processor and exporter when it owns the provider.
- Documented Next.js spans are normalized and sent to the loopback collector.
onRequestErrorsends redacted request errors.
NEXT_RUNTIME === 'nodejs' and imports
@stacknext/next dynamically so Edge bundles do not pull Node-only modules.
Edge instrumentation is not supported even though the import is guarded.
What is captured
- Documented
next.*request, route, render, fetch, action and proxy spans. - HTTP attributes and parent ids preserved from Next.js.
- Drizzle or Prisma query events when an adapter is registered.
- Errors passed to the Next.js error hook.
- Custom spans and wrapped actions from
@stacknext/next.
Existing OpenTelemetry setup
registerStackNext() yields to an already-registered provider. Keep your
existing exporter and call StackNext from the existing register() hook:
stacknext status and stacknext coverage.
Supported versions
Next.js 15 and 16 with the App Router on the Node.js runtime. The supported peer range is>=15.0.0 <17. A newer major prints a warning in stacknext init until
it is added to the validation matrix. See compatibility.