OpenTelemetry JavaScript Client
Installations
npm install @opentelemetry/api
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM, UMD
Min. Node Version
>=8.0.0
Node Version
18.19.0
NPM Version
lerna/6.6.2/node@v18.19.0+x64 (linux)
Score
99.4
Supply Chain
100
Quality
81.4
Maintenance
100
Vulnerability
88
License
Releases
experimental/v0.57.1
Published on 14 Jan 2025
v1.30.1
Published on 14 Jan 2025
experimental/v0.57.0
Published on 18 Dec 2024
v1.30.0
Published on 18 Dec 2024
experimental/v0.56.0
Published on 04 Dec 2024
v1.29.0
Published on 04 Dec 2024
Contributors
Languages
TypeScript (97.04%)
JavaScript (2.78%)
Jinja (0.1%)
Shell (0.08%)
Developer
Download Statistics
Total Downloads
1,172,584,545
Last Day
2,766,829
Last Week
12,487,971
Last Month
54,905,303
Last Year
548,346,350
GitHub Statistics
2,828 Stars
2,514 Commits
838 Forks
56 Watching
8 Branches
500 Contributors
Bundle Size
19.78 kB
Minified
5.36 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.9.0
Package Id
@opentelemetry/api@1.9.0
Unpacked Size
1.16 MB
Size
123.81 kB
File Count
642
NPM Version
lerna/6.6.2/node@v18.19.0+x64 (linux)
Node Version
18.19.0
Publised On
05 Jun 2024
Total Downloads
Cumulative downloads
Total Downloads
1,172,584,545
Last day
-3.1%
2,766,829
Compared to previous day
Last week
-13%
12,487,971
Compared to previous week
Last month
8.1%
54,905,303
Compared to previous month
Last year
84%
548,346,350
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
OpenTelemetry API for JavaScript
API Reference
  • Â
Documentation
This package provides everything needed to interact with the OpenTelemetry API, including all TypeScript interfaces, enums, and no-op implementations. It is intended for use both on the server and in the browser.
The methods in this package perform no operations by default. This means they can be safely called by a library or end-user application whether there is an SDK registered or not. In order to generate and export telemetry data, you will also need an SDK such as the OpenTelemetry JS SDK.
Tracing Quick Start
You Will Need
- An application you wish to instrument
- OpenTelemetry JS SDK
- Node.js >=8.5.0 (14+ is preferred) or an ECMAScript 5+ compatible browser
Note: ECMAScript 5+ compatibility is for this package only. Please refer to the documentation for the SDK you are using to determine its minimum ECMAScript version.
Note for library authors: Only your end users will need an OpenTelemetry SDK. If you wish to support OpenTelemetry in your library, you only need to use the OpenTelemetry API. For more information, please read the tracing documentation.
Install Dependencies
1npm install @opentelemetry/api @opentelemetry/sdk-trace-base
Trace Your Application
In order to get started with tracing, you will need to first register an SDK. The SDK you are using may provide a convenience method which calls the registration methods for you, but if you would like to call them directly they are documented here: SDK registration methods.
Once you have registered an SDK, you can start and end spans. A simple example of basic SDK registration and tracing a simple operation is below. The example should export spans to the console once per second. For more information, see the tracing documentation.
1const { trace } = require("@opentelemetry/api"); 2const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require("@opentelemetry/sdk-trace-base"); 3 4// Create and register an SDK 5const provider = new BasicTracerProvider(); 6provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); 7trace.setGlobalTracerProvider(provider); 8 9// Acquire a tracer from the global tracer provider which will be used to trace the application 10const name = 'my-application-name'; 11const version = '0.1.0'; 12const tracer = trace.getTracer(name, version); 13 14// Trace your application by creating spans 15async function operation() { 16 const span = tracer.startSpan("do operation"); 17 18 // mock some work by sleeping 1 second 19 await new Promise((resolve, reject) => { 20 setTimeout(resolve, 1000); 21 }) 22 23 span.end(); 24} 25 26async function main() { 27 while (true) { 28 await operation(); 29 } 30} 31 32main();
Version Compatibility
Because the npm installer and node module resolution algorithm could potentially allow two or more copies of any given package to exist within the same node_modules
structure, the OpenTelemetry API takes advantage of a variable on the global
object to store the global API. When an API method in the API package is called, it checks if this global
API exists and proxies calls to it if and only if it is a compatible API version. This means if a package has a dependency on an OpenTelemetry API version which is not compatible with the API used by the end user, the package will receive a no-op implementation of the API.
Upgrade Guidelines
0.21.0 to 1.0.0
No breaking changes
0.20.0 to 0.21.0
- #78
api.context.bind
arguments reversed andcontext
is now a required argument. - #46 Noop classes and singletons are no longer exported. To create a noop span it is recommended to use
api.trace.wrapSpanContext
withINVALID_SPAN_CONTEXT
instead of using theNOOP_TRACER
.
1.0.0-rc.3 to 0.20.0
- Removing
TimedEvent
which was not part of spec HttpBaggage
renamed toHttpBaggagePropagator
- #45
Span#context
renamed toSpan#spanContext
- #47
getSpan
/setSpan
/getSpanContext
/setSpanContext
moved totrace
namespace - #55
getBaggage
/setBaggage
/createBaggage
moved topropagation
namespace
Useful links
- For more information on OpenTelemetry, visit: https://opentelemetry.io/
- For more about OpenTelemetry JavaScript: https://github.com/open-telemetry/opentelemetry-js
- For help or feedback on this project, join us in GitHub Discussions
License
Apache 2.0 - See LICENSE for more information.
No vulnerabilities found.
Reason
30 commit(s) and 18 issue activity found in the last 90 days -- score normalized to 10
Reason
all changesets reviewed
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/open-telemetry/.github/SECURITY.md:1
- Info: Found linked content: github.com/open-telemetry/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/open-telemetry/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/open-telemetry/.github/SECURITY.md:1
Reason
no binaries found in the repo
Reason
SAST tool is run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Info: all commits (30) are checked with a SAST tool
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/benchmark.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/benchmark.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/benchmark.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/benchmark.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/benchmark.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/benchmark.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/changelog.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/changelog.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/close-stale.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/close-stale.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/codeql-analysis.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/create-or-update-release-pr.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/create-or-update-release-pr.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/create-or-update-release-pr.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/create-or-update-release-pr.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/docs.yaml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/docs.yaml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/docs.yaml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/docs.yaml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/docs.yaml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/docs.yaml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/lint.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/peer-api.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/peer-api.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-to-npm.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/publish-to-npm.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-to-npm.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/publish-to-npm.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sbom.yml:68: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/sbom.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sbom.yml:72: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/sbom.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sbom.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/sbom.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sbom.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/sbom.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/sbom.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/sbom.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/unit-test.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/unit-test.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/unit-test.yml:58: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/unit-test.yml:69: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/unit-test.yml:71: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/unit-test.yml:96: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/unit-test.yml:98: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/unit-test.yml:114: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/unit-test.yml:125: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/unit-test.yml:126: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/unit-test.yml:142: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/unit-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/w3c-integration-test.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/w3c-integration-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/w3c-integration-test.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/open-telemetry/opentelemetry-js/w3c-integration-test.yml/main?enable=pin
- Warn: pipCommand not pinned by hash: integration-tests/tracecontext-integration-test.sh:13
- Warn: pipCommand not pinned by hash: integration-tests/tracecontext-integration-test.sh:14
- Warn: npmCommand not pinned by hash: .github/workflows/benchmark.yml:30
- Warn: npmCommand not pinned by hash: .github/workflows/create-or-update-release-pr.yml:49
- Warn: npmCommand not pinned by hash: .github/workflows/peer-api.yml:21
- Warn: npmCommand not pinned by hash: .github/workflows/peer-api.yml:24
- Warn: npmCommand not pinned by hash: .github/workflows/sbom.yml:22
- Warn: npmCommand not pinned by hash: .github/workflows/unit-test.yml:38
- Warn: npmCommand not pinned by hash: .github/workflows/unit-test.yml:44
- Info: 0 out of 32 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 5 third-party GitHubAction dependencies pinned
- Info: 0 out of 2 pipCommand dependencies pinned
- Info: 10 out of 17 npmCommand dependencies pinned
Reason
8 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-cg87-wmx4-v546
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/sbom.yml:65
- Warn: no topLevel permission defined: .github/workflows/benchmark.yml:1
- Warn: no topLevel permission defined: .github/workflows/changelog.yml:1
- Warn: no topLevel permission defined: .github/workflows/close-stale.yml:1
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: no topLevel permission defined: .github/workflows/create-or-update-release-pr.yml:1
- Warn: no topLevel permission defined: .github/workflows/docs.yaml:1
- Warn: no topLevel permission defined: .github/workflows/label-releases.yml:1
- Warn: no topLevel permission defined: .github/workflows/lint.yml:1
- Warn: no topLevel permission defined: .github/workflows/peer-api.yml:1
- Warn: no topLevel permission defined: .github/workflows/publish-to-npm.yml:1
- Info: topLevel permissions set to 'read-all': .github/workflows/sbom.yml:6
- Warn: no topLevel permission defined: .github/workflows/unit-test.yml:1
- Warn: no topLevel permission defined: .github/workflows/w3c-integration-test.yml:1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
Project has not signed or included provenance with any releases.
Details
- Warn: release artifact v1.30.1 not signed: https://api.github.com/repos/open-telemetry/opentelemetry-js/releases/194614577
- Warn: release artifact experimental/v0.57.1 not signed: https://api.github.com/repos/open-telemetry/opentelemetry-js/releases/194614597
- Warn: release artifact v1.30.0 not signed: https://api.github.com/repos/open-telemetry/opentelemetry-js/releases/191397365
- Warn: release artifact experimental/v0.57.0 not signed: https://api.github.com/repos/open-telemetry/opentelemetry-js/releases/191397538
- Warn: release artifact v1.29.0 not signed: https://api.github.com/repos/open-telemetry/opentelemetry-js/releases/188994126
- Warn: release artifact v1.30.1 does not have provenance: https://api.github.com/repos/open-telemetry/opentelemetry-js/releases/194614577
- Warn: release artifact experimental/v0.57.1 does not have provenance: https://api.github.com/repos/open-telemetry/opentelemetry-js/releases/194614597
- Warn: release artifact v1.30.0 does not have provenance: https://api.github.com/repos/open-telemetry/opentelemetry-js/releases/191397365
- Warn: release artifact experimental/v0.57.0 does not have provenance: https://api.github.com/repos/open-telemetry/opentelemetry-js/releases/191397538
- Warn: release artifact v1.29.0 does not have provenance: https://api.github.com/repos/open-telemetry/opentelemetry-js/releases/188994126
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
6
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @opentelemetry/api
@opentelemetry/api-logs
Public logs API for OpenTelemetry
@opentelemetry/api-metrics
Public metrics API for OpenTelemetry
@opentelemetry/instrumentation-net
OpenTelemetry instrumentation for `node:net` network API module
@opentelemetry/instrumentation-runtime-node
OpenTelemetry instrumentation for Node.js Performance measurement API