API Reference

OpenTelemetry

Vendor-neutral observability SDK for traces, metrics, and logs with automatic instrumentation, context propagation, and OTLP export.

Official Documentation ↗
CompatibilityThis documentation covers version OpenTelemetry JS 1.x; auto-instrumentation support depends on library versions. Check the official docs for the latest API surface.

Installation

npmnpm install @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node @opentelemetry/exporter-trace-otlp-http
pnpmpnpm add @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node @opentelemetry/exporter-trace-otlp-http
yarnyarn add @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node @opentelemetry/exporter-trace-otlp-http

Methods

OpenTelemetry is a vendor-neutral standard for traces, metrics, and logs. In Node.js, the SDK wires instrumentation, context propagation, and exporters. It does not store data; you choose the backend and retention.

Start before the app

Initialize the SDK before importing instrumented libraries. Use --import for a tracing module or import it first in the entry point. If the SDK starts after the HTTP client loads, spans and propagation can be missing.

Sample and redact

Tracing every request is expensive. Sample high-volume traffic and keep error and slow traces. Span attributes can contain secrets or personal data; apply the same redaction rules as logs. Propagate W3C trace context through HTTP and message headers.

Flush on shutdown

The exporter buffers telemetry. Stop accepting traffic, finish in-flight work, and call sdk.shutdown() before exiting. Without it, the last traces before a deploy or crash are lost.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://opentelemetry.io/docs/languages/js/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:19.276Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

Does OpenTelemetry send data to a vendor by itself?
No. It provides APIs and SDKs; you choose an exporter such as OTLP, a collector, or a vendor backend. The data destination and retention are your responsibility.
Why are some spans missing?
Common causes are starting the SDK after libraries load, missing context propagation, sampling, or not flushing on shutdown. Check the tracer provider and the exporter endpoint.
Is automatic instrumentation enough?
It covers common HTTP, database, and framework calls, but business operations and custom transports need manual spans. Add attributes that help diagnosis without leaking personal data.