Skip to content

Next.js OpenTelemetry instrumentation

Next.js loads OpenTelemetry through its built-in instrumentation.ts hook rather than the --require flag used by other Node.js frameworks. Because Next.js bundles server code and runs some routes on the Edge runtime, the supported path is the @vercel/otel package, which configures the SDK for both runtimes and sends traces, metrics, and logs to Osuite over OTLP.

  • Next.js 15 or newer (App Router or Pages Router). On Next.js 13.4–14 the instrumentation hook is behind a flag — see the note below.
  • Node.js 18 or newer.
  • An Osuite ingest token from Settings → API Keys.
  1. Install the package

    Terminal window
    npm install @vercel/otel

    @vercel/otel bundles the OpenTelemetry SDK and OTLP exporters, so no separate exporter packages are required.

  2. Create the instrumentation hook

    Create instrumentation.ts in your project root (or inside src/ if you use a src directory). Next.js calls the exported register function once when the server starts.

    instrumentation.ts
    import { registerOTel } from '@vercel/otel';
    export function register() {
    registerOTel({ serviceName: 'storefront' });
    }

@vercel/otel reads the OTLP endpoint and headers from environment variables and defaults to the HTTP/protobuf transport:

  • OTEL_EXPORTER_OTLP_ENDPOINT — your Osuite ingest endpoint.
  • OTEL_EXPORTER_OTLP_HEADERS — the x-osuite-ingest-token header that authenticates ingestion.
  • OTEL_SERVICE_NAME — the service name that identifies this service in Osuite. Set it to the same name passed as serviceName in the register call above (storefront); if the two disagree, your telemetry is split across two services in Osuite.
  • OTEL_RESOURCE_ATTRIBUTES — additional resource attributes such as service.environment.

Build the app (npm run build) and start it. Choose your deployment target:

Terminal window
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.<region>.osuite.io:443"
export OTEL_EXPORTER_OTLP_HEADERS="x-osuite-ingest-token=<your-ingest-token>"
export OTEL_SERVICE_NAME="storefront"
export OTEL_RESOURCE_ATTRIBUTES="service.environment=production"
npm run start

What you should see

Load a page or call a route handler, then open APM. The storefront service appears within a minute, emitting request-rate and latency metrics. Opening a trace shows the inbound request span with child spans for server-side data fetches and outbound calls.

No data in Osuite after a few minutes? Work through these checks.

  • Endpoint — confirm the exporter targets exactly ingest.<region>.osuite.io:443 for your region, over TLS.
  • Token — confirm the ingest header carries a valid <your-ingest-token> and has not been rotated.
  • Pipeline — confirm the signal you expect (traces, logs, or metrics) is wired into an active pipeline with the otlp/osuite exporter attached.
  • Export errors — check the application or Collector logs for OTLP export failures (auth, DNS, TLS, connection refused).
  • Network — confirm the host has outbound access to the ingest endpoint on port 443.
  • Timing — allow up to a minute for the first data to appear before assuming a failure.

Still stuck? Ask the Investigation Agent or contact support.

For Node-specific issues — including why the instrumentation hook may not fire — see Node.js troubleshooting.