Instrumentation entry points
What you need to know
Instrumentation is code that observes application behavior. Next.js provides separate server and client entry points, letting you initialize tools in the runtime where they belong.
By the end, you can: choose server or client registration; describe runtime constraints.
Register a runtime-specific local marker
export async function register(){ if(process.env.NEXT_RUNTIME==='nodejs'){ const {markStart}=await import('./lib/server-marker'); markStart(); }}Expected behavior: Place at instrumentation.ts; the companion module marks startup locally. Edge does not load the Node-specific module.
How it works
Place instrumentation.ts at the application root (or src if the app uses src). Its register export is called when a server instance initializes; this is not a per-request handler or a guarantee of exactly one call across all replicas. Keep runtime-dependent imports inside appropriate NEXT_RUNTIME checks; Node-only packages cannot be assumed to work in Edge. The onRequestError export can observe errors captured by the framework. Await any asynchronous reporting that must finish within that hook, and do not assume every caught business exception triggers it. In instrumentation-client.ts initialize small browser-only diagnostics early; avoid blocking startup. Use OpenTelemetry-compatible traces when a reviewed SDK and exporter are available. Here no external exporter is installed or contacted.
Mark the client initialization point
performance.mark('river-books:client-init');Expected behavior: Place at instrumentation-client.ts. A supported browser can show the mark in a performance recording; it is not a hydration-completion measurement.
Common mistake
Importing a Node-only exporter at module top level and checking the runtime afterward is too late to guarantee compatibility. Do not send all browser data to an unknown collector.
Practice and verification
Locate each entrypoint in the fixture. Explain whether it runs on initialization, per error or per browser startup. Test a new process and a deliberate local request failure after a reviewed build.
Scope: Proposed Next.js 16.x / React 19, App Router with Cache Components disabled unless noted. Framework and browser examples are staged, not executed. Synthetic numbers are not measured performance or actual provider rates.
Further reading: Instrumentation · Instrumentation Client