@opentelemetry/api
Public API for OpenTelemetry
Last updated 7 months ago by pichlermarc .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @opentelemetry/api 
SYNC missed versions from official npm registry.

OpenTelemetry API for JavaScript

API Reference   •   Documentation
NPM Release

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

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

const { trace }  = require("@opentelemetry/api");
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor }  = require("@opentelemetry/sdk-trace-base");

// Create and register an SDK
const provider = new BasicTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
trace.setGlobalTracerProvider(provider);

// Acquire a tracer from the global tracer provider which will be used to trace the application
const name = 'my-application-name';
const version = '0.1.0';
const tracer = trace.getTracer(name, version);

// Trace your application by creating spans
async function operation() {
  const span = tracer.startSpan("do operation");

  // mock some work by sleeping 1 second
  await new Promise((resolve, reject) => {
    setTimeout(resolve, 1000);
  })

  span.end();
}

async function main() {
  while (true) {
    await operation();
  }
}

main();

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 and context 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 with INVALID_SPAN_CONTEXT instead of using the NOOP_TRACER.

1.0.0-rc.3 to 0.20.0

  • Removing TimedEvent which was not part of spec
  • HttpBaggage renamed to HttpBaggagePropagator
  • #45 Span#context renamed to Span#spanContext
  • #47 getSpan/setSpan/getSpanContext/setSpanContext moved to trace namespace
  • #55 getBaggage/setBaggage/createBaggage moved to propagation namespace

Useful links

License

Apache 2.0 - See LICENSE for more information.

Current Tags

  • 0.17.1-alpha.21                                ...           canary (4 years ago)
  • 1.9.0                                ...           latest (7 months ago)
  • 1.3.0                                ...           next (2 years ago)
  • 1.0.0-rc.1                                ...           rc (4 years ago)

63 Versions

  • 1.9.0                                ...           7 months ago
  • 1.8.0                                ...           10 months ago
  • 1.7.0                                ...           a year ago
  • 1.6.0                                ...           a year ago
  • 1.5.0 [deprecated]           ...           a year ago
  • 1.4.1                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           4 years ago
  • 0.21.0                                ...           4 years ago
  • 0.20.0                                ...           4 years ago
  • 0.19.0                                ...           4 years ago
  • 1.0.0-rc.3                                ...           4 years ago
  • 1.0.0-rc.2 [deprecated]           ...           4 years ago
  • 1.0.0-rc.1 [deprecated]           ...           4 years ago
  • 1.0.0-rc.0                                ...           4 years ago
  • 0.18.1                                ...           4 years ago
  • 0.18.0                                ...           4 years ago
  • 0.17.1-alpha.21                                ...           4 years ago
  • 0.17.0                                ...           4 years ago
  • 0.16.1-alpha.20                                ...           4 years ago
  • 0.16.1-alpha.15                                ...           4 years ago
  • 0.16.1-alpha.14                                ...           4 years ago
  • 0.16.1-alpha.11                                ...           4 years ago
  • 0.16.0                                ...           4 years ago
  • 0.15.0                                ...           4 years ago
  • 0.14.0                                ...           4 years ago
  • 0.13.0                                ...           4 years ago
  • 0.12.1-alpha.7                                ...           4 years ago
  • 0.12.0                                ...           4 years ago
  • 0.12.1-alpha.54                                ...           4 years ago
  • 0.11.1-alpha.53                                ...           4 years ago
  • 0.11.1-alpha.44                                ...           4 years ago
  • 0.11.1-alpha.36                                ...           4 years ago
  • 0.11.1-alpha.35                                ...           4 years ago
  • 0.11.1-alpha.15                                ...           4 years ago
  • 0.11.0                                ...           4 years ago
  • 0.11.1-alpha.48                                ...           4 years ago
  • 0.10.3-alpha.41                                ...           4 years ago
  • 0.10.3-alpha.35                                ...           4 years ago
  • 0.10.3-alpha.34                                ...           4 years ago
  • 0.10.3-canary.0                                ...           4 years ago
  • 0.10.2                                ...           4 years ago
  • 0.10.1                                ...           4 years ago
  • 0.10.0                                ...           4 years ago
  • 0.9.0                                ...           5 years ago
  • 0.8.3                                ...           5 years ago
  • 0.8.2                                ...           5 years ago
  • 0.8.1                                ...           5 years ago
  • 0.8.0                                ...           5 years ago
  • 0.7.0                                ...           5 years ago
  • 0.6.1                                ...           5 years ago
  • 0.6.0                                ...           5 years ago
  • 0.5.2                                ...           5 years ago
  • 0.5.1                                ...           5 years ago
  • 0.5.0                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (26)
Dependents (56)

© 2010 - cnpmjs.org x YWFE | Home | YWFE