Skip to content

Commit

Permalink
chore: remove metrics SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Nov 4, 2021
1 parent 85d5110 commit dec7dba
Show file tree
Hide file tree
Showing 32 changed files with 12 additions and 3,708 deletions.
180 changes: 7 additions & 173 deletions experimental/packages/opentelemetry-sdk-metrics-base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,187 +7,21 @@

OpenTelemetry metrics allow a user to collect data and export it to a metrics backend like [Prometheus](https://prometheus.io/).

## 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.26.0`](https://github.com/open-telemetry/opentelemetry-js/tree/v0.26.0/experimental/packages/opentelemetry-sdk-metrics-base).

## Installation

```bash
npm install --save @opentelemetry/sdk-metrics-base
npm install --save "@opentelemetry/sdk-metrics-base@~0.26.0"
```

## Usage

### Counter

Choose this kind of metric when the value is a quantity, the sum is of primary interest, and the event count and value distribution are not of primary interest. It is restricted to non-negative increments.
Example uses for Counter:

- count the number of bytes received
- count the number of requests completed
- count the number of accounts created
- count the number of checkpoints run
- count the number of 5xx errors.

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

// Initialize the Meter to capture measurements in various ways.
const meter = new MeterProvider().getMeter('your-meter-name');

const counter = meter.createCounter('metric_name', {
description: 'Example of a counter'
});

const labels = { pid: process.pid };
counter.add(10, labels);
```

### UpDownCounter

`UpDownCounter` is similar to `Counter` except that it supports negative increments. It is generally useful for capturing changes in an amount of resources used, or any quantity that rises and falls during a request.

Example uses for UpDownCounter:

- count the number of active requests
- count memory in use by instrumenting new and delete
- count queue size by instrumenting enqueue and dequeue
- count semaphore up and down operations

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

// Initialize the Meter to capture measurements in various ways.
const meter = new MeterProvider().getMeter('your-meter-name');

const counter = meter.createUpDownCounter('metric_name', {
description: 'Example of a UpDownCounter'
});

const labels = { pid: process.pid };
counter.add(Math.random() > 0.5 ? 1 : -1, labels);
```

### Observable Gauge

Choose this kind of metric when only last value is important without worry about aggregation.
The callback can be sync or async.

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

const meter = new MeterProvider().getMeter('your-meter-name');


// async callback - for operation that needs to wait for value
meter.createObservableGauge('your_metric_name', {
description: 'Example of an async observable gauge with callback',
}, async (observableResult) => {
const value = await getAsyncValue();
observableResult.observe(value, { label: '1' });
});

function getAsyncValue() {
return new Promise((resolve) => {
setTimeout(()=> {
resolve(Math.random());
}, 100);
});
}

// sync callback in case you don't need to wait for value
meter.createObservableGauge('your_metric_name', {
description: 'Example of a sync observable gauge with callback',
}, (observableResult) => {
observableResult.observe(getRandomValue(), { label: '1' });
observableResult.observe(getRandomValue(), { label: '2' });
});

function getRandomValue() {
return Math.random();
}
```

### ObservableUpDownCounter

Choose this kind of metric when sum is important and you want to capture any value that starts at zero and rises or falls throughout the process lifetime.
The callback can be sync or async.

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

const meter = new MeterProvider().getMeter('your-meter-name');

// async callback - for operation that needs to wait for value
meter.createObservableUpDownCounter('your_metric_name', {
description: 'Example of an async observable up down counter with callback',
}, async (observableResult) => {
const value = await getAsyncValue();
observableResult.observe(value, { label: '1' });
});

function getAsyncValue() {
return new Promise((resolve) => {
setTimeout(()=> {
resolve(Math.random());
}, 100);
});
}

// sync callback in case you don't need to wait for value
meter.createObservableUpDownCounter('your_metric_name', {
description: 'Example of a sync observable up down counter with callback',
}, (observableResult) => {
observableResult.observe(getRandomValue(), { label: '1' });
});

function getRandomValue() {
return Math.random();
}

```

### Observable Counter

Choose this kind of metric when collecting a sum that never decreases.
The callback can be sync or async.

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

const meter = new MeterProvider().getMeter('your-meter-name');

// async callback in case you need to wait for values
meter.createObservableCounter('example_metric', {
description: 'Example of an async observable counter with callback',
}, async (observableResult) => {
const value = await getAsyncValue();
observableResult.observe(value, { label: '1' });
});

function getAsyncValue() {
return new Promise((resolve) => {
setTimeout(() => {
resolve(Math.random());
}, 100)
});
}

// sync callback in case you don't need to wait for values
meter.createObservableCounter('example_metric', {
description: 'Example of a sync observable counter with callback',
}, (observableResult) => {
const value = getRandomValue();
observableResult.observe(value, { label: '1' });
});

function getRandomValue() {
return Math.random();
}
```

### Histogram
Please see the [version `0.26.0` README](https://github.com/open-telemetry/opentelemetry-js/tree/v0.26.0/experimental/packages/opentelemetry-sdk-metrics-base#usage).

`Histogram` is a non-additive synchronous instrument useful for recording any non-additive number, positive or negative.
Values captured by `Histogram.record(value)` are treated as individual events belonging to a distribution that is being summarized.
`Histogram` should be chosen either when capturing measurements that do not contribute meaningfully to a sum, or when capturing numbers that are additive in nature, but where the distribution of individual increments is considered interesting.
TODO: Add usage information for updated SDK

## Useful links

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@opentelemetry/sdk-metrics-base",
"version": "0.26.0",
"private": true,
"description": "OpenTelemetry metrics SDK",
"main": "build/src/index.js",
"module": "build/esm/index.js",
Expand Down

This file was deleted.

Loading

0 comments on commit dec7dba

Please sign in to comment.