register()
The function exported from instrumentation.ts that Next.js calls once when a new server instance starts.
In more detail
Use it to start the OpenTelemetry SDK or other monitoring. Check process.env.NEXT_RUNTIME to import Node-only code only in the Node.js runtime.
Example
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') await import('./instrumentation.node');
}Related terms
- instrumentation — Code, often a library, that makes an application emit telemetry about its operations.
- NEXT_RUNTIME — An environment variable Next.js sets to nodejs or edge so code can tell which runtime it is running in.
- OpenTelemetry — A vendor-neutral, open-source standard and set of tools for producing traces, metrics and logs and sending them to any backend.
Taught in
- Instrumentation: OpenTelemetry & Performance Spans — Next.js 15 & Modern App Router Architecture