@opentelemetry/metrics
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -18,3 +18,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Aggregator_1 = require("./Aggregator"); | ||
const aggregators_1 = require("./aggregators"); | ||
const types_1 = require("./types"); | ||
@@ -45,7 +45,7 @@ /** | ||
case types_1.MetricKind.COUNTER: | ||
return new Aggregator_1.CounterSumAggregator(); | ||
return new aggregators_1.CounterSumAggregator(); | ||
case types_1.MetricKind.OBSERVER: | ||
return new Aggregator_1.ObserverAggregator(); | ||
return new aggregators_1.ObserverAggregator(); | ||
default: | ||
return new Aggregator_1.MeasureExactAggregator(); | ||
return new aggregators_1.MeasureExactAggregator(); | ||
} | ||
@@ -52,0 +52,0 @@ } |
@@ -18,3 +18,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const types_1 = require("./types"); | ||
const base_1 = require("@opentelemetry/base"); | ||
@@ -30,20 +29,21 @@ /** | ||
console.log(metric.labels); | ||
switch (metric.descriptor.metricKind) { | ||
case types_1.MetricKind.COUNTER: | ||
const sum = metric.aggregator.toPoint().value; | ||
console.log('value: ' + sum); | ||
break; | ||
default: | ||
const distribution = metric.aggregator.toPoint() | ||
.value; | ||
console.log('min: ' + | ||
distribution.min + | ||
', max: ' + | ||
distribution.max + | ||
', count: ' + | ||
distribution.count + | ||
', sum: ' + | ||
distribution.sum); | ||
break; | ||
const point = metric.aggregator.toPoint(); | ||
if (typeof point.value === 'number') { | ||
console.log('value: ' + point.value); | ||
} | ||
else if (typeof point.value.buckets === 'object') { | ||
const histogram = point.value; | ||
console.log(`count: ${histogram.count}, sum: ${histogram.sum}, buckets: ${histogram.buckets}`); | ||
} | ||
else { | ||
const distribution = point.value; | ||
console.log('min: ' + | ||
distribution.min + | ||
', max: ' + | ||
distribution.max + | ||
', count: ' + | ||
distribution.count + | ||
', sum: ' + | ||
distribution.sum); | ||
} | ||
} | ||
@@ -50,0 +50,0 @@ return resultCallback(base_1.ExportResult.SUCCESS); |
@@ -34,2 +34,28 @@ /*! | ||
} | ||
export interface Histogram { | ||
/** | ||
* Buckets are implemented using two different array: | ||
* - boundaries contains every boundary (which are upper boundary for each slice) | ||
* - counts contains count of event for each slice | ||
* | ||
* Note that we'll always have n+1 (where n is the number of boundaries) slice | ||
* because we need to count event that are above the highest boundary. This is the | ||
* reason why it's not implement using array of object, because the last slice | ||
* dont have any boundary. | ||
* | ||
* Example if we measure the values: [5, 30, 5, 40, 5, 15, 15, 15, 25] | ||
* with the boundaries [ 10, 20, 30 ], we will have the following state: | ||
* | ||
* buckets: { | ||
* boundaries: [10, 20, 30], | ||
* counts: [3, 3, 2, 1], | ||
* } | ||
*/ | ||
buckets: { | ||
boundaries: number[]; | ||
counts: number[]; | ||
}; | ||
sum: number; | ||
count: number; | ||
} | ||
export interface MetricRecord { | ||
@@ -69,4 +95,4 @@ readonly descriptor: MetricDescriptor; | ||
export interface Point { | ||
value: Sum | LastValue | Distribution; | ||
value: Sum | LastValue | Distribution | Histogram; | ||
timestamp: HrTime; | ||
} |
@@ -18,7 +18,7 @@ /*! | ||
export * from './Meter'; | ||
export * from './MeterProvider'; | ||
export * from './Metric'; | ||
export * from './MeterProvider'; | ||
export * from './export/Aggregator'; | ||
export * from './MetricObservable'; | ||
export * from './export/aggregators'; | ||
export * from './export/ConsoleMetricExporter'; | ||
export * from './export/types'; | ||
export * from './export/Aggregator'; |
@@ -23,8 +23,8 @@ "use strict"; | ||
__export(require("./Meter")); | ||
__export(require("./MeterProvider")); | ||
__export(require("./Metric")); | ||
__export(require("./MeterProvider")); | ||
__export(require("./export/Aggregator")); | ||
__export(require("./MetricObservable")); | ||
__export(require("./export/aggregators")); | ||
__export(require("./export/ConsoleMetricExporter")); | ||
__export(require("./export/types")); | ||
__export(require("./export/Aggregator")); | ||
//# sourceMappingURL=index.js.map |
@@ -16,3 +16,3 @@ /*! | ||
*/ | ||
import * as types from '@opentelemetry/api'; | ||
import * as api from '@opentelemetry/api'; | ||
import { Resource } from '@opentelemetry/resources'; | ||
@@ -24,3 +24,3 @@ import { BoundCounter, BaseBoundInstrument, BoundMeasure, BoundObserver } from './BoundInstrument'; | ||
/** This is a SDK implementation of {@link Metric} interface. */ | ||
export declare abstract class Metric<T extends BaseBoundInstrument> implements types.Metric<T> { | ||
export declare abstract class Metric<T extends BaseBoundInstrument> implements api.Metric<T> { | ||
private readonly _name; | ||
@@ -32,4 +32,4 @@ private readonly _options; | ||
protected readonly _disabled: boolean; | ||
protected readonly _valueType: types.ValueType; | ||
protected readonly _logger: types.Logger; | ||
protected readonly _valueType: api.ValueType; | ||
protected readonly _logger: api.Logger; | ||
private readonly _descriptor; | ||
@@ -45,3 +45,3 @@ private readonly _instruments; | ||
*/ | ||
bind(labels: types.Labels): T; | ||
bind(labels: api.Labels): T; | ||
/** | ||
@@ -51,3 +51,3 @@ * Removes the Instrument from the metric, if it is present. | ||
*/ | ||
unbind(labels: types.Labels): void; | ||
unbind(labels: api.Labels): void; | ||
/** | ||
@@ -59,9 +59,9 @@ * Clears all Instruments from the Metric. | ||
private _getMetricDescriptor; | ||
protected abstract _makeInstrument(labels: types.Labels): T; | ||
protected abstract _makeInstrument(labels: api.Labels): T; | ||
} | ||
/** This is a SDK implementation of Counter Metric. */ | ||
export declare class CounterMetric extends Metric<BoundCounter> implements Pick<types.MetricUtils, 'add'> { | ||
export declare class CounterMetric extends Metric<BoundCounter> implements Pick<api.MetricUtils, 'add'> { | ||
private readonly _batcher; | ||
constructor(name: string, options: MetricOptions, _batcher: Batcher, resource: Resource); | ||
protected _makeInstrument(labels: types.Labels): BoundCounter; | ||
protected _makeInstrument(labels: api.Labels): BoundCounter; | ||
/** | ||
@@ -73,17 +73,17 @@ * Adds the given value to the current value. Values cannot be negative. | ||
*/ | ||
add(value: number, labels: types.Labels): void; | ||
add(value: number, labels: api.Labels): void; | ||
} | ||
export declare class MeasureMetric extends Metric<BoundMeasure> implements Pick<types.MetricUtils, 'record'> { | ||
export declare class MeasureMetric extends Metric<BoundMeasure> implements Pick<api.MetricUtils, 'record'> { | ||
private readonly _batcher; | ||
protected readonly _absolute: boolean; | ||
constructor(name: string, options: MetricOptions, _batcher: Batcher, resource: Resource); | ||
protected _makeInstrument(labels: types.Labels): BoundMeasure; | ||
record(value: number, labels: types.Labels): void; | ||
protected _makeInstrument(labels: api.Labels): BoundMeasure; | ||
record(value: number, labels: api.Labels): void; | ||
} | ||
/** This is a SDK implementation of Observer Metric. */ | ||
export declare class ObserverMetric extends Metric<BoundObserver> implements Pick<types.MetricUtils, 'setCallback'> { | ||
export declare class ObserverMetric extends Metric<BoundObserver> implements Pick<api.MetricUtils, 'setCallback'> { | ||
private readonly _batcher; | ||
private _observerResult; | ||
constructor(name: string, options: MetricOptions, _batcher: Batcher, resource: Resource); | ||
protected _makeInstrument(labels: types.Labels): BoundObserver; | ||
protected _makeInstrument(labels: api.Labels): BoundObserver; | ||
getMetricRecord(): MetricRecord[]; | ||
@@ -94,3 +94,3 @@ /** | ||
*/ | ||
setCallback(callback: (observerResult: types.ObserverResult) => void): void; | ||
setCallback(callback: (observerResult: api.ObserverResult) => void): void; | ||
} |
@@ -131,3 +131,3 @@ "use strict"; | ||
getMetricRecord() { | ||
this._observerResult.observers.forEach((callback, labels) => { | ||
this._observerResult.callbackObservers.forEach((callback, labels) => { | ||
const instrument = this.bind(labels); | ||
@@ -144,2 +144,8 @@ instrument.update(callback()); | ||
callback(this._observerResult); | ||
this._observerResult.observers.forEach((observer, labels) => { | ||
observer.subscribe(value => { | ||
const instrument = this.bind(labels); | ||
instrument.update(value); | ||
}); | ||
}); | ||
} | ||
@@ -146,0 +152,0 @@ } |
@@ -16,3 +16,3 @@ /*! | ||
*/ | ||
import { ObserverResult as TypeObserverResult, Labels } from '@opentelemetry/api'; | ||
import { MetricObservable, ObserverResult as TypeObserverResult, Labels } from '@opentelemetry/api'; | ||
/** | ||
@@ -22,4 +22,5 @@ * Implementation of {@link TypeObserverResult} | ||
export declare class ObserverResult implements TypeObserverResult { | ||
observers: Map<Labels, Function>; | ||
observe(callback: any, labels: Labels): void; | ||
callbackObservers: Map<Labels, Function>; | ||
observers: Map<Labels, MetricObservable>; | ||
observe(callback: Function | MetricObservable, labels: Labels): void; | ||
} |
@@ -23,6 +23,12 @@ "use strict"; | ||
constructor() { | ||
this.callbackObservers = new Map(); | ||
this.observers = new Map(); | ||
} | ||
observe(callback, labels) { | ||
this.observers.set(labels, callback); | ||
if (typeof callback === 'function') { | ||
this.callbackObservers.set(labels, callback); | ||
} | ||
else { | ||
this.observers.set(labels, callback); | ||
} | ||
} | ||
@@ -29,0 +35,0 @@ } |
@@ -16,2 +16,2 @@ /*! | ||
*/ | ||
export declare const VERSION = "0.6.1"; | ||
export declare const VERSION = "0.7.0"; |
@@ -19,3 +19,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.6.1'; | ||
exports.VERSION = '0.7.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/metrics", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "OpenTelemetry metrics SDK", | ||
@@ -60,7 +60,7 @@ "main": "build/src/index.js", | ||
"dependencies": { | ||
"@opentelemetry/api": "^0.6.1", | ||
"@opentelemetry/base": "^0.6.1", | ||
"@opentelemetry/core": "^0.6.1", | ||
"@opentelemetry/resources": "^0.6.1" | ||
"@opentelemetry/api": "^0.7.0", | ||
"@opentelemetry/base": "^0.7.0", | ||
"@opentelemetry/core": "^0.7.0", | ||
"@opentelemetry/resources": "^0.7.0" | ||
} | ||
} |
@@ -28,4 +28,4 @@ # OpenTelemetry Metrics SDK | ||
const counter = meter.createCounter('metric_name', { | ||
labelKeys: ["pid"], | ||
description: "Example of a counter" | ||
labelKeys: ['pid'], | ||
description: 'Example of a counter' | ||
}); | ||
@@ -38,4 +38,39 @@ | ||
boundCounter.add(10); | ||
``` | ||
### Observable | ||
Choose this kind of metric when only last value is important without worry about aggregation | ||
```js | ||
const { MeterProvider, MetricObservable } = require('@opentelemetry/metrics'); | ||
// Initialize the Meter to capture measurements in various ways. | ||
const meter = new MeterProvider().getMeter('your-meter-name'); | ||
const observer = meter.createObserver('metric_name', { | ||
labelKeys: ['pid', 'core'], | ||
description: 'Example of a observer' | ||
}); | ||
function getCpuUsage() { | ||
return Math.random(); | ||
} | ||
const metricObservable = new MetricObservable(); | ||
observer.setCallback((observerResult) => { | ||
// synchronous callback | ||
observerResult.observe(getCpuUsage, { pid: process.pid, core: '1' }); | ||
// asynchronous callback | ||
observerResult.observe(metricObservable, { pid: process.pid, core: '2' }); | ||
}); | ||
// simulate asynchronous operation | ||
setInterval(()=> { | ||
metricObservable.next(getCpuUsage()); | ||
}, 2000) | ||
``` | ||
See [examples/prometheus](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/prometheus) for a short example. | ||
@@ -42,0 +77,0 @@ |
90343
45
1937
98
+ Added@opentelemetry/api@0.7.0(transitive)
+ Added@opentelemetry/base@0.7.0(transitive)
+ Added@opentelemetry/context-base@0.7.0(transitive)
+ Added@opentelemetry/core@0.7.0(transitive)
+ Added@opentelemetry/resources@0.7.0(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedbignumber.js@9.1.2(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedgaxios@2.3.4(transitive)
+ Addedgcp-metadata@3.5.0(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedjson-bigint@0.3.1(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removed@opentelemetry/api@0.6.1(transitive)
- Removed@opentelemetry/base@0.6.1(transitive)
- Removed@opentelemetry/context-base@0.6.1(transitive)
- Removed@opentelemetry/core@0.6.1(transitive)
- Removed@opentelemetry/resources@0.6.1(transitive)
Updated@opentelemetry/api@^0.7.0
Updated@opentelemetry/base@^0.7.0
Updated@opentelemetry/core@^0.7.0