JSPM

  • Created
  • Published
  • Downloads 217330
  • Score
    100M100P100Q23596F
  • License Apache-2.0

Work in progress OpenTelemetry metrics SDK

Package Exports

  • @opentelemetry/sdk-metrics-base
  • @opentelemetry/sdk-metrics-base/build/esm/index.js
  • @opentelemetry/sdk-metrics-base/build/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@opentelemetry/sdk-metrics-base) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

OpenTelemetry Metrics SDK

NPM Published Version Apache License

OpenTelemetry metrics allow a user to collect data and export it to a metrics backend like Prometheus.

Work In Progress

The OpenTelemetry SDK in this directory is undergoing drastic changes. If you need to use metrics, we recommend you use version 0.27.0.

Installation

npm install --save "@opentelemetry/sdk-metrics-base@~0.27.0"

Usage

Please see the version 0.27.0 README.

TODO: Add usage information for updated SDK

Installation of the Latest experimental version

npm install --save @opentelemetry/sdk-metrics-base

Usage of the Latest experimental version

The basic setup of the SDK can be seen as followings:

const opentelemetry = require('@opentelemetry/api-metrics');
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');

// To create an instrument, you first need to initialize the Meter provider.
// NOTE: The default OpenTelemetry meter provider does not record any metric instruments.
//       Registering a working meter provider allows the API methods to record instruments.
opentelemetry.setGlobalMeterProvider(new MeterProvider());

// To record a metric event, we used the global singleton meter to create an instrument.
const counter = opentelemetry.getMeter('default').createCounter('foo');

// record a metric event.
counter.add(1, { attributeKey: 'attribute-value' });

In conditions, we may need to setup an async instrument to observe costly events:

// Creating an async instrument, similar to synchronous instruments
const observableCounter = opentelemetry.getMeter('default')
  .createObservableCounter('observable-counter');

// Register a single-instrument callback to the async instrument.
observableCounter.addCallback(async (observableResult) => {
  // ... do async stuff
  observableResult.observe(1, { attributeKey: 'attribute-value' });
});

// Register a multi-instrument callback and associate it with a set of async instruments.
opentelemetry.getMeter('default')
  .addBatchObservableCallback(batchObservableCallback, [ observableCounter ]);
async function batchObservableCallback(batchObservableResult) {
  // ... do async stuff
  batchObservableResult.observe(observableCounter, 1, { attributeKey: 'attribute-value' });

  // This is been dropped since the observable is not associated with the callback at registration.
  batchObservableResult.observe(otherObservable, 2);
}

License

Apache 2.0 - See LICENSE for more information.