Getting Started • API and SDK Reference
<a href="https://github.com/open-telemetry/opentelemetry-js/actions">
<img alt="Build Status" src="https://github.com/open-telemetry/opentelemetry-js/actions/workflows/unit-test.yml/badge.svg?style=shield">
This is the JavaScript version of OpenTelemetry, a framework for collecting traces, metrics, and logs from applications.
Much of OpenTelemetry JS documentation is written assuming the compiled application is run as CommonJS. For more details on ECMAScript Modules vs CommonJS, refer to esm-support.
The following describes how to set up tracing for a basic web application. For more detailed documentation, see the website at https://opentelemetry.io/docs/instrumentation/js/.
Dependencies with the latest tag on NPM should be compatible with each other.
See the version compatibility matrix below for more information.
npm install --save @opentelemetry/api
npm install --save @opentelemetry/sdk-node
npm install --save @opentelemetry/auto-instrumentations-node
Note: auto-instrumentations-node is a meta package from opentelemetry-js-contrib that provides a simple way to initialize multiple Node.js instrumentations.
// tracing.js
'use strict'
const process = require('process');
const opentelemetry = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace');
const { resourceFromAttributes } = require('@opentelemetry/resources');
const { ATTR_SERVICE_NAME } = require('@opentelemetry/semantic-conventions');
// configure the SDK to export telemetry data to the console
// enable all auto-instrumentations from the meta package
const traceExporter = new ConsoleSpanExporter();
const sdk = new opentelemetry.NodeSDK({
resource: resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'my-service',
}),
traceExporter,
instrumentations: [getNodeAutoInstrumentations()]
});
// initialize the SDK and register with the OpenTelemetry API
// this enables the API to record telemetry
sdk.start();
// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
sdk.shutdown()
.then(() => console.log('Tracing terminated'))
.catch((error) => console.log('Error terminating tracing', error))
.finally(() => process.exit(0));
});
node -r ./tracing.js app.js
The above example will emit auto-instrumented telemetry about your Node.js application to the console. For a more in-depth example, see the Getting Started Guide.
It's possible that an application instrumented as outlined above may not be behaving in an expected manner. For example, if the application is meant to be sending data to an Open Telemetry collector, that collector may not be receiving any data. Insight into such issues can be gained by enabling a diagnostics logger:
// Added as additional configuration to tracing.js
const {
diag,
DiagConsoleLogger,
DiagLogLevel
} = require('@opentelemetry/api');
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
If you are a library author looking to build OpenTelemetry into your library, please see [the documentation][docs]. As a library author, it is important that you only depend on properties and methods published on the public API. If you use any properties or methods from the SDK that are not officially a part of the public API, your library may break if an application owner uses a different SDK implementation.
| Platform Version | Supported |
|---|---|
Node.js v24 |
:heavy_check_mark: |
Node.js v22 |
:heavy_check_mark: |
Node.js v20 |
:heavy_check_mark: |
Node.js v18 |
:heavy_check_mark: |
| Older Node Versions | See Node Support |
| Web Browsers | See Browser Support below |
Only Node.js Active or Maintenance LTS versions are supported. Previous versions of node may work, but they are not tested by OpenTelemetry and they are not guaranteed to work.
[!IMPORTANT] Client instrumentation for the browser is experimental and mostly unspecified. If you are interested in helping out, get in touch with the [Client Instrumentation SIG][client-instrumentation-sig].
Rather than define versions of specific browsers / runtimes, OpenTelemetry sets the minimum supported version based on the underlying language features used.
The current minimum language feature support is set as ECMAScript 2022 that are available in all modern browsers / runtimes.
This means that if you are targeting or your end-users are using a browser / runtime that does not support ES2022, you will need to transpile the code and provide any necessary polyfills for the missing features to ensure compatibility with your target environments. Any support issues that arise from using a browser or runtime that does not support ES2022 will be closed as "won't fix".
This minimum support level is subject to change as the project evolves and as the underlying language features evolve.
OpenTelemetry JavaScript is built with TypeScript v5.0.4. If you have a TypeScript project (app, library, instrumentation, etc.)
that depends on it, we recommend using same or higher version to compile the project.
OpenTelemetry JavaScript will follow DefinitelyType's support policy for TypeScript which sets a support window of 2 years. Support for TypeScript versions older than 2 years will be dropped in minor releases of OpenTelemetry JavaScript.
OpenTelemetry is released as a set of distinct packages in 3 categories: API, stable SDK, and experimental. The API is located at /api, the stable SDK packages are in the /packages directory, and the experimental packages are listed in the /experimental/packages directory. There may also be API packages for experimental signals in the experimental directory. All stable packages are released with the same version, and all experimental packages are released with the same version. The below table describes which versions of each set of packages are expected to work together.
| Stable Packages | Experimental Packages |
|---|---|
| 2.0.x | 0.200.x |
| 1.30.x | 0.57.x |
| 1.29.x | 0.56.x |
| 1.28.x | 0.55.x |
| 1.27.x | 0.54.x |
| 1.25.x | 0.52.x |
Older version compatibility matrix
| Stable Packages | Experimental Packages |
|---|---|
| 1.24.x | 0.51.x |
| 1.23.x | 0.50.x |
| 1.22.x | 0.49.x |
| 1.21.x | 0.48.x |
| 1.20.x | 0.47.x |
| 1.19.x | 0.46.x |
| 1.18.x | 0.45.x |
| 1.17.x | 0.43.x, 0.44.x |
| 1.16.x | 0.42.x |
| 1.15.x | 0.41.x |
| 1.14.x | 0.40.x |
| 1.13.x | 0.39.x |
| 1.12.x | 0.38.x |
| 1.11.x | 0.37.x |
| 1.10.x | 0.36.x |
| 1.9.x | 0.35.x |
| 1.8.x (this and later versions require API >=1.3.0 for metrics) | 0.34.x |
| 1.7.x | 0.33.x |
| 1.6.x | 0.32.x |
| 1.5.x | 0.31.x |
| 1.4.x | 0.30.x |
| 1.3.x | 0.29.x |
| 1.2.x | 0.29.x |
| 1.1.x | 0.28.x |
| 1.0.x | 0.27.x |
| 1.0.x (this and later versions require API >=1.0.0 for traces) | 0.26.x |
The current version for each package can be found in the respective package.json file for that module. For additional details see the [versioning and stability][spec-versioning] docu
$ claude mcp add opentelemetry-js \
-- python -m otcore.mcp_server <graph>