Sourcemap Explorer
Stack · npm package

@opentelemetry/api

Public API for OpenTelemetry

latest 1.9.1· Apache-2.0· 64 versions publishedView on npm

About

Public API for OpenTelemetry

opentelemetrynodejsbrowsertracingprofilingstatsmonitoring

Live mirror of the GitHub README. Updated whenever the repo's default branch changes.


Getting Started   •   API and SDK Reference

GitHub release (latest by date including pre-releases) Codecov Status license
Build Status Beta

Contributing   •   Examples


About this project

This is the JavaScript version of OpenTelemetry, a framework for collecting traces, metrics, and logs from applications.

Quick Start

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/.

Installation

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.

Set up Tracing

// 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-base');
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));
});

Run Your Application

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. For more information about automatic instrumentation see @opentelemetry/sdk-trace-node, which provides auto-instrumentation for Node.js applications. If the automatic instrumentation does not suit your needs, or you would like to create manual traces, see @opentelemetry/sdk-trace-base

Debugging The Setup

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);

Library Author

If you are a library author looking to build OpenTelemetry into your library, please see the documentation. 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.

Supported Runtimes

Platform VersionSupported
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 VersionsSee Node Support
Web BrowsersSee Browser Support below

Node Support

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.

Browser Support

[!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.

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.

TypeScript Support

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.

Package Version Compatibility

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 PackagesExperimental Packages
2.0.x0.200.x
1.30.x0.57.x
1.29.x0.56.x
1.28.x0.55.x
1.27.x0.54.x
1.25.x0.52.x
Older version compatibility matrix
Stable PackagesExperimental Packages
1.24.x0.51.x
1.23.x0.50.x
1.22.x0.49.x
1.21.x0.48.x
1.20.x0.47.x
1.19.x0.46.x
1.18.x0.45.x
1.17.x0.43.x, 0.44.x
1.16.x0.42.x
1.15.x0.41.x
1.14.x0.40.x
1.13.x0.39.x
1.12.x0.38.x
1.11.x0.37.x
1.10.x0.36.x
1.9.x0.35.x
1.8.x (this and later versions require API >=1.3.0 for metrics)0.34.x
1.7.x0.33.x
1.6.x0.32.x
1.5.x0.31.x
1.4.x0.30.x
1.3.x0.29.x
1.2.x0.29.x
1.1.x0.28.x
1.0.x0.27.x
1.0.x (this and later versions require API >=1.0.0 for traces)0.26.x

Versioning

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 document in the specification.

Feature Status

SignalAPI StatusSDK Status
TracingStableStable
MetricsStableStable
LogsDevelopmentDevelopment

For a more detailed breakdown of feature support see the specification compliance matrix.

Contributing

We'd love your help! Use tags up-for-grabs and good first issue to get started with the project. For instructions to build and make changes to this project, see the CONTRIBUTING guide.

We have a weekly SIG meeting! See the community page for meeting details and notes.

Maintainers

For more information about the maintainer role, see the community repository.

Approvers

In addition, Browser SIG Maintainers are granted the Approver role for browser-targeted packages as defined in this repository's CODEOWNERS file.

For more information about the approver role, see the community repository.

Triagers

Members of this team have triager permissions for opentelemetry-js.git and opentelemetry-js-contrib.git.

  • N/A

For more information about the triager role, see the community repository.

Contrib Triagers

Members of this team have triager permissions for opentelemetry-js-contrib.git. Typically, members of this are component owners of one or more packages in the contrib repo.

For more information about the triager role, see the community repository.

Emeritus

For more information about the emeritus role, see the community repository.

Thanks to all of our contributors!

Repo contributors

Packages

API

PackageDescription
@opentelemetry/apiThis package provides TypeScript interfaces, enums and no-op implementations for the OpenTelemetry core trace and metrics model. It is intended for use both on the server and in the browser.
@opentelemetry/coreThis package provides default and no-op implementations of the OpenTelemetry api for trace and metrics. It's intended for use both on the server and in the browser.

Implementation / SDKs

PackageDescription
@opentelemetry/sdk-trace-baseThis module provides a full control over instrumentation and span creation. It doesn't load async_hooks or any instrumentation by default. It is intended for use both on the server and in the browser.
@opentelemetry/sdk-metricsThis module provides instruments and meters for reporting of time series data.
@opentelemetry/sdk-trace-nodeThis module provides automatic tracing for Node.js applications. It is intended for use on the server only.
@opentelemetry/sdk-trace-webThis module provides automated instrumentation and tracing for Web applications. It is intended for use in the browser only.

Compatible Exporters

OpenTelemetry is vendor-agnostic and can upload data to any backend with various exporter implementations. Even though, OpenTelemetry provides support for many backends, vendors/users can also implement their own exporters for proprietary and unofficially supported backends.

See the OpenTelemetry registry for a list of exporters available.

Instrumentations

OpenTelemetry can collect tracing data automatically using instrumentations.

To request automatic tracing support for a module not on this list, please file an issue. Alternatively, Vendor/Users can write an instrumentation yourself.

Currently, OpenTelemetry supports automatic tracing for:

Node Instrumentations
Core
Contrib

These instrumentations are hosted at https://github.com/open-telemetry/opentelemetry-js-contrib/tree/master/plugins/node

Web Instrumentations
Core
Contrib

These instrumentations are hosted at https://github.com/open-telemetry/opentelemetry-js-contrib/tree/master/plugins/web

Shims

PackageDescription
@opentelemetry/shim-opentracingOpenTracing shim allows existing OpenTracing instrumentation to report to OpenTelemetry

Useful links

License

Apache 2.0 - See LICENSE for more information.

Quick facts

Latest version1.9.1
LicenseApache-2.0
AuthorOpenTelemetry Authors
Installnpm install @opentelemetry/api
Direct dependencies0

How Sourcemap Explorer detects @opentelemetry/api

We catch @opentelemetry/api from two complementary signals: bundled source paths and the embedded package.json. Modern bundlers (webpack, Vite, esbuild, Rollup, Turbopack) preserve the original node_modules/@opentelemetry/api/ paths inside the JavaScript sourcemap's sources[] array — that's the canonical signal. When the matching package.json is also captured in sourcesContent[], we read the exact version field — patch number included. No regex guessing, no version inference.

  1. 1

    Confirm the site exposes sourcemaps

    In DevTools Network, check the response headers of any application script for `SourceMap` or `X-SourceMap`. Failing that, fetch the script's last 4 KB and look for a `//# sourceMappingURL=` comment.

  2. 2

    Find the package in the bundle

    Open DevTools → Network → reload. Click any application script and look at its sourcemap. Inside, search `sources[]` for entries matching `node_modules/@opentelemetry/api/` — every match confirms the package is bundled. The matching `sourcesContent[i]` for `node_modules/@opentelemetry/api/package.json` gives you the exact installed version.

  3. 3

    Read the version directly from package.json

    Run `jq -r '. as $m | $m.sources | to_entries[] | select(.value | endswith("node_modules/@opentelemetry/api/package.json")) | $m.sourcesContent[.key] | fromjson | .version' bundle.js.map`. Sourcemap Explorer automates the same query in the popup.

Recent versions

Version
Released
0.4.0
0.5.0
0.5.1
0.5.2
0.6.0
0.6.1
0.7.0
0.8.0

FAQ

What is @opentelemetry/api used for?

Public API for OpenTelemetry

How can I tell if a website is using @opentelemetry/api?

Open the page in Chrome with the Sourcemap Explorer extension installed and read the Stack tab. We catch `@opentelemetry/api` from two complementary signals: `node_modules/@opentelemetry/api/` paths inside the JavaScript sourcemap, and the embedded `package.json` we read for exact-version detection. Without the extension you can do the same lookup manually in DevTools — the steps are listed in the "How Sourcemap Explorer detects" section above.

What is the latest version of @opentelemetry/api?

1.9.1, as published on the npm registry. The "Recent versions" table on this page lists the most recent 8 releases with their release dates. Sourcemap Explorer reports the version actually bundled into a site, which can lag the latest release by months on real-world deployments.

Where can I read more?

Project homepage: https://github.com/open-telemetry/opentelemetry-js/tree/main/api. Source code: https://github.com/open-telemetry/opentelemetry-js. Published on npm: https://www.npmjs.com/package/@opentelemetry/api. Licensed as Apache-2.0.

Detected by Sourcemap Explorer

When a bundle ships sourcemaps, we read the embedded package.json for @opentelemetry/api and report the precise version. Without sourcemaps, an import / require in the page's scripts is enough to flag it.

Install free on Chrome