diff --git a/README.md b/README.md index d5e2f0d917..ae4eb6f483 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,29 @@ To request automatic tracing support for a module not on this list, please [file ## Upgrade guidelines +### 0.26.x to 0.27.x + +Metric types are renamed: + +- `@openetelemetry/api-metrics` + - `Meter` + - `createValueRecorder` => `createHistogram` + - `createValueObserver` => `createObservableGauge` + - `createSumObserver` => `createObservableCounter` + - `createUpDownSumObserver` => `createObservableUpDownCounter` + - `ValueRecorder` => `Histogram` + - `ValueObserver` => `ObservableGauge` + - `SumObserver` => `ObservableCounter` + - `UpDownSumObserver` => `ObservableUpDownCounter` + - `ObserverResult` => `ObservableResult` + - `Observation.observer` => `Observation.observable` +- `@opentelemetry/sdk-metrics-base` + - `MetricKind` + - `VALUE_RECORDER` => `HISTOGRAM` + - `SUM_OBSERVER` => `OBSERVABLE_COUNTER` + - `UP_DOWN_SUM_OBSERVER` => `OBSERVABLE_UP_DOWN_COUNTER` + - `VALUE_OBSERVER` => `OBSERVABLE_GAUGE` + ### 0.25.x to 1.x.y Collector exporter packages and types are renamed: diff --git a/doc/processor-api.md b/doc/processor-api.md index b3abbcdecc..944834b038 100644 --- a/doc/processor-api.md +++ b/doc/processor-api.md @@ -138,7 +138,7 @@ const meter = new MeterProvider({ interval: 1000, }).getMeter('example-custom-processor'); -const requestsLatency = meter.createValueRecorder('requests', { +const requestsLatency = meter.createHistogram('requests', { monotonic: true, description: 'Average latency' }); diff --git a/examples/metrics/metrics/observer.js b/examples/metrics/metrics/observer.js index def56d872b..a31345f2a5 100644 --- a/examples/metrics/metrics/observer.js +++ b/examples/metrics/metrics/observer.js @@ -21,29 +21,29 @@ const exporter = new PrometheusExporter( const meter = new MeterProvider({ exporter, interval: 2000, -}).getMeter('example-observer'); +}).getMeter('example-meter'); -meter.createValueObserver('cpu_core_usage', { - description: 'Example of a sync value observer with callback', -}, async (observerResult) => { // this callback is called once per each interval +meter.createObservableGauge('cpu_core_usage', { + description: 'Example of a sync observable gauge with callback', +}, async (observableResult) => { // this callback is called once per each interval await new Promise((resolve) => { setTimeout(()=> {resolve()}, 50); }); - observerResult.observe(getRandomValue(), { core: '1' }); - observerResult.observe(getRandomValue(), { core: '2' }); + observableResult.observe(getRandomValue(), { core: '1' }); + observableResult.observe(getRandomValue(), { core: '2' }); }); // no callback as they will be updated in batch observer -const tempMetric = meter.createValueObserver('cpu_temp_per_app', { - description: 'Example of sync value observer used with async batch observer', +const tempMetric = meter.createObservableGauge('cpu_temp_per_app', { + description: 'Example of sync observable gauge used with async batch observer', }); // no callback as they will be updated in batch observer -const cpuUsageMetric = meter.createValueObserver('cpu_usage_per_app', { - description: 'Example of sync value observer used with async batch observer', +const cpuUsageMetric = meter.createObservableGauge('cpu_usage_per_app', { + description: 'Example of sync observable gauge used with async batch observer', }); -meter.createBatchObserver((observerBatchResult) => { +meter.createBatchObserver((batchObserverResult) => { Promise.all([ someAsyncMetrics(), // simulate waiting @@ -52,11 +52,11 @@ meter.createBatchObserver((observerBatchResult) => { }), ]).then(([apps, waiting]) => { apps.forEach(app => { - observerBatchResult.observe({ app: app.name, core: '1' }, [ + batchObserverResult.observe({ app: app.name, core: '1' }, [ tempMetric.observation(app.core1.temp), cpuUsageMetric.observation(app.core1.usage), ]); - observerBatchResult.observe({ app: app.name, core: '2' }, [ + batchObserverResult.observe({ app: app.name, core: '2' }, [ tempMetric.observation(app.core2.temp), cpuUsageMetric.observation(app.core2.usage), ]); diff --git a/examples/otlp-exporter-node/metrics.js b/examples/otlp-exporter-node/metrics.js index e0065aa697..3a2294f43f 100644 --- a/examples/otlp-exporter-node/metrics.js +++ b/examples/otlp-exporter-node/metrics.js @@ -31,8 +31,8 @@ const upDownCounter = meter.createUpDownCounter('test_up_down_counter', { description: 'Example of a UpDownCounter', }); -const recorder = meter.createValueRecorder('test_value_recorder', { - description: 'Example of a ValueRecorder', +const histogram = meter.createHistogram('test_histogram', { + description: 'Example of a Histogram', }); const labels = { pid: process.pid, environment: 'staging' }; @@ -40,5 +40,5 @@ const labels = { pid: process.pid, environment: 'staging' }; setInterval(() => { requestCounter.bind(labels).add(1); upDownCounter.bind(labels).add(Math.random() > 0.5 ? 1 : -1); - recorder.bind(labels).record(Math.random()); + histogram.bind(labels).record(Math.random()); }, 1000); diff --git a/experimental/packages/opentelemetry-api-metrics/src/NoopMeter.ts b/experimental/packages/opentelemetry-api-metrics/src/NoopMeter.ts index 6e0fd5bd20..775ad78f00 100644 --- a/experimental/packages/opentelemetry-api-metrics/src/NoopMeter.ts +++ b/experimental/packages/opentelemetry-api-metrics/src/NoopMeter.ts @@ -21,18 +21,19 @@ import { UnboundMetric, Labels, Counter, - ValueRecorder, - ValueObserver, + Histogram, + ObservableGauge, UpDownCounter, - BaseObserver, - UpDownSumObserver, + ObservableBase, + ObservableCounter, + ObservableUpDownCounter, } from './types/Metric'; import { - BoundValueRecorder, + BoundHistogram, BoundCounter, - BoundBaseObserver, + BoundObservableBase, } from './types/BoundInstrument'; -import { ObserverResult } from './types/ObserverResult'; +import { ObservableResult } from './types/ObservableResult'; import { Observation } from './types/Observation'; /** @@ -43,12 +44,12 @@ export class NoopMeter implements Meter { constructor() {} /** - * Returns constant noop value recorder. + * Returns a constant noop histogram. * @param name the name of the metric. * @param [options] the metric options. */ - createValueRecorder(_name: string, _options?: MetricOptions): ValueRecorder { - return NOOP_VALUE_RECORDER_METRIC; + createHistogram(_name: string, _options?: MetricOptions): Histogram { + return NOOP_HISTOGRAM_METRIC; } /** @@ -70,45 +71,45 @@ export class NoopMeter implements Meter { } /** - * Returns constant noop value observer. + * Returns a constant noop observable gauge. * @param name the name of the metric. * @param [options] the metric options. - * @param [callback] the value observer callback + * @param [callback] the observable gauge callback */ - createValueObserver( + createObservableGauge( _name: string, _options?: MetricOptions, - _callback?: (observerResult: ObserverResult) => void - ): ValueObserver { - return NOOP_VALUE_OBSERVER_METRIC; + _callback?: (observableResult: ObservableResult) => void + ): ObservableGauge { + return NOOP_OBSERVABLE_GAUGE_METRIC; } /** - * Returns constant noop sum observer. + * Returns a constant noop observable counter. * @param name the name of the metric. * @param [options] the metric options. - * @param [callback] the sum observer callback + * @param [callback] the observable counter callback */ - createSumObserver( + createObservableCounter( _name: string, _options?: MetricOptions, - _callback?: (observerResult: ObserverResult) => void - ): ValueObserver { - return NOOP_SUM_OBSERVER_METRIC; + _callback?: (observableResult: ObservableResult) => void + ): ObservableCounter { + return NOOP_OBSERVABLE_COUNTER_METRIC; } /** - * Returns constant noop up down sum observer. + * Returns a constant noop up down observable counter. * @param name the name of the metric. * @param [options] the metric options. - * @param [callback] the up down sum observer callback + * @param [callback] the up down observable counter callback */ - createUpDownSumObserver( + createObservableUpDownCounter( _name: string, _options?: MetricOptions, - _callback?: (observerResult: ObserverResult) => void - ): UpDownSumObserver { - return NOOP_UP_DOWN_SUM_OBSERVER_METRIC; + _callback?: (observableResult: ObservableResult) => void + ): ObservableUpDownCounter { + return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC; } /** @@ -165,20 +166,20 @@ export class NoopCounterMetric } } -export class NoopValueRecorderMetric - extends NoopMetric - implements ValueRecorder { +export class NoopHistogramMetric + extends NoopMetric + implements Histogram { record(value: number, labels: Labels): void { this.bind(labels).record(value); } } -export class NoopBaseObserverMetric - extends NoopMetric - implements BaseObserver { +export class NoopObservableBaseMetric + extends NoopMetric + implements ObservableBase { observation(): Observation { return { - observer: this as BaseObserver, + observable: this as ObservableBase, value: 0, }; } @@ -192,13 +193,13 @@ export class NoopBoundCounter implements BoundCounter { } } -export class NoopBoundValueRecorder implements BoundValueRecorder { +export class NoopBoundHistogram implements BoundHistogram { record(_value: number, _baggage?: unknown, _spanContext?: unknown): void { return; } } -export class NoopBoundBaseObserver implements BoundBaseObserver { +export class NoopBoundObservableBase implements BoundObservableBase { update(_value: number): void {} } @@ -206,22 +207,22 @@ export const NOOP_METER = new NoopMeter(); export const NOOP_BOUND_COUNTER = new NoopBoundCounter(); export const NOOP_COUNTER_METRIC = new NoopCounterMetric(NOOP_BOUND_COUNTER); -export const NOOP_BOUND_VALUE_RECORDER = new NoopBoundValueRecorder(); -export const NOOP_VALUE_RECORDER_METRIC = new NoopValueRecorderMetric( - NOOP_BOUND_VALUE_RECORDER +export const NOOP_BOUND_HISTOGRAM = new NoopBoundHistogram(); +export const NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric( + NOOP_BOUND_HISTOGRAM ); -export const NOOP_BOUND_BASE_OBSERVER = new NoopBoundBaseObserver(); -export const NOOP_VALUE_OBSERVER_METRIC = new NoopBaseObserverMetric( - NOOP_BOUND_BASE_OBSERVER +export const NOOP_BOUND_OBSERVABLE_BASE = new NoopBoundObservableBase(); +export const NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableBaseMetric( + NOOP_BOUND_OBSERVABLE_BASE ); -export const NOOP_UP_DOWN_SUM_OBSERVER_METRIC = new NoopBaseObserverMetric( - NOOP_BOUND_BASE_OBSERVER +export const NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableBaseMetric( + NOOP_BOUND_OBSERVABLE_BASE ); -export const NOOP_SUM_OBSERVER_METRIC = new NoopBaseObserverMetric( - NOOP_BOUND_BASE_OBSERVER +export const NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableBaseMetric( + NOOP_BOUND_OBSERVABLE_BASE ); export const NOOP_BATCH_OBSERVER = new NoopBatchObserver(); diff --git a/experimental/packages/opentelemetry-api-metrics/src/api/global-utils.ts b/experimental/packages/opentelemetry-api-metrics/src/api/global-utils.ts index a23f76396d..e371d5165d 100644 --- a/experimental/packages/opentelemetry-api-metrics/src/api/global-utils.ts +++ b/experimental/packages/opentelemetry-api-metrics/src/api/global-utils.ts @@ -52,4 +52,4 @@ export function makeGetter( * version. If the global API is not compatible with the API package * attempting to get it, a NOOP API implementation will be returned. */ -export const API_BACKWARDS_COMPATIBILITY_VERSION = 3; +export const API_BACKWARDS_COMPATIBILITY_VERSION = 4; diff --git a/experimental/packages/opentelemetry-api-metrics/src/index.ts b/experimental/packages/opentelemetry-api-metrics/src/index.ts index de39eb0821..2a7a0dd255 100644 --- a/experimental/packages/opentelemetry-api-metrics/src/index.ts +++ b/experimental/packages/opentelemetry-api-metrics/src/index.ts @@ -22,7 +22,7 @@ export * from './types/Meter'; export * from './types/MeterProvider'; export * from './types/Metric'; export * from './types/Observation'; -export * from './types/ObserverResult'; +export * from './types/ObservableResult'; import { MetricsAPI } from './api/metrics'; /** Entrypoint for metrics API */ diff --git a/experimental/packages/opentelemetry-api-metrics/src/types/BatchObserverResult.ts b/experimental/packages/opentelemetry-api-metrics/src/types/BatchObserverResult.ts index bae99eb866..971156a774 100644 --- a/experimental/packages/opentelemetry-api-metrics/src/types/BatchObserverResult.ts +++ b/experimental/packages/opentelemetry-api-metrics/src/types/BatchObserverResult.ts @@ -18,8 +18,7 @@ import { Labels } from './Metric'; import { Observation } from './Observation'; /** - * Interface that is being used in callback function for Observer Metric - * for batch + * Interface that is being used in callback function for BatchObserver */ export interface BatchObserverResult { /** diff --git a/experimental/packages/opentelemetry-api-metrics/src/types/BoundInstrument.ts b/experimental/packages/opentelemetry-api-metrics/src/types/BoundInstrument.ts index 0d5554771e..378c934988 100644 --- a/experimental/packages/opentelemetry-api-metrics/src/types/BoundInstrument.ts +++ b/experimental/packages/opentelemetry-api-metrics/src/types/BoundInstrument.ts @@ -23,16 +23,16 @@ export interface BoundCounter { add(value: number): void; } -/** ValueRecorder to report instantaneous measurement of a value. */ -export interface BoundValueRecorder { +/** Histogram to report instantaneous measurement of a value. */ +export interface BoundHistogram { /** - * Records the given value to this value recorder. + * Records the given value to this histogram. * @param value to record. */ record(value: number): void; } -/** An Instrument for Base Observer */ -export interface BoundBaseObserver { +/** An Instrument for Base Observable */ +export interface BoundObservableBase { update(value: number): void; } diff --git a/experimental/packages/opentelemetry-api-metrics/src/types/Meter.ts b/experimental/packages/opentelemetry-api-metrics/src/types/Meter.ts index 27428f2554..a522840ec5 100644 --- a/experimental/packages/opentelemetry-api-metrics/src/types/Meter.ts +++ b/experimental/packages/opentelemetry-api-metrics/src/types/Meter.ts @@ -18,29 +18,29 @@ import { BatchObserverResult } from './BatchObserverResult'; import { MetricOptions, Counter, - ValueRecorder, - ValueObserver, + Histogram, + ObservableGauge, BatchObserverOptions, UpDownCounter, - SumObserver, - UpDownSumObserver, + ObservableCounter, + ObservableUpDownCounter, } from './Metric'; -import { ObserverResult } from './ObserverResult'; +import { ObservableResult } from './ObservableResult'; /** * An interface to allow the recording metrics. * * {@link Metric}s are used for recording pre-defined aggregation (`Counter`), - * or raw values (`ValueRecorder`) in which the aggregation and labels + * or raw values (`Histogram`) in which the aggregation and labels * for the exported metric are deferred. */ export interface Meter { /** - * Creates and returns a new `ValueRecorder`. + * Creates and returns a new `Histogram`. * @param name the name of the metric. * @param [options] the metric options. */ - createValueRecorder(name: string, options?: MetricOptions): ValueRecorder; + createHistogram(name: string, options?: MetricOptions): Histogram; /** * Creates a new `Counter` metric. Generally, this kind of metric when the @@ -71,40 +71,40 @@ export interface Meter { createUpDownCounter(name: string, options?: MetricOptions): UpDownCounter; /** - * Creates a new `ValueObserver` metric. + * Creates a new `ObservableGauge` metric. * @param name the name of the metric. * @param [options] the metric options. - * @param [callback] the observer callback + * @param [callback] the observable callback */ - createValueObserver( + createObservableGauge( name: string, options?: MetricOptions, - callback?: (observerResult: ObserverResult) => void - ): ValueObserver; + callback?: (observableResult: ObservableResult) => void + ): ObservableGauge; /** - * Creates a new `SumObserver` metric. + * Creates a new `ObservableCounter` metric. * @param name the name of the metric. * @param [options] the metric options. - * @param [callback] the observer callback + * @param [callback] the observable callback */ - createSumObserver( + createObservableCounter( name: string, options?: MetricOptions, - callback?: (observerResult: ObserverResult) => void - ): SumObserver; + callback?: (observableResult: ObservableResult) => void + ): ObservableCounter; /** - * Creates a new `UpDownSumObserver` metric. + * Creates a new `ObservableUpDownCounter` metric. * @param name the name of the metric. * @param [options] the metric options. - * @param [callback] the observer callback + * @param [callback] the observable callback */ - createUpDownSumObserver( + createObservableUpDownCounter( name: string, options?: MetricOptions, - callback?: (observerResult: ObserverResult) => void - ): UpDownSumObserver; + callback?: (observableResult: ObservableResult) => void + ): ObservableUpDownCounter; /** * Creates a new `BatchObserver`, can be used to update many metrics diff --git a/experimental/packages/opentelemetry-api-metrics/src/types/Metric.ts b/experimental/packages/opentelemetry-api-metrics/src/types/Metric.ts index aebbc46246..55b51218f8 100644 --- a/experimental/packages/opentelemetry-api-metrics/src/types/Metric.ts +++ b/experimental/packages/opentelemetry-api-metrics/src/types/Metric.ts @@ -15,10 +15,13 @@ */ import { - BoundBaseObserver, + BoundObservableBase, BoundCounter, - BoundValueRecorder, + BoundHistogram, } from './BoundInstrument'; +import { + Observation, +} from './Observation'; /** * Options needed for metric creation @@ -146,31 +149,28 @@ export interface UpDownCounter extends UnboundMetric { add(value: number, labels?: Labels): void; } -export interface ValueRecorder extends UnboundMetric { +export interface Histogram extends UnboundMetric { /** - * Records the given value to this value recorder. + * Records the given value to this histogram. */ record(value: number, labels?: Labels): void; } -/** Base interface for the Observer metrics. */ -export interface BaseObserver extends UnboundMetric { +/** Base interface for the Observable metrics. */ +export interface ObservableBase extends UnboundMetric { observation: ( value: number - ) => { - value: number; - observer: BaseObserver; - }; + ) => Observation; } -/** Base interface for the ValueObserver metrics. */ -export type ValueObserver = BaseObserver; +/** Base interface for the ObservableGauge metrics. */ +export type ObservableGauge = ObservableBase; -/** Base interface for the UpDownSumObserver metrics. */ -export type UpDownSumObserver = BaseObserver; +/** Base interface for the ObservableUpDownCounter metrics. */ +export type ObservableUpDownCounter = ObservableBase; -/** Base interface for the SumObserver metrics. */ -export type SumObserver = BaseObserver; +/** Base interface for the ObservableCounter metrics. */ +export type ObservableCounter = ObservableBase; /** * key-value pairs passed by the user. diff --git a/experimental/packages/opentelemetry-api-metrics/src/types/ObserverResult.ts b/experimental/packages/opentelemetry-api-metrics/src/types/ObservableResult.ts similarity index 86% rename from experimental/packages/opentelemetry-api-metrics/src/types/ObserverResult.ts rename to experimental/packages/opentelemetry-api-metrics/src/types/ObservableResult.ts index 7792483ad1..c909833ab9 100644 --- a/experimental/packages/opentelemetry-api-metrics/src/types/ObserverResult.ts +++ b/experimental/packages/opentelemetry-api-metrics/src/types/ObservableResult.ts @@ -17,8 +17,8 @@ import { Labels } from './Metric'; /** - * Interface that is being used in callback function for Observer Metric + * Interface that is being used in callback function for Observable Metric */ -export interface ObserverResult { +export interface ObservableResult { observe(value: number, labels: Labels): void; } diff --git a/experimental/packages/opentelemetry-api-metrics/src/types/Observation.ts b/experimental/packages/opentelemetry-api-metrics/src/types/Observation.ts index d36f48fb71..1e805f3689 100644 --- a/experimental/packages/opentelemetry-api-metrics/src/types/Observation.ts +++ b/experimental/packages/opentelemetry-api-metrics/src/types/Observation.ts @@ -14,12 +14,12 @@ * limitations under the License. */ -import { BaseObserver } from './Metric'; +import { ObservableBase } from './Metric'; /** - * Interface for updating value of certain value observer + * Interface for updating value of certain observable */ export interface Observation { - observer: BaseObserver; + observable: ObservableBase; value: number; } diff --git a/experimental/packages/opentelemetry-api-metrics/test/noop-implementations/noop-meter.test.ts b/experimental/packages/opentelemetry-api-metrics/test/noop-implementations/noop-meter.test.ts index cbfe044a9f..07b2e7b402 100644 --- a/experimental/packages/opentelemetry-api-metrics/test/noop-implementations/noop-meter.test.ts +++ b/experimental/packages/opentelemetry-api-metrics/test/noop-implementations/noop-meter.test.ts @@ -18,9 +18,9 @@ import * as assert from 'assert'; import { NoopMeterProvider, NOOP_BOUND_COUNTER, - NOOP_BOUND_VALUE_RECORDER, + NOOP_BOUND_HISTOGRAM, NOOP_COUNTER_METRIC, - NOOP_VALUE_RECORDER_METRIC, + NOOP_HISTOGRAM_METRIC, } from '../../src'; describe('NoopMeter', () => { @@ -38,23 +38,23 @@ describe('NoopMeter', () => { assert.strictEqual(counter.bind(labels), NOOP_BOUND_COUNTER); counter.clear(); - const valueRecorder = meter.createValueRecorder('some-name'); - valueRecorder.bind(labels).record(1); + const histogram = meter.createHistogram('some-name'); + histogram.bind(labels).record(1); // ensure the correct noop const is returned - assert.strictEqual(valueRecorder, NOOP_VALUE_RECORDER_METRIC); - assert.strictEqual(valueRecorder.bind(labels), NOOP_BOUND_VALUE_RECORDER); + assert.strictEqual(histogram, NOOP_HISTOGRAM_METRIC); + assert.strictEqual(histogram.bind(labels), NOOP_BOUND_HISTOGRAM); const options = { component: 'tests', description: 'the testing package', }; - const valueRecorderWithOptions = meter.createValueRecorder( + const histogramWithOptions = meter.createHistogram( 'some-name', options ); - assert.strictEqual(valueRecorderWithOptions, NOOP_VALUE_RECORDER_METRIC); + assert.strictEqual(histogramWithOptions, NOOP_HISTOGRAM_METRIC); const counterWithOptions = meter.createCounter('some-name', options); assert.strictEqual(counterWithOptions, NOOP_COUNTER_METRIC); }); diff --git a/experimental/packages/opentelemetry-exporter-otlp-grpc/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-otlp-grpc/test/OTLPMetricExporter.test.ts index 86b8e1cef3..83d8723d4f 100644 --- a/experimental/packages/opentelemetry-exporter-otlp-grpc/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-otlp-grpc/test/OTLPMetricExporter.test.ts @@ -17,8 +17,8 @@ import * as protoLoader from '@grpc/proto-loader'; import { Counter, - ValueObserver, - ValueRecorder, + ObservableGauge, + Histogram, } from '@opentelemetry/api-metrics'; import { diag } from '@opentelemetry/api'; import { otlpTypes } from '@opentelemetry/exporter-otlp-http'; @@ -31,13 +31,13 @@ import * as sinon from 'sinon'; import { OTLPMetricExporter } from '../src'; import { ensureExportedCounterIsCorrect, - ensureExportedObserverIsCorrect, - ensureExportedValueRecorderIsCorrect, + ensureExportedObservableGaugeIsCorrect, + ensureExportedHistogramIsCorrect, ensureMetadataIsCorrect, ensureResourceIsCorrect, mockCounter, - mockObserver, - mockValueRecorder, + mockObservableGauge, + mockHistogram, } from './helper'; const metricsServiceProtoPath = @@ -140,21 +140,21 @@ const testOTLPMetricExporter = (params: TestParams) => metrics = []; const counter: metrics.Metric & Counter = mockCounter(); - const observer: metrics.Metric & - ValueObserver = mockObserver(observerResult => { - observerResult.observe(3, {}); - observerResult.observe(6, {}); + const observableGauge: metrics.Metric & + ObservableGauge = mockObservableGauge(observableResult => { + observableResult.observe(3, {}); + observableResult.observe(6, {}); }); - const recorder: metrics.Metric & - ValueRecorder = mockValueRecorder(); + const histogram: metrics.Metric & + Histogram = mockHistogram(); counter.add(1); - recorder.record(7); - recorder.record(14); + histogram.record(7); + histogram.record(14); metrics.push((await counter.getMetricRecord())[0]); - metrics.push((await observer.getMetricRecord())[0]); - metrics.push((await recorder.getMetricRecord())[0]); + metrics.push((await observableGauge.getMetricRecord())[0]); + metrics.push((await histogram.getMetricRecord())[0]); }); afterEach(() => { @@ -203,21 +203,21 @@ const testOTLPMetricExporter = (params: TestParams) => resource = exportedData[0].resource; const counter = exportedData[0].instrumentationLibraryMetrics[0].metrics[0]; - const observer = + const observableGauge = exportedData[0].instrumentationLibraryMetrics[0].metrics[1]; - const recorder = + const histogram = exportedData[0].instrumentationLibraryMetrics[0].metrics[2]; ensureExportedCounterIsCorrect( counter, counter.intSum?.dataPoints[0].timeUnixNano ); - ensureExportedObserverIsCorrect( - observer, - observer.doubleGauge?.dataPoints[0].timeUnixNano + ensureExportedObservableGaugeIsCorrect( + observableGauge, + observableGauge.doubleGauge?.dataPoints[0].timeUnixNano ); - ensureExportedValueRecorderIsCorrect( - recorder, - recorder.intHistogram?.dataPoints[0].timeUnixNano, + ensureExportedHistogramIsCorrect( + histogram, + histogram.intHistogram?.dataPoints[0].timeUnixNano, [0, 100], ['0', '2', '0'] ); diff --git a/experimental/packages/opentelemetry-exporter-otlp-grpc/test/helper.ts b/experimental/packages/opentelemetry-exporter-otlp-grpc/test/helper.ts index e77f0f1742..48325a12d4 100644 --- a/experimental/packages/opentelemetry-exporter-otlp-grpc/test/helper.ts +++ b/experimental/packages/opentelemetry-exporter-otlp-grpc/test/helper.ts @@ -17,9 +17,9 @@ import { SpanStatusCode, TraceFlags } from '@opentelemetry/api'; import { Counter, - ObserverResult, - ValueObserver, - ValueRecorder, + ObservableResult, + ObservableGauge, + Histogram, ValueType, } from '@opentelemetry/api-metrics'; import { otlpTypes } from '@opentelemetry/exporter-otlp-http'; @@ -75,16 +75,16 @@ export function mockCounter(): metrics.Metric & Counter { return metric; } -export function mockObserver( - callback: (observerResult: ObserverResult) => void -): metrics.Metric & ValueObserver { - const name = 'double-observer'; +export function mockObservableGauge( + callback: (observableResult: ObservableResult) => void +): metrics.Metric & ObservableGauge { + const name = 'double-observable-gauge'; const metric = meter['_metrics'].get(name) || - meter.createValueObserver( + meter.createObservableGauge( name, { - description: 'sample observer description', + description: 'sample observable gauge description', valueType: ValueType.DOUBLE, }, callback @@ -94,13 +94,13 @@ export function mockObserver( return metric; } -export function mockValueRecorder(): metrics.Metric & - ValueRecorder { - const name = 'int-recorder'; +export function mockHistogram(): metrics.Metric & + Histogram { + const name = 'int-histogram'; const metric = meter['_metrics'].get(name) || - meter.createValueRecorder(name, { - description: 'sample recorder description', + meter.createHistogram(name, { + description: 'sample histogram description', valueType: ValueType.INT, boundaries: [0, 100], }); @@ -352,13 +352,13 @@ export function ensureExportedCounterIsCorrect( }); } -export function ensureExportedObserverIsCorrect( +export function ensureExportedObservableGaugeIsCorrect( metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, time?: number ) { assert.deepStrictEqual(metric, { - name: 'double-observer', - description: 'sample observer description', + name: 'double-observable-gauge', + description: 'sample observable gauge description', unit: '1', data: 'doubleGauge', doubleGauge: { @@ -375,15 +375,15 @@ export function ensureExportedObserverIsCorrect( }); } -export function ensureExportedValueRecorderIsCorrect( +export function ensureExportedHistogramIsCorrect( metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, time?: number, explicitBounds: number[] = [Infinity], bucketCounts: string[] = ['2', '0'] ) { assert.deepStrictEqual(metric, { - name: 'int-recorder', - description: 'sample recorder description', + name: 'int-histogram', + description: 'sample histogram description', unit: '1', data: 'intHistogram', intHistogram: { diff --git a/experimental/packages/opentelemetry-exporter-otlp-http/src/transformMetrics.ts b/experimental/packages/opentelemetry-exporter-otlp-http/src/transformMetrics.ts index cc0f580883..97a0e1ec3e 100644 --- a/experimental/packages/opentelemetry-exporter-otlp-http/src/transformMetrics.ts +++ b/experimental/packages/opentelemetry-exporter-otlp-http/src/transformMetrics.ts @@ -47,7 +47,7 @@ export function toCollectorLabels( export function toAggregationTemporality( metric: MetricRecord ): opentelemetryProto.metrics.v1.AggregationTemporality { - if (metric.descriptor.metricKind === MetricKind.VALUE_OBSERVER) { + if (metric.descriptor.metricKind === MetricKind.OBSERVABLE_GAUGE) { return opentelemetryProto.metrics.v1.AggregationTemporality .AGGREGATION_TEMPORALITY_UNSPECIFIED; } @@ -115,14 +115,14 @@ export function toCollectorMetric( if ( metric.aggregator.kind === AggregatorKind.SUM || - metric.descriptor.metricKind === MetricKind.SUM_OBSERVER || - metric.descriptor.metricKind === MetricKind.UP_DOWN_SUM_OBSERVER + metric.descriptor.metricKind === MetricKind.OBSERVABLE_COUNTER || + metric.descriptor.metricKind === MetricKind.OBSERVABLE_UP_DOWN_COUNTER ) { const result = { dataPoints: [toDataPoint(metric, startTime)], isMonotonic: metric.descriptor.metricKind === MetricKind.COUNTER || - metric.descriptor.metricKind === MetricKind.SUM_OBSERVER, + metric.descriptor.metricKind === MetricKind.OBSERVABLE_COUNTER, aggregationTemporality: toAggregationTemporality(metric), }; if (metric.descriptor.valueType === ValueType.INT) { diff --git a/experimental/packages/opentelemetry-exporter-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-otlp-http/test/browser/CollectorMetricExporter.test.ts index 34463695c8..a2d289a7fe 100644 --- a/experimental/packages/opentelemetry-exporter-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -17,14 +17,14 @@ import { diag } from '@opentelemetry/api'; import { Counter, - ValueObserver, - ValueRecorder, + ObservableGauge, + Histogram, } from '@opentelemetry/api-metrics'; import { ExportResultCode, hrTimeToNanoseconds } from '@opentelemetry/core'; import { BoundCounter, - BoundObserver, - BoundValueRecorder, + BoundObservable, + BoundHistogram, Metric, MetricRecord, } from '@opentelemetry/sdk-metrics-base'; @@ -37,12 +37,12 @@ import { ensureCounterIsCorrect, ensureExportMetricsServiceRequestIsSet, ensureHeadersContain, - ensureObserverIsCorrect, - ensureValueRecorderIsCorrect, + ensureObservableGaugeIsCorrect, + ensureHistogramIsCorrect, ensureWebResourceIsCorrect, mockCounter, - mockObserver, - mockValueRecorder, + mockObservableGauge, + mockHistogram, } from '../helper'; describe('OTLPMetricExporter - web', () => { @@ -57,22 +57,22 @@ describe('OTLPMetricExporter - web', () => { stubBeacon = sinon.stub(navigator, 'sendBeacon'); metrics = []; const counter: Metric & Counter = mockCounter(); - const observer: Metric & ValueObserver = mockObserver( - observerResult => { - observerResult.observe(3, {}); - observerResult.observe(6, {}); + const observableGauge: Metric & ObservableGauge = mockObservableGauge( + observableResult => { + observableResult.observe(3, {}); + observableResult.observe(6, {}); }, - 'double-observer2' + 'double-observable-gauge2' ); - const recorder: Metric & - ValueRecorder = mockValueRecorder(); + const histogram: Metric & + Histogram = mockHistogram(); counter.add(1); - recorder.record(7); - recorder.record(14); + histogram.record(7); + histogram.record(14); metrics.push((await counter.getMetricRecord())[0]); - metrics.push((await observer.getMetricRecord())[0]); - metrics.push((await recorder.getMetricRecord())[0]); + metrics.push((await observableGauge.getMetricRecord())[0]); + metrics.push((await histogram.getMetricRecord())[0]); }); afterEach(() => { @@ -121,11 +121,11 @@ describe('OTLPMetricExporter - web', () => { "second metric doesn't exist" ); if (metric2) { - ensureObserverIsCorrect( + ensureObservableGaugeIsCorrect( metric2, hrTimeToNanoseconds(metrics[1].aggregator.toPoint().timestamp), 6, - 'double-observer2' + 'double-observable-gauge2' ); } @@ -134,7 +134,7 @@ describe('OTLPMetricExporter - web', () => { "third metric doesn't exist" ); if (metric3) { - ensureValueRecorderIsCorrect( + ensureHistogramIsCorrect( metric3, hrTimeToNanoseconds(metrics[2].aggregator.toPoint().timestamp), [0, 100], @@ -234,11 +234,11 @@ describe('OTLPMetricExporter - web', () => { "second metric doesn't exist" ); if (metric2) { - ensureObserverIsCorrect( + ensureObservableGaugeIsCorrect( metric2, hrTimeToNanoseconds(metrics[1].aggregator.toPoint().timestamp), 6, - 'double-observer2' + 'double-observable-gauge2' ); } @@ -247,7 +247,7 @@ describe('OTLPMetricExporter - web', () => { "third metric doesn't exist" ); if (metric3) { - ensureValueRecorderIsCorrect( + ensureHistogramIsCorrect( metric3, hrTimeToNanoseconds(metrics[2].aggregator.toPoint().timestamp), [0, 100], diff --git a/experimental/packages/opentelemetry-exporter-otlp-http/test/common/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-otlp-http/test/common/CollectorMetricExporter.test.ts index 119702c683..7282f538c0 100644 --- a/experimental/packages/opentelemetry-exporter-otlp-http/test/common/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-otlp-http/test/common/CollectorMetricExporter.test.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import { Counter, ValueObserver } from '@opentelemetry/api-metrics'; +import { Counter, ObservableGauge } from '@opentelemetry/api-metrics'; import { ExportResultCode } from '@opentelemetry/core'; import { BoundCounter, - BoundObserver, + BoundObservable, Metric, MetricRecord, } from '@opentelemetry/sdk-metrics-base'; @@ -27,7 +27,7 @@ import * as sinon from 'sinon'; import { OTLPExporterBase } from '../../src/OTLPExporterBase'; import * as otlpTypes from '../../src/types'; import { OTLPExporterConfigBase } from '../../src/types'; -import { mockCounter, mockObserver } from '../helper'; +import { mockCounter, mockObservableGauge } from '../helper'; type CollectorExporterConfig = OTLPExporterConfigBase; class OTLPMetricExporter extends OTLPExporterBase< @@ -70,17 +70,17 @@ describe('OTLPMetricExporter - common', () => { collectorExporter = new OTLPMetricExporter(collectorExporterConfig); metrics = []; const counter: Metric & Counter = mockCounter(); - const observer: Metric & ValueObserver = mockObserver( - observerResult => { - observerResult.observe(3, {}); - observerResult.observe(6, {}); + const observableGauge: Metric & ObservableGauge = mockObservableGauge( + observableResult => { + observableResult.observe(3, {}); + observableResult.observe(6, {}); }, - 'double-observer3' + 'double-observable-gauge3' ); counter.add(1); metrics.push((await counter.getMetricRecord())[0]); - metrics.push((await observer.getMetricRecord())[0]); + metrics.push((await observableGauge.getMetricRecord())[0]); }); it('should create an instance', () => { diff --git a/experimental/packages/opentelemetry-exporter-otlp-http/test/common/transformMetrics.test.ts b/experimental/packages/opentelemetry-exporter-otlp-http/test/common/transformMetrics.test.ts index e94a6cf71d..71ce5ab274 100644 --- a/experimental/packages/opentelemetry-exporter-otlp-http/test/common/transformMetrics.test.ts +++ b/experimental/packages/opentelemetry-exporter-otlp-http/test/common/transformMetrics.test.ts @@ -15,16 +15,16 @@ */ import { Counter, - SumObserver, - UpDownSumObserver, - ValueObserver, - ValueRecorder, + ObservableCounter, + ObservableUpDownCounter, + ObservableGauge, + Histogram, } from '@opentelemetry/api-metrics'; import { hrTimeToNanoseconds } from '@opentelemetry/core'; import { BoundCounter, - BoundObserver, - BoundValueRecorder, + BoundObservable, + BoundHistogram, Metric, SumAggregator, } from '@opentelemetry/sdk-metrics-base'; @@ -34,18 +34,18 @@ import * as transform from '../../src/transformMetrics'; import { ensureCounterIsCorrect, ensureDoubleCounterIsCorrect, - ensureObserverIsCorrect, - ensureSumObserverIsCorrect, - ensureUpDownSumObserverIsCorrect, - ensureValueRecorderIsCorrect, + ensureObservableGaugeIsCorrect, + ensureObservableCounterIsCorrect, + ensureObservableUpDownCounterIsCorrect, + ensureHistogramIsCorrect, mockCounter, mockDoubleCounter, mockedInstrumentationLibraries, mockedResources, - mockObserver, - mockSumObserver, - mockUpDownSumObserver, - mockValueRecorder, + mockObservableGauge, + mockObservableCounter, + mockObservableUpDownCounter, + mockHistogram, multiInstrumentationLibraryMetricsGet, multiResourceMetricsGet, } from '../helper'; @@ -54,10 +54,10 @@ describe('transformMetrics', () => { describe('toCollectorMetric', async () => { let counter: Metric & Counter; let doubleCounter: Metric & Counter; - let observer: Metric & ValueObserver; - let sumObserver: Metric & SumObserver; - let upDownSumObserver: Metric & UpDownSumObserver; - let recorder: Metric & ValueRecorder; + let observableGauge: Metric & ObservableGauge; + let observableCounter: Metric & ObservableCounter; + let observableUpDownCounter: Metric & ObservableUpDownCounter; + let histogram: Metric & Histogram; beforeEach(() => { counter = mockCounter(); doubleCounter = mockDoubleCounter(); @@ -72,22 +72,22 @@ describe('transformMetrics', () => { return -1; } - observer = mockObserver(observerResult => { + observableGauge = mockObservableGauge(observableResult => { count1++; - observerResult.observe(getValue(count1), {}); + observableResult.observe(getValue(count1), {}); }); - sumObserver = mockSumObserver(observerResult => { + observableCounter = mockObservableCounter(observableResult => { count2++; - observerResult.observe(getValue(count2), {}); + observableResult.observe(getValue(count2), {}); }); - upDownSumObserver = mockUpDownSumObserver(observerResult => { + observableUpDownCounter = mockObservableUpDownCounter(observableResult => { count3++; - observerResult.observe(getValue(count3), {}); + observableResult.observe(getValue(count3), {}); }); - recorder = mockValueRecorder(); + histogram = mockHistogram(); // Counter counter.add(1); @@ -95,9 +95,9 @@ describe('transformMetrics', () => { // Double Counter doubleCounter.add(8); - // ValueRecorder - recorder.record(7); - recorder.record(14); + // Histogram + histogram.record(7); + histogram.record(14); }); it('should convert metric', async () => { @@ -113,46 +113,46 @@ describe('transformMetrics', () => { hrTimeToNanoseconds(doubleCounterMetric.aggregator.toPoint().timestamp) ); - await observer.getMetricRecord(); - await observer.getMetricRecord(); - const observerMetric = (await observer.getMetricRecord())[0]; - ensureObserverIsCorrect( - transform.toCollectorMetric(observerMetric, 1592602232694000000), - hrTimeToNanoseconds(observerMetric.aggregator.toPoint().timestamp), + await observableGauge.getMetricRecord(); + await observableGauge.getMetricRecord(); + const observableGaugeMetric = (await observableGauge.getMetricRecord())[0]; + ensureObservableGaugeIsCorrect( + transform.toCollectorMetric(observableGaugeMetric, 1592602232694000000), + hrTimeToNanoseconds(observableGaugeMetric.aggregator.toPoint().timestamp), -1 ); // collect 3 times - await sumObserver.getMetricRecord(); - await sumObserver.getMetricRecord(); - const sumObserverMetric = (await sumObserver.getMetricRecord())[0]; - ensureSumObserverIsCorrect( - transform.toCollectorMetric(sumObserverMetric, 1592602232694000000), - hrTimeToNanoseconds(sumObserverMetric.aggregator.toPoint().timestamp), + await observableCounter.getMetricRecord(); + await observableCounter.getMetricRecord(); + const observableCounterMetric = (await observableCounter.getMetricRecord())[0]; + ensureObservableCounterIsCorrect( + transform.toCollectorMetric(observableCounterMetric, 1592602232694000000), + hrTimeToNanoseconds(observableCounterMetric.aggregator.toPoint().timestamp), 3 ); // collect 3 times - await upDownSumObserver.getMetricRecord(); - await upDownSumObserver.getMetricRecord(); - const upDownSumObserverMetric = ( - await upDownSumObserver.getMetricRecord() + await observableUpDownCounter.getMetricRecord(); + await observableUpDownCounter.getMetricRecord(); + const observableUpDownCounterMetric = ( + await observableUpDownCounter.getMetricRecord() )[0]; - ensureUpDownSumObserverIsCorrect( + ensureObservableUpDownCounterIsCorrect( transform.toCollectorMetric( - upDownSumObserverMetric, + observableUpDownCounterMetric, 1592602232694000000 ), hrTimeToNanoseconds( - upDownSumObserverMetric.aggregator.toPoint().timestamp + observableUpDownCounterMetric.aggregator.toPoint().timestamp ), -1 ); - const recorderMetric = (await recorder.getMetricRecord())[0]; - ensureValueRecorderIsCorrect( - transform.toCollectorMetric(recorderMetric, 1592602232694000000), - hrTimeToNanoseconds(recorderMetric.aggregator.toPoint().timestamp), + const histogramMetric = (await histogram.getMetricRecord())[0]; + ensureHistogramIsCorrect( + transform.toCollectorMetric(histogramMetric, 1592602232694000000), + hrTimeToNanoseconds(histogramMetric.aggregator.toPoint().timestamp), [0, 100], [0, 2, 0] ); @@ -186,8 +186,8 @@ describe('transformMetrics', () => { const [resource1, resource2] = mockedResources; const [library] = mockedInstrumentationLibraries; const [metric1, metric2, metric3] = multiResourceMetricsGet( - observerResult => { - observerResult.observe(1, {}); + observableResult => { + observableResult.observe(1, {}); } ); @@ -197,8 +197,8 @@ describe('transformMetrics', () => { ]); const result = transform.groupMetricsByResourceAndLibrary( - multiResourceMetricsGet(observerResult => { - observerResult.observe(1, {}); + multiResourceMetricsGet(observableResult => { + observableResult.observe(1, {}); }) ); @@ -212,7 +212,7 @@ describe('transformMetrics', () => { metric1, metric2, metric3, - ] = multiInstrumentationLibraryMetricsGet(observerResult => {}); + ] = multiInstrumentationLibraryMetricsGet(observableResult => {}); const expected = new Map([ [ resource, @@ -224,7 +224,7 @@ describe('transformMetrics', () => { ]); const result = transform.groupMetricsByResourceAndLibrary( - multiInstrumentationLibraryMetricsGet(observerResult => {}) + multiInstrumentationLibraryMetricsGet(observableResult => {}) ); assert.deepStrictEqual(result, expected); diff --git a/experimental/packages/opentelemetry-exporter-otlp-http/test/helper.ts b/experimental/packages/opentelemetry-exporter-otlp-http/test/helper.ts index 8783906034..5befa3515f 100644 --- a/experimental/packages/opentelemetry-exporter-otlp-http/test/helper.ts +++ b/experimental/packages/opentelemetry-exporter-otlp-http/test/helper.ts @@ -17,11 +17,11 @@ import { SpanStatusCode, TraceFlags } from '@opentelemetry/api'; import { Counter, - ObserverResult, - SumObserver, - UpDownSumObserver, - ValueObserver, - ValueRecorder, + ObservableResult, + ObservableCounter, + ObservableUpDownCounter, + ObservableGauge, + Histogram, ValueType, } from '@opentelemetry/api-metrics'; import { hexToBase64, InstrumentationLibrary, VERSION } from '@opentelemetry/core'; @@ -78,16 +78,16 @@ export function mockDoubleCounter(): metrics.Metric & return metric; } -export function mockObserver( - callback: (observerResult: ObserverResult) => unknown, - name = 'double-observer' -): metrics.Metric & ValueObserver { +export function mockObservableGauge( + callback: (observableResult: ObservableResult) => unknown, + name = 'double-observable-gauge' +): metrics.Metric & ObservableGauge { const metric = meter['_metrics'].get(name) || - meter.createValueObserver( + meter.createObservableGauge( name, { - description: 'sample observer description', + description: 'sample observable gauge description', valueType: ValueType.DOUBLE, }, callback @@ -97,16 +97,16 @@ export function mockObserver( return metric; } -export function mockSumObserver( - callback: (observerResult: ObserverResult) => unknown, - name = 'double-sum-observer' -): metrics.Metric & SumObserver { +export function mockObservableCounter( + callback: (observableResult: ObservableResult) => unknown, + name = 'double-observable-counter' +): metrics.Metric & ObservableCounter { const metric = meter['_metrics'].get(name) || - meter.createSumObserver( + meter.createObservableCounter( name, { - description: 'sample sum observer description', + description: 'sample observable counter description', valueType: ValueType.DOUBLE, }, callback @@ -116,16 +116,16 @@ export function mockSumObserver( return metric; } -export function mockUpDownSumObserver( - callback: (observerResult: ObserverResult) => unknown, - name = 'double-up-down-sum-observer' -): metrics.Metric & UpDownSumObserver { +export function mockObservableUpDownCounter( + callback: (observableResult: ObservableResult) => unknown, + name = 'double-up-down-observable-counter' +): metrics.Metric & ObservableUpDownCounter { const metric = meter['_metrics'].get(name) || - meter.createUpDownSumObserver( + meter.createObservableUpDownCounter( name, { - description: 'sample up down sum observer description', + description: 'sample observable up down counter description', valueType: ValueType.DOUBLE, }, callback @@ -135,13 +135,13 @@ export function mockUpDownSumObserver( return metric; } -export function mockValueRecorder(): metrics.Metric & - ValueRecorder { - const name = 'int-recorder'; +export function mockHistogram(): metrics.Metric & + Histogram { + const name = 'int-histogram'; const metric = meter['_metrics'].get(name) || - meter.createValueRecorder(name, { - description: 'sample recorder description', + meter.createHistogram(name, { + description: 'sample histogram description', valueType: ValueType.INT, boundaries: [0, 100], }); @@ -313,7 +313,7 @@ export const multiResourceTrace: ReadableSpan[] = [ ]; export const multiResourceMetricsGet = function ( - callback: (observerResult: ObserverResult) => unknown + callback: (observableResult: ObservableResult) => unknown ): any[] { return [ { @@ -322,7 +322,7 @@ export const multiResourceMetricsGet = function ( instrumentationLibrary: mockedInstrumentationLibraries[0], }, { - ...mockObserver(callback), + ...mockObservableGauge(callback), resource: mockedResources[1], instrumentationLibrary: mockedInstrumentationLibraries[0], }, @@ -335,7 +335,7 @@ export const multiResourceMetricsGet = function ( }; export const multiInstrumentationLibraryMetricsGet = function ( - callback: (observerResult: ObserverResult) => unknown + callback: (observableResult: ObservableResult) => unknown ): any[] { return [ { @@ -344,7 +344,7 @@ export const multiInstrumentationLibraryMetricsGet = function ( instrumentationLibrary: mockedInstrumentationLibraries[0], }, { - ...mockObserver(callback), + ...mockObservableGauge(callback), resource: mockedResources[0], instrumentationLibrary: mockedInstrumentationLibraries[1], }, @@ -601,15 +601,15 @@ export function ensureDoubleCounterIsCorrect( }); } -export function ensureObserverIsCorrect( +export function ensureObservableGaugeIsCorrect( metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, time: number, value: number, - name = 'double-observer' + name = 'double-observable-gauge' ) { assert.deepStrictEqual(metric, { name, - description: 'sample observer description', + description: 'sample observable gauge description', unit: '1', doubleGauge: { dataPoints: [ @@ -624,15 +624,15 @@ export function ensureObserverIsCorrect( }); } -export function ensureSumObserverIsCorrect( +export function ensureObservableCounterIsCorrect( metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, time: number, value: number, - name = 'double-sum-observer' + name = 'double-observable-counter' ) { assert.deepStrictEqual(metric, { name, - description: 'sample sum observer description', + description: 'sample observable counter description', unit: '1', doubleSum: { isMonotonic: true, @@ -651,15 +651,15 @@ export function ensureSumObserverIsCorrect( }); } -export function ensureUpDownSumObserverIsCorrect( +export function ensureObservableUpDownCounterIsCorrect( metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, time: number, value: number, - name = 'double-up-down-sum-observer' + name = 'double-up-down-observable-counter' ) { assert.deepStrictEqual(metric, { name, - description: 'sample up down sum observer description', + description: 'sample observable up down counter description', unit: '1', doubleSum: { isMonotonic: false, @@ -678,15 +678,15 @@ export function ensureUpDownSumObserverIsCorrect( }); } -export function ensureValueRecorderIsCorrect( +export function ensureHistogramIsCorrect( metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, time: number, explicitBounds: (number | null)[] = [Infinity], bucketCounts: number[] = [2, 0] ) { assert.deepStrictEqual(metric, { - name: 'int-recorder', - description: 'sample recorder description', + name: 'int-histogram', + description: 'sample histogram description', unit: '1', intHistogram: { dataPoints: [ diff --git a/experimental/packages/opentelemetry-exporter-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-otlp-http/test/node/CollectorMetricExporter.test.ts index 4937ef3737..11308aeef2 100644 --- a/experimental/packages/opentelemetry-exporter-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -17,14 +17,14 @@ import { diag } from '@opentelemetry/api'; import { Counter, - ValueObserver, - ValueRecorder, + ObservableGauge, + Histogram, } from '@opentelemetry/api-metrics'; import * as core from '@opentelemetry/core'; import { BoundCounter, - BoundObserver, - BoundValueRecorder, + BoundObservable, + BoundHistogram, Metric, MetricRecord, } from '@opentelemetry/sdk-metrics-base'; @@ -39,11 +39,11 @@ import * as otlpTypes from '../../src/types'; import { ensureCounterIsCorrect, ensureExportMetricsServiceRequestIsSet, - ensureObserverIsCorrect, - ensureValueRecorderIsCorrect, + ensureObservableGaugeIsCorrect, + ensureHistogramIsCorrect, mockCounter, - mockObserver, - mockValueRecorder, + mockObservableGauge, + mockHistogram, } from '../helper'; import { MockedResponse } from './nodeHelpers'; @@ -149,21 +149,21 @@ describe('OTLPMetricExporter - node with json over http', () => { }); metrics = []; const counter: Metric & Counter = mockCounter(); - const observer: Metric & ValueObserver = mockObserver( - observerResult => { - observerResult.observe(6, {}); + const observableGauge: Metric & ObservableGauge = mockObservableGauge( + observableResult => { + observableResult.observe(6, {}); }, - 'double-observer2' + 'double-observable-gauge2' ); - const recorder: Metric & - ValueRecorder = mockValueRecorder(); + const histogram: Metric & + Histogram = mockHistogram(); counter.add(1); - recorder.record(7); - recorder.record(14); + histogram.record(7); + histogram.record(14); metrics.push((await counter.getMetricRecord())[0]); - metrics.push((await observer.getMetricRecord())[0]); - metrics.push((await recorder.getMetricRecord())[0]); + metrics.push((await observableGauge.getMetricRecord())[0]); + metrics.push((await histogram.getMetricRecord())[0]); }); it('should open the connection', done => { @@ -224,15 +224,15 @@ describe('OTLPMetricExporter - node with json over http', () => { metric1, core.hrTimeToNanoseconds(metrics[0].aggregator.toPoint().timestamp) ); - assert.ok(typeof metric2 !== 'undefined', "observer doesn't exist"); - ensureObserverIsCorrect( + assert.ok(typeof metric2 !== 'undefined', "observable gauge doesn't exist"); + ensureObservableGaugeIsCorrect( metric2, core.hrTimeToNanoseconds(metrics[1].aggregator.toPoint().timestamp), 6, - 'double-observer2' + 'double-observable-gauge2' ); assert.ok(typeof metric3 !== 'undefined', "histogram doesn't exist"); - ensureValueRecorderIsCorrect( + ensureHistogramIsCorrect( metric3, core.hrTimeToNanoseconds(metrics[2].aggregator.toPoint().timestamp), [0, 100], diff --git a/experimental/packages/opentelemetry-exporter-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-otlp-proto/test/OTLPMetricExporter.test.ts index 17716f0887..b623d2d819 100644 --- a/experimental/packages/opentelemetry-exporter-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-otlp-proto/test/OTLPMetricExporter.test.ts @@ -17,8 +17,8 @@ import { diag } from '@opentelemetry/api'; import { Counter, - ValueObserver, - ValueRecorder, + ObservableGauge, + Histogram, } from '@opentelemetry/api-metrics'; import { ExportResultCode } from '@opentelemetry/core'; import { @@ -33,13 +33,13 @@ import { OTLPMetricExporter } from '../src'; import { getExportRequestProto } from '../src/util'; import { ensureExportedCounterIsCorrect, - ensureExportedObserverIsCorrect, - ensureExportedValueRecorderIsCorrect, + ensureExportedObservableGaugeIsCorrect, + ensureExportedHistogramIsCorrect, ensureExportMetricsServiceRequestIsSet, mockCounter, MockedResponse, - mockObserver, - mockValueRecorder, + mockObservableGauge, + mockHistogram, } from './helper'; const fakeRequest = { @@ -121,21 +121,21 @@ describe('OTLPMetricExporter - node with proto over http', () => { metrics = []; const counter: metrics.Metric & Counter = mockCounter(); - const observer: metrics.Metric & - ValueObserver = mockObserver(observerResult => { - observerResult.observe(3, {}); - observerResult.observe(6, {}); + const observableGauge: metrics.Metric & + ObservableGauge = mockObservableGauge(observableResult => { + observableResult.observe(3, {}); + observableResult.observe(6, {}); }); - const recorder: metrics.Metric & - ValueRecorder = mockValueRecorder(); + const histogram: metrics.Metric & + Histogram = mockHistogram(); counter.add(1); - recorder.record(7); - recorder.record(14); + histogram.record(7); + histogram.record(14); metrics.push((await counter.getMetricRecord())[0]); - metrics.push((await observer.getMetricRecord())[0]); - metrics.push((await recorder.getMetricRecord())[0]); + metrics.push((await observableGauge.getMetricRecord())[0]); + metrics.push((await histogram.getMetricRecord())[0]); }); afterEach(() => { sinon.restore(); @@ -197,8 +197,8 @@ describe('OTLPMetricExporter - node with proto over http', () => { metric1, metric1.intSum?.dataPoints[0].timeUnixNano ); - assert.ok(typeof metric2 !== 'undefined', "observer doesn't exist"); - ensureExportedObserverIsCorrect( + assert.ok(typeof metric2 !== 'undefined', "observable gauge doesn't exist"); + ensureExportedObservableGaugeIsCorrect( metric2, metric2.doubleGauge?.dataPoints[0].timeUnixNano ); @@ -206,7 +206,7 @@ describe('OTLPMetricExporter - node with proto over http', () => { typeof metric3 !== 'undefined', "value recorder doesn't exist" ); - ensureExportedValueRecorderIsCorrect( + ensureExportedHistogramIsCorrect( metric3, metric3.intHistogram?.dataPoints[0].timeUnixNano, [0, 100], diff --git a/experimental/packages/opentelemetry-exporter-otlp-proto/test/helper.ts b/experimental/packages/opentelemetry-exporter-otlp-proto/test/helper.ts index f8b90b9fef..f76b8619b0 100644 --- a/experimental/packages/opentelemetry-exporter-otlp-proto/test/helper.ts +++ b/experimental/packages/opentelemetry-exporter-otlp-proto/test/helper.ts @@ -17,9 +17,9 @@ import { SpanStatusCode, TraceFlags } from '@opentelemetry/api'; import { Counter, - ObserverResult, - ValueObserver, - ValueRecorder, + ObservableResult, + ObservableGauge, + Histogram, ValueType, } from '@opentelemetry/api-metrics'; import { hexToBase64 } from '@opentelemetry/core'; @@ -54,16 +54,16 @@ export function mockCounter(): metrics.Metric & Counter { return metric; } -export function mockObserver( - callback: (observerResult: ObserverResult) => void -): metrics.Metric & ValueObserver { - const name = 'double-observer'; +export function mockObservableGauge( + callback: (observableResult: ObservableResult) => void +): metrics.Metric & ObservableGauge { + const name = 'double-observable-gauge'; const metric = meter['_metrics'].get(name) || - meter.createValueObserver( + meter.createObservableGauge( name, { - description: 'sample observer description', + description: 'sample observable gauge description', valueType: ValueType.DOUBLE, }, callback @@ -73,13 +73,13 @@ export function mockObserver( return metric; } -export function mockValueRecorder(): metrics.Metric & - ValueRecorder { - const name = 'int-recorder'; +export function mockHistogram(): metrics.Metric & + Histogram { + const name = 'int-histogram'; const metric = meter['_metrics'].get(name) || - meter.createValueRecorder(name, { - description: 'sample recorder description', + meter.createHistogram(name, { + description: 'sample histogram description', valueType: ValueType.INT, boundaries: [0, 100], }); @@ -316,13 +316,13 @@ export function ensureExportedCounterIsCorrect( }); } -export function ensureExportedObserverIsCorrect( +export function ensureExportedObservableGaugeIsCorrect( metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, time?: number ) { assert.deepStrictEqual(metric, { - name: 'double-observer', - description: 'sample observer description', + name: 'double-observable-gauge', + description: 'sample observable gauge description', unit: '1', doubleGauge: { dataPoints: [ @@ -336,15 +336,15 @@ export function ensureExportedObserverIsCorrect( }); } -export function ensureExportedValueRecorderIsCorrect( +export function ensureExportedHistogramIsCorrect( metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, time?: number, explicitBounds: number[] = [Infinity], bucketCounts: string[] = ['2', '0'] ) { assert.deepStrictEqual(metric, { - name: 'int-recorder', - description: 'sample recorder description', + name: 'int-histogram', + description: 'sample histogram description', unit: '1', intHistogram: { dataPoints: [ diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts index e62ba0478a..35473b14a3 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts @@ -106,11 +106,11 @@ function toPrometheusType( case AggregatorKind.SUM: if ( metricKind === MetricKind.COUNTER || - metricKind === MetricKind.SUM_OBSERVER + metricKind === MetricKind.OBSERVABLE_COUNTER ) { return 'counter'; } - /** MetricKind.UP_DOWN_COUNTER and MetricKind.UP_DOWN_SUM_OBSERVER */ + /** MetricKind.UP_DOWN_COUNTER and MetricKind.OBSERVABLE_UP_DOWN_COUNTER */ return 'gauge'; case AggregatorKind.LAST_VALUE: return 'gauge'; diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts index 11d0090861..3b5f044be3 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ObserverResult } from '@opentelemetry/api-metrics'; +import { ObservableResult } from '@opentelemetry/api-metrics'; import { CounterMetric, SumAggregator, @@ -270,18 +270,18 @@ describe('PrometheusExporter', () => { }); }); - it('should export an observer aggregation', done => { + it('should export an observable gauge aggregation', done => { function getCpuUsage() { return 0.999; } - meter.createValueObserver( - 'metric_observer', + meter.createObservableGauge( + 'metric_observable_gauge', { description: 'a test description', }, - (observerResult: ObserverResult) => { - observerResult.observe(getCpuUsage(), { + (observableResult: ObservableResult) => { + observableResult.observe(getCpuUsage(), { pid: String(123), core: '1', }); @@ -298,9 +298,9 @@ describe('PrometheusExporter', () => { const lines = body.split('\n'); assert.deepStrictEqual(lines, [ - '# HELP metric_observer a test description', - '# TYPE metric_observer gauge', - `metric_observer{pid="123",core="1"} 0.999 ${mockedHrTimeMs}`, + '# HELP metric_observable_gauge a test description', + '# TYPE metric_observable_gauge gauge', + `metric_observable_gauge{pid="123",core="1"} 0.999 ${mockedHrTimeMs}`, '', ]); done(); @@ -472,18 +472,18 @@ describe('PrometheusExporter', () => { }); }); - it('should export a SumObserver as a counter', done => { + it('should export an ObservableCounter as a counter', done => { function getValue() { return 20; } - meter.createSumObserver( - 'sum_observer', + meter.createObservableCounter( + 'metric_observable_counter', { description: 'a test description', }, - (observerResult: ObserverResult) => { - observerResult.observe(getValue(), { + (observableResult: ObservableResult) => { + observableResult.observe(getValue(), { key1: 'labelValue1', }); } @@ -498,9 +498,9 @@ describe('PrometheusExporter', () => { const lines = body.split('\n'); assert.deepStrictEqual(lines, [ - '# HELP sum_observer a test description', - '# TYPE sum_observer gauge', - `sum_observer{key1="labelValue1"} 20 ${mockedHrTimeMs}`, + '# HELP metric_observable_counter a test description', + '# TYPE metric_observable_counter gauge', + `metric_observable_counter{key1="labelValue1"} 20 ${mockedHrTimeMs}`, '', ]); }); @@ -512,18 +512,18 @@ describe('PrometheusExporter', () => { }); }); - it('should export a UpDownSumObserver as a gauge', done => { + it('should export an ObservableUpDownCounter as a gauge', done => { function getValue() { return 20; } - meter.createUpDownSumObserver( - 'updown_observer', + meter.createObservableUpDownCounter( + 'metric_observable_up_down_counter', { description: 'a test description', }, - (observerResult: ObserverResult) => { - observerResult.observe(getValue(), { + (observableResult: ObservableResult) => { + observableResult.observe(getValue(), { key1: 'labelValue1', }); } @@ -538,9 +538,9 @@ describe('PrometheusExporter', () => { const lines = body.split('\n'); assert.deepStrictEqual(lines, [ - '# HELP updown_observer a test description', - '# TYPE updown_observer gauge', - `updown_observer{key1="labelValue1"} 20 ${mockedHrTimeMs}`, + '# HELP metric_observable_up_down_counter a test description', + '# TYPE metric_observable_up_down_counter gauge', + `metric_observable_up_down_counter{key1="labelValue1"} 20 ${mockedHrTimeMs}`, '', ]); }); @@ -552,12 +552,12 @@ describe('PrometheusExporter', () => { }); }); - it('should export a ValueRecorder as a summary', done => { - const valueRecorder = meter.createValueRecorder('value_recorder', { + it('should export a Histogram as a summary', done => { + const histogram = meter.createHistogram('test_histogram', { description: 'a test description', }); - valueRecorder.bind({ key1: 'labelValue1' }).record(20); + histogram.bind({ key1: 'labelValue1' }).record(20); meter.collect().then(() => { exporter.export(meter.getProcessor().checkPointSet(), () => { @@ -568,11 +568,11 @@ describe('PrometheusExporter', () => { const lines = body.split('\n'); assert.deepStrictEqual(lines, [ - '# HELP value_recorder a test description', - '# TYPE value_recorder histogram', - `value_recorder_count{key1="labelValue1"} 1 ${mockedHrTimeMs}`, - `value_recorder_sum{key1="labelValue1"} 20 ${mockedHrTimeMs}`, - `value_recorder_bucket{key1="labelValue1",le="+Inf"} 1 ${mockedHrTimeMs}`, + '# HELP test_histogram a test description', + '# TYPE test_histogram histogram', + `test_histogram_count{key1="labelValue1"} 1 ${mockedHrTimeMs}`, + `test_histogram_sum{key1="labelValue1"} 20 ${mockedHrTimeMs}`, + `test_histogram_bucket{key1="labelValue1",le="+Inf"} 1 ${mockedHrTimeMs}`, '', ]); diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts index 4934ebb788..7c3582f07b 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts @@ -19,9 +19,9 @@ import { LastValueAggregator, MeterProvider, CounterMetric, - ValueRecorderMetric, + HistogramMetric, UpDownCounterMetric, - ValueObserverMetric, + ObservableGaugeMetric, } from '@opentelemetry/sdk-metrics-base'; import { diag, DiagLogLevel } from '@opentelemetry/api'; import * as assert from 'assert'; @@ -99,15 +99,15 @@ describe('PrometheusSerializer', () => { const meter = new MeterProvider({ processor: new ExactProcessor(LastValueAggregator), }).getMeter('test'); - const observer = meter.createValueObserver( + const observableGauge = meter.createObservableGauge( 'test', {}, - observerResult => { - observerResult.observe(1, labels); + observableResult => { + observableResult.observe(1, labels); } - ) as ValueObserverMetric; + ) as ObservableGaugeMetric; await meter.collect(); - const records = await observer.getMetricRecord(); + const records = await observableGauge.getMetricRecord(); const record = records[0]; const result = serializer.serializeRecord( @@ -126,15 +126,15 @@ describe('PrometheusSerializer', () => { const meter = new MeterProvider({ processor: new ExactProcessor(LastValueAggregator), }).getMeter('test'); - const observer = meter.createValueObserver( + const observableGauge = meter.createObservableGauge( 'test', {}, - observerResult => { - observerResult.observe(1, labels); + observableResult => { + observableResult.observe(1, labels); } - ) as ValueObserverMetric; + ) as ObservableGaugeMetric; await meter.collect(); - const records = await observer.getMetricRecord(); + const records = await observableGauge.getMetricRecord(); const record = records[0]; const result = serializer.serializeRecord( @@ -153,13 +153,13 @@ describe('PrometheusSerializer', () => { const processor = new ExactProcessor(HistogramAggregator, [1, 10, 100]); const meter = new MeterProvider({ processor }).getMeter('test'); - const recorder = meter.createValueRecorder('test', { + const histogram = meter.createHistogram('test', { description: 'foobar', - }) as ValueRecorderMetric; + }) as HistogramMetric; - recorder.bind(labels).record(5); + histogram.bind(labels).record(5); - const records = await recorder.getMetricRecord(); + const records = await histogram.getMetricRecord(); const record = records[0]; const result = serializer.serializeRecord( @@ -181,13 +181,13 @@ describe('PrometheusSerializer', () => { const serializer = new PrometheusSerializer(); const meter = new MeterProvider().getMeter('test'); - const recorder = meter.createValueRecorder('test', { + const histogram = meter.createHistogram('test', { description: 'foobar', boundaries: [1, 10, 100], - }) as ValueRecorderMetric; - recorder.bind(labels).record(5); + }) as HistogramMetric; + histogram.bind(labels).record(5); - const records = await recorder.getMetricRecord(); + const records = await histogram.getMetricRecord(); const record = records[0]; const result = serializer.serializeRecord( @@ -210,12 +210,12 @@ describe('PrometheusSerializer', () => { const processor = new ExactProcessor(HistogramAggregator, [1, 10, 100]); const meter = new MeterProvider({ processor }).getMeter('test'); - const recorder = meter.createValueRecorder('test', { + const histogram = meter.createHistogram('test', { description: 'foobar', - }) as ValueRecorderMetric; - recorder.bind(labels).record(5); + }) as HistogramMetric; + histogram.bind(labels).record(5); - const records = await recorder.getMetricRecord(); + const records = await histogram.getMetricRecord(); const record = records[0]; const result = serializer.serializeRecord( @@ -304,17 +304,17 @@ describe('PrometheusSerializer', () => { processor: new ExactProcessor(LastValueAggregator), }).getMeter('test'); const processor = new PrometheusLabelsBatcher(); - const observer = meter.createValueObserver( + const observableGauge = meter.createObservableGauge( 'test', { description: 'foobar', }, - observerResult => { - observerResult.observe(1, labels); + observableResult => { + observableResult.observe(1, labels); } - ) as ValueObserverMetric; + ) as ObservableGaugeMetric; await meter.collect(); - const records = await observer.getMetricRecord(); + const records = await observableGauge.getMetricRecord(); records.forEach(it => processor.process(it)); const checkPointSet = processor.checkPointSet(); @@ -336,16 +336,16 @@ describe('PrometheusSerializer', () => { const processor = new ExactProcessor(HistogramAggregator, [1, 10, 100]); const meter = new MeterProvider({ processor }).getMeter('test'); - const recorder = meter.createValueRecorder('test', { + const histogram = meter.createHistogram('test', { description: 'foobar', - }) as ValueRecorderMetric; - recorder.bind({ val: '1' }).record(5); - recorder.bind({ val: '1' }).record(50); - recorder.bind({ val: '1' }).record(120); + }) as HistogramMetric; + histogram.bind({ val: '1' }).record(5); + histogram.bind({ val: '1' }).record(50); + histogram.bind({ val: '1' }).record(120); - recorder.bind({ val: '2' }).record(5); + histogram.bind({ val: '2' }).record(5); - const records = await recorder.getMetricRecord(); + const records = await histogram.getMetricRecord(); const labelBatcher = new PrometheusLabelsBatcher(); records.forEach(it => labelBatcher.process(it)); const checkPointSet = labelBatcher.checkPointSet(); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/README.md b/experimental/packages/opentelemetry-sdk-metrics-base/README.md index 1761164b0f..b760ecc336 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/README.md +++ b/experimental/packages/opentelemetry-sdk-metrics-base/README.md @@ -73,7 +73,7 @@ boundCounter.add(Math.random() > 0.5 ? 1 : -1); ``` -### Value Observer +### Observable Gauge Choose this kind of metric when only last value is important without worry about aggregation. The callback can be sync or async. @@ -85,11 +85,11 @@ const meter = new MeterProvider().getMeter('your-meter-name'); // async callback - for operation that needs to wait for value -meter.createValueObserver('your_metric_name', { - description: 'Example of an async observer with callback', -}, async (observerResult) => { +meter.createObservableGauge('your_metric_name', { + description: 'Example of an async observable gauge with callback', +}, async (observableResult) => { const value = await getAsyncValue(); - observerResult.observe(value, { label: '1' }); + observableResult.observe(value, { label: '1' }); }); function getAsyncValue() { @@ -101,11 +101,11 @@ function getAsyncValue() { } // sync callback in case you don't need to wait for value -meter.createValueObserver('your_metric_name', { - description: 'Example of a sync observer with callback', -}, (observerResult) => { - observerResult.observe(getRandomValue(), { label: '1' }); - observerResult.observe(getRandomValue(), { label: '2' }); +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() { @@ -113,7 +113,7 @@ function getRandomValue() { } ``` -### UpDownSumObserver +### 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. @@ -124,11 +124,11 @@ 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.createUpDownSumObserver('your_metric_name', { - description: 'Example of an async observer with callback', -}, async (observerResult) => { +meter.createObservableUpDownCounter('your_metric_name', { + description: 'Example of an async observable up down counter with callback', +}, async (observableResult) => { const value = await getAsyncValue(); - observerResult.observe(value, { label: '1' }); + observableResult.observe(value, { label: '1' }); }); function getAsyncValue() { @@ -140,10 +140,10 @@ function getAsyncValue() { } // sync callback in case you don't need to wait for value -meter.createUpDownSumObserver('your_metric_name', { - description: 'Example of a sync observer with callback', -}, (observerResult) => { - observerResult.observe(getRandomValue(), { label: '1' }); +meter.createObservableUpDownCounter('your_metric_name', { + description: 'Example of a sync observable up down counter with callback', +}, (observableResult) => { + observableResult.observe(getRandomValue(), { label: '1' }); }); function getRandomValue() { @@ -152,7 +152,7 @@ function getRandomValue() { ``` -### Sum Observer +### Observable Counter Choose this kind of metric when collecting a sum that never decreases. The callback can be sync or async. @@ -163,11 +163,11 @@ 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.createSumObserver('example_metric', { - description: 'Example of an async sum observer with callback', -}, async (observerResult) => { +meter.createObservableCounter('example_metric', { + description: 'Example of an async observable counter with callback', +}, async (observableResult) => { const value = await getAsyncValue(); - observerResult.observe(value, { label: '1' }); + observableResult.observe(value, { label: '1' }); }); function getAsyncValue() { @@ -179,11 +179,11 @@ function getAsyncValue() { } // sync callback in case you don't need to wait for values -meter.createSumObserver('example_metric', { - description: 'Example of a sync sum observer with callback', -}, (observerResult) => { +meter.createObservableCounter('example_metric', { + description: 'Example of a sync observable counter with callback', +}, (observableResult) => { const value = getRandomValue(); - observerResult.observe(value, { label: '1' }); + observableResult.observe(value, { label: '1' }); }); function getRandomValue() { @@ -193,7 +193,7 @@ function getRandomValue() { ### Batch Observer -Choose this kind of metric when you need to update multiple observers with the results of a single async calculation. +Choose this kind of metric when you need to update multiple observables with the results of a single async calculation. ```js const { MeterProvider } = require('@opentelemetry/sdk-metrics-base'); @@ -213,17 +213,17 @@ const meter = new MeterProvider({ interval: 3000, }).getMeter('example-observer'); -const cpuUsageMetric = meter.createValueObserver('cpu_usage_per_app', { +const cpuUsageMetric = meter.createObservableGauge('cpu_usage_per_app', { description: 'CPU', }); -const MemUsageMetric = meter.createValueObserver('mem_usage_per_app', { +const MemUsageMetric = meter.createObservableGauge('mem_usage_per_app', { description: 'Memory', }); -meter.createBatchObserver((observerBatchResult) => { +meter.createBatchObserver((batchObserverResult) => { getSomeAsyncMetrics().then(metrics => { - observerBatchResult.observe({ app: 'myApp' }, [ + batchObserverResult.observe({ app: 'myApp' }, [ cpuUsageMetric.observation(metrics.value1), MemUsageMetric.observation(metrics.value2) ]); @@ -245,11 +245,11 @@ function getSomeAsyncMetrics() { See [examples/prometheus](https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/prometheus) for a short example. -### Value Recorder +### Histogram -`ValueRecorder` is a non-additive synchronous instrument useful for recording any non-additive number, positive or negative. -Values captured by `ValueRecorder.record(value)` are treated as individual events belonging to a distribution that is being summarized. -`ValueRecorder` 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. +`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. ## Useful links diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/BatchObserver.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/BatchObserver.ts index 90c5384465..576102cb46 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/BatchObserver.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/BatchObserver.ts @@ -23,12 +23,12 @@ const MAX_TIMEOUT_UPDATE_MS = 500; /** This is a SDK implementation of Batch Observer. */ export class BatchObserver { - private _callback: (observerResult: api.BatchObserverResult) => void; + private _callback: (observableResult: api.BatchObserverResult) => void; private _maxTimeoutUpdateMS: number; constructor( options: api.BatchObserverOptions, - callback?: (observerResult: api.BatchObserverResult) => void + callback?: (observableResult: api.BatchObserverResult) => void ) { this._maxTimeoutUpdateMS = options.maxTimeoutUpdateMS ?? MAX_TIMEOUT_UPDATE_MS; @@ -38,27 +38,27 @@ export class BatchObserver { collect(): Promise { diag.debug('getMetricRecord - start'); return new Promise(resolve => { - const observerResult = new BatchObserverResult(); + const batchObserverResult = new BatchObserverResult(); // cancels after MAX_TIMEOUT_MS - no more waiting for results const timer = setTimeout(() => { - observerResult.cancelled = true; + batchObserverResult.cancelled = true; // remove callback to prevent user from updating the values later if - // for any reason the observerBatchResult will be referenced - observerResult.onObserveCalled(); + // for any reason the batchObserverResult will be referenced + batchObserverResult.onObserveCalled(); resolve(); diag.debug('getMetricRecord - timeout'); }, this._maxTimeoutUpdateMS); // sets callback for each "observe" method - observerResult.onObserveCalled(() => { + batchObserverResult.onObserveCalled(() => { clearTimeout(timer); resolve(); diag.debug('getMetricRecord - end'); }); // calls the BatchObserverResult callback - this._callback(observerResult); + this._callback(batchObserverResult); }); } } diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/BatchObserverResult.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/BatchObserverResult.ts index 4e2c0c8b28..f882774ad0 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/BatchObserverResult.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/BatchObserverResult.ts @@ -44,14 +44,14 @@ export class BatchObserverResult implements api.BatchObserverResult { return; } observations.forEach(observation => { - observation.observer.bind(labels).update(observation.value); + observation.observable.bind(labels).update(observation.value); }); if (!this._immediate) { this._immediate = setImmediate(() => { if (typeof this._callback === 'function') { this._callback(); // prevent user from updating the values later if for any reason - // the observerBatchResult will be referenced and then try to use + // the batchObserverResult will be referenced and then try to use this._callback = undefined; } }); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/BoundInstrument.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/BoundInstrument.ts index 296bf72909..67a66b204c 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/BoundInstrument.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/BoundInstrument.ts @@ -117,9 +117,9 @@ export class BoundUpDownCounter /** * BoundMeasure is an implementation of the {@link BoundMeasure} interface. */ -export class BoundValueRecorder +export class BoundHistogram extends BaseBoundInstrument - implements api.BoundValueRecorder { + implements api.BoundHistogram { constructor( labels: api.Labels, disabled: boolean, @@ -135,11 +135,11 @@ export class BoundValueRecorder } /** - * BoundObserver is an implementation of the {@link BoundObserver} interface. + * BoundObservable is an implementation of the {@link BoundObservable} interface. */ -export class BoundObserver +export class BoundObservable extends BaseBoundInstrument - implements api.BoundBaseObserver { + implements api.BoundObservableBase { constructor( labels: api.Labels, disabled: boolean, diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/ValueRecorderMetric.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/HistogramMetric.ts similarity index 79% rename from experimental/packages/opentelemetry-sdk-metrics-base/src/ValueRecorderMetric.ts rename to experimental/packages/opentelemetry-sdk-metrics-base/src/HistogramMetric.ts index 28e9d7e1b2..20a7ade3a7 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/ValueRecorderMetric.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/HistogramMetric.ts @@ -17,15 +17,15 @@ import * as api from '@opentelemetry/api-metrics'; import { InstrumentationLibrary } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import { BoundValueRecorder } from './BoundInstrument'; +import { BoundHistogram } from './BoundInstrument'; import { Processor } from './export/Processor'; import { MetricKind } from './export/types'; import { Metric } from './Metric'; -/** This is a SDK implementation of Value Recorder Metric. */ -export class ValueRecorderMetric - extends Metric - implements api.ValueRecorder { +/** This is a SDK implementation of Histogram Metric. */ +export class HistogramMetric + extends Metric + implements api.Histogram { constructor( name: string, options: api.MetricOptions, @@ -36,14 +36,14 @@ export class ValueRecorderMetric super( name, options, - MetricKind.VALUE_RECORDER, + MetricKind.HISTOGRAM, resource, instrumentationLibrary ); } - protected _makeInstrument(labels: api.Labels): BoundValueRecorder { - return new BoundValueRecorder( + protected _makeInstrument(labels: api.Labels): BoundHistogram { + return new BoundHistogram( labels, this._disabled, this._valueType, diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts index 9a77e865bb..143d50692a 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts @@ -25,12 +25,12 @@ import { PushController } from './export/Controller'; import { NoopExporter } from './export/NoopExporter'; import { Processor, UngroupedProcessor } from './export/Processor'; import { Metric } from './Metric'; -import { SumObserverMetric } from './SumObserverMetric'; +import { ObservableCounterMetric } from './ObservableCounterMetric'; import { DEFAULT_CONFIG, DEFAULT_METRIC_OPTIONS, MeterConfig } from './types'; import { UpDownCounterMetric } from './UpDownCounterMetric'; -import { UpDownSumObserverMetric } from './UpDownSumObserverMetric'; -import { ValueObserverMetric } from './ValueObserverMetric'; -import { ValueRecorderMetric } from './ValueRecorderMetric'; +import { ObservableUpDownCounterMetric } from './ObservableUpDownCounterMetric'; +import { ObservableGaugeMetric } from './ObservableGaugeMetric'; +import { HistogramMetric } from './HistogramMetric'; // eslint-disable-next-line @typescript-eslint/no-var-requires const merge = require('lodash.merge'); // @TODO - replace once the core is released @@ -68,34 +68,34 @@ export class Meter implements api.Meter { } /** - * Creates and returns a new {@link ValueRecorder}. + * Creates and returns a new {@link Histogram}. * @param name the name of the metric. * @param [options] the metric options. */ - createValueRecorder( + createHistogram( name: string, options?: api.MetricOptions - ): api.ValueRecorder { + ): api.Histogram { if (!this._isValidName(name)) { diag.warn( `Invalid metric name ${name}. Defaulting to noop metric implementation.` ); - return api.NOOP_VALUE_RECORDER_METRIC; + return api.NOOP_HISTOGRAM_METRIC; } const opt: api.MetricOptions = { ...DEFAULT_METRIC_OPTIONS, ...options, }; - const valueRecorder = new ValueRecorderMetric( + const histogram = new HistogramMetric( name, opt, this._processor, this._resource, this._instrumentationLibrary ); - this._registerMetric(name, valueRecorder); - return valueRecorder; + this._registerMetric(name, histogram); + return histogram; } /** @@ -163,27 +163,27 @@ export class Meter implements api.Meter { } /** - * Creates a new `ValueObserver` metric. + * Creates a new `ObservableGauge` metric. * @param name the name of the metric. * @param [options] the metric options. - * @param [callback] the value observer callback + * @param [callback] the observable gauge callback */ - createValueObserver( + createObservableGauge( name: string, options: api.MetricOptions = {}, - callback?: (observerResult: api.ObserverResult) => unknown - ): api.ValueObserver { + callback?: (observableResult: api.ObservableResult) => unknown + ): api.ObservableGauge { if (!this._isValidName(name)) { diag.warn( `Invalid metric name ${name}. Defaulting to noop metric implementation.` ); - return api.NOOP_VALUE_OBSERVER_METRIC; + return api.NOOP_OBSERVABLE_GAUGE_METRIC; } const opt: api.MetricOptions = { ...DEFAULT_METRIC_OPTIONS, ...options, }; - const valueObserver = new ValueObserverMetric( + const observableGauge = new ObservableGaugeMetric( name, opt, this._processor, @@ -191,26 +191,26 @@ export class Meter implements api.Meter { this._instrumentationLibrary, callback ); - this._registerMetric(name, valueObserver); - return valueObserver; + this._registerMetric(name, observableGauge); + return observableGauge; } - createSumObserver( + createObservableCounter( name: string, options: api.MetricOptions = {}, - callback?: (observerResult: api.ObserverResult) => unknown - ): api.SumObserver { + callback?: (observableResult: api.ObservableResult) => unknown + ): api.ObservableCounter { if (!this._isValidName(name)) { diag.warn( `Invalid metric name ${name}. Defaulting to noop metric implementation.` ); - return api.NOOP_SUM_OBSERVER_METRIC; + return api.NOOP_OBSERVABLE_COUNTER_METRIC; } const opt: api.MetricOptions = { ...DEFAULT_METRIC_OPTIONS, ...options, }; - const sumObserver = new SumObserverMetric( + const observableCounter = new ObservableCounterMetric( name, opt, this._processor, @@ -218,32 +218,32 @@ export class Meter implements api.Meter { this._instrumentationLibrary, callback ); - this._registerMetric(name, sumObserver); - return sumObserver; + this._registerMetric(name, observableCounter); + return observableCounter; } /** - * Creates a new `UpDownSumObserver` metric. + * Creates a new `ObservableUpDownCounter` metric. * @param name the name of the metric. * @param [options] the metric options. - * @param [callback] the value observer callback + * @param [callback] the observable gauge callback */ - createUpDownSumObserver( + createObservableUpDownCounter( name: string, options: api.MetricOptions = {}, - callback?: (observerResult: api.ObserverResult) => unknown - ): api.UpDownSumObserver { + callback?: (observableResult: api.ObservableResult) => unknown + ): api.ObservableUpDownCounter { if (!this._isValidName(name)) { diag.warn( `Invalid metric name ${name}. Defaulting to noop metric implementation.` ); - return api.NOOP_UP_DOWN_SUM_OBSERVER_METRIC; + return api.NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC; } const opt: api.MetricOptions = { ...DEFAULT_METRIC_OPTIONS, ...options, }; - const upDownSumObserver = new UpDownSumObserverMetric( + const observableUpDownCounter = new ObservableUpDownCounterMetric( name, opt, this._processor, @@ -251,8 +251,8 @@ export class Meter implements api.Meter { this._instrumentationLibrary, callback ); - this._registerMetric(name, upDownSumObserver); - return upDownSumObserver; + this._registerMetric(name, observableUpDownCounter); + return observableUpDownCounter; } /** @@ -261,7 +261,7 @@ export class Meter implements api.Meter { * @param [options] the batch options. */ createBatchObserver( - callback: (observerResult: api.BatchObserverResult) => void, + callback: (observableResult: api.BatchObserverResult) => void, options: api.BatchObserverOptions = {} ): BatchObserver { const opt: api.BatchObserverOptions = { diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/BaseObserverMetric.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableBaseMetric.ts similarity index 68% rename from experimental/packages/opentelemetry-sdk-metrics-base/src/BaseObserverMetric.ts rename to experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableBaseMetric.ts index 6f48df49bf..60626680a5 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/BaseObserverMetric.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableBaseMetric.ts @@ -17,22 +17,22 @@ import * as api from '@opentelemetry/api-metrics'; import { Observation } from '@opentelemetry/api-metrics'; import { InstrumentationLibrary } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import { BoundObserver } from './BoundInstrument'; +import { BoundObservable } from './BoundInstrument'; import { Processor } from './export/Processor'; import { MetricKind, MetricRecord } from './export/types'; import { Metric } from './Metric'; -import { ObserverResult } from './ObserverResult'; +import { ObservableResult } from './ObservableResult'; const NOOP_CALLBACK = () => {}; /** * This is a SDK implementation of Base Observer Metric. - * All observers should extend this class + * All observables should extend this class */ -export abstract class BaseObserverMetric - extends Metric - implements api.BaseObserver { - protected _callback: (observerResult: api.ObserverResult) => unknown; +export abstract class ObservableBaseMetric + extends Metric + implements api.ObservableBase { + protected _callback: (observableResult: api.ObservableResult) => unknown; constructor( name: string, @@ -41,14 +41,14 @@ export abstract class BaseObserverMetric resource: Resource, metricKind: MetricKind, instrumentationLibrary: InstrumentationLibrary, - callback?: (observerResult: api.ObserverResult) => unknown + callback?: (observableResult: api.ObservableResult) => unknown ) { super(name, options, metricKind, resource, instrumentationLibrary); this._callback = callback || NOOP_CALLBACK; } - protected _makeInstrument(labels: api.Labels): BoundObserver { - return new BoundObserver( + protected _makeInstrument(labels: api.Labels): BoundObservable { + return new BoundObservable( labels, this._disabled, this._valueType, @@ -57,16 +57,16 @@ export abstract class BaseObserverMetric } override async getMetricRecord(): Promise { - const observerResult = new ObserverResult(); - await this._callback(observerResult); + const observableResult = new ObservableResult(); + await this._callback(observableResult); - this._processResults(observerResult); + this._processResults(observableResult); return super.getMetricRecord(); } - protected _processResults(observerResult: ObserverResult): void { - observerResult.values.forEach((value, labels) => { + protected _processResults(observableResult: ObservableResult): void { + observableResult.values.forEach((value, labels) => { const instrument = this.bind(labels); instrument.update(value); }); @@ -75,7 +75,7 @@ export abstract class BaseObserverMetric observation(value: number): Observation { return { value, - observer: this as BaseObserverMetric, + observable: this as ObservableBaseMetric, }; } } diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/SumObserverMetric.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableCounterMetric.ts similarity index 72% rename from experimental/packages/opentelemetry-sdk-metrics-base/src/SumObserverMetric.ts rename to experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableCounterMetric.ts index 8f58727ceb..5465f14eff 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/SumObserverMetric.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableCounterMetric.ts @@ -17,38 +17,38 @@ import * as api from '@opentelemetry/api-metrics'; import { InstrumentationLibrary } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import { BaseObserverMetric } from './BaseObserverMetric'; +import { ObservableBaseMetric } from './ObservableBaseMetric'; import { Processor } from './export/Processor'; import { LastValue, MetricKind } from './export/types'; -import { ObserverResult } from './ObserverResult'; +import { ObservableResult } from './ObservableResult'; -/** This is a SDK implementation of SumObserver Metric. */ -export class SumObserverMetric - extends BaseObserverMetric - implements api.SumObserver { +/** This is a SDK implementation of ObservableCounter Metric. */ +export class ObservableCounterMetric + extends ObservableBaseMetric + implements api.ObservableCounter { constructor( name: string, options: api.MetricOptions, processor: Processor, resource: Resource, instrumentationLibrary: InstrumentationLibrary, - callback?: (observerResult: api.ObserverResult) => unknown + callback?: (observableResult: api.ObservableResult) => unknown ) { super( name, options, processor, resource, - MetricKind.SUM_OBSERVER, + MetricKind.OBSERVABLE_COUNTER, instrumentationLibrary, callback ); } - protected override _processResults(observerResult: ObserverResult): void { - observerResult.values.forEach((value, labels) => { + protected override _processResults(observableResult: ObservableResult): void { + observableResult.values.forEach((value, labels) => { const instrument = this.bind(labels); - // SumObserver is monotonic which means it should only accept values + // ObservableCounter is monotonic which means it should only accept values // greater or equal then previous value const previous = instrument.getAggregator().toPoint(); let previousValue = -Infinity; diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/ValueObserverMetric.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableGaugeMetric.ts similarity index 78% rename from experimental/packages/opentelemetry-sdk-metrics-base/src/ValueObserverMetric.ts rename to experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableGaugeMetric.ts index a7ac5c5ff5..2d59e78f95 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/ValueObserverMetric.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableGaugeMetric.ts @@ -16,28 +16,28 @@ import * as api from '@opentelemetry/api-metrics'; import { InstrumentationLibrary } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import { BaseObserverMetric } from './BaseObserverMetric'; +import { ObservableBaseMetric } from './ObservableBaseMetric'; import { Processor } from './export/Processor'; import { MetricKind } from './export/types'; -/** This is a SDK implementation of Value Observer Metric. */ -export class ValueObserverMetric - extends BaseObserverMetric - implements api.ValueObserver { +/** This is a SDK implementation of ObservableGauge Metric. */ +export class ObservableGaugeMetric + extends ObservableBaseMetric + implements api.ObservableGauge { constructor( name: string, options: api.MetricOptions, processor: Processor, resource: Resource, instrumentationLibrary: InstrumentationLibrary, - callback?: (observerResult: api.ObserverResult) => unknown + callback?: (observableResult: api.ObservableResult) => unknown ) { super( name, options, processor, resource, - MetricKind.VALUE_OBSERVER, + MetricKind.OBSERVABLE_GAUGE, instrumentationLibrary, callback ); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/ObserverResult.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableResult.ts similarity index 83% rename from experimental/packages/opentelemetry-sdk-metrics-base/src/ObserverResult.ts rename to experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableResult.ts index 60dcc04449..51fc07899e 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/ObserverResult.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableResult.ts @@ -15,14 +15,14 @@ */ import { - ObserverResult as TypeObserverResult, + ObservableResult as TypeObservableResult, Labels, } from '@opentelemetry/api-metrics'; /** - * Implementation of {@link TypeObserverResult} + * Implementation of {@link TypeObservableResult} */ -export class ObserverResult implements TypeObserverResult { +export class ObservableResult implements TypeObservableResult { values: Map = new Map(); observe(value: number, labels: Labels): void { diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/UpDownSumObserverMetric.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableUpDownCounterMetric.ts similarity index 76% rename from experimental/packages/opentelemetry-sdk-metrics-base/src/UpDownSumObserverMetric.ts rename to experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableUpDownCounterMetric.ts index 31cec8af7a..d9a767044a 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/UpDownSumObserverMetric.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableUpDownCounterMetric.ts @@ -17,28 +17,28 @@ import * as api from '@opentelemetry/api-metrics'; import { InstrumentationLibrary } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import { BaseObserverMetric } from './BaseObserverMetric'; +import { ObservableBaseMetric } from './ObservableBaseMetric'; import { Processor } from './export/Processor'; import { MetricKind } from './export/types'; -/** This is a SDK implementation of UpDownSumObserver Metric. */ -export class UpDownSumObserverMetric - extends BaseObserverMetric - implements api.UpDownSumObserver { +/** This is a SDK implementation of ObservableUpDownCounter Metric. */ +export class ObservableUpDownCounterMetric + extends ObservableBaseMetric + implements api.ObservableUpDownCounter { constructor( name: string, options: api.MetricOptions, processor: Processor, resource: Resource, instrumentationLibrary: InstrumentationLibrary, - callback?: (observerResult: api.ObserverResult) => unknown + callback?: (observableResult: api.ObservableResult) => unknown ) { super( name, options, processor, resource, - MetricKind.UP_DOWN_SUM_OBSERVER, + MetricKind.OBSERVABLE_UP_DOWN_COUNTER, instrumentationLibrary, callback ); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/export/Processor.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/export/Processor.ts index 03d2cbcf52..3cc23c70f0 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/export/Processor.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/export/Processor.ts @@ -54,12 +54,12 @@ export class UngroupedProcessor extends Processor { case MetricKind.UP_DOWN_COUNTER: return new aggregators.SumAggregator(); - case MetricKind.SUM_OBSERVER: - case MetricKind.UP_DOWN_SUM_OBSERVER: - case MetricKind.VALUE_OBSERVER: + case MetricKind.OBSERVABLE_COUNTER: + case MetricKind.OBSERVABLE_UP_DOWN_COUNTER: + case MetricKind.OBSERVABLE_GAUGE: return new aggregators.LastValueAggregator(); - case MetricKind.VALUE_RECORDER: + case MetricKind.HISTOGRAM: return new aggregators.HistogramAggregator( metricDescriptor.boundaries || [Infinity] ); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/export/types.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/export/types.ts index 889e96598d..33206ea936 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/export/types.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/export/types.ts @@ -27,10 +27,10 @@ import { Resource } from '@opentelemetry/resources'; export enum MetricKind { COUNTER, UP_DOWN_COUNTER, - VALUE_RECORDER, - SUM_OBSERVER, - UP_DOWN_SUM_OBSERVER, - VALUE_OBSERVER, + HISTOGRAM, + OBSERVABLE_COUNTER, + OBSERVABLE_UP_DOWN_COUNTER, + OBSERVABLE_GAUGE, BATCH_OBSERVER, } diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/index.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/index.ts index afcdeea5b1..a3d74d5352 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/index.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/index.ts @@ -16,11 +16,11 @@ export * from './BoundInstrument'; export * from './CounterMetric'; -export * from './ValueRecorderMetric'; +export * from './HistogramMetric'; export * from './Meter'; export * from './MeterProvider'; export * from './Metric'; -export * from './ValueObserverMetric'; +export * from './ObservableGaugeMetric'; export * from './export/aggregators'; export * from './export/ConsoleMetricExporter'; export * from './export/Processor'; diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts index 0fcc05ede3..e89545f7ad 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts @@ -34,15 +34,15 @@ import { MetricRecord, Sum, UpDownCounterMetric, - ValueObserverMetric, - ValueRecorderMetric, + ObservableGaugeMetric, + HistogramMetric, } from '../src'; import { BatchObserver } from '../src/BatchObserver'; import { BatchObserverResult } from '../src/BatchObserverResult'; import { SumAggregator } from '../src/export/aggregators'; import { Processor } from '../src/export/Processor'; -import { SumObserverMetric } from '../src/SumObserverMetric'; -import { UpDownSumObserverMetric } from '../src/UpDownSumObserverMetric'; +import { ObservableCounterMetric } from '../src/ObservableCounterMetric'; +import { ObservableUpDownCounterMetric } from '../src/ObservableUpDownCounterMetric'; import { hashLabels } from '../src/Utils'; const nonNumberValues = [ @@ -550,33 +550,33 @@ describe('Meter', () => { }); }); - describe('#ValueRecorder', () => { - it('should create a valueRecorder', () => { - const valueRecorder = meter.createValueRecorder('name'); - assert.ok(valueRecorder instanceof Metric); + describe('#Histogram', () => { + it('should create a histogram', () => { + const histogram = meter.createHistogram('name'); + assert.ok(histogram instanceof Metric); }); - it('should create a valueRecorder with options', () => { - const valueRecorder = meter.createValueRecorder('name', { + it('should create a histogram with options', () => { + const histogram = meter.createHistogram('name', { description: 'desc', unit: '1', disabled: false, }); - assert.ok(valueRecorder instanceof Metric); + assert.ok(histogram instanceof Metric); }); - it('should set histogram boundaries for value recorder', async () => { - const valueRecorder = meter.createValueRecorder('name', { + it('should set histogram boundaries for histogram', async () => { + const histogram = meter.createHistogram('name', { description: 'desc', unit: '1', disabled: false, boundaries: [10, 20, 30, 100], - }) as ValueRecorderMetric; + }) as HistogramMetric; - valueRecorder.record(10); - valueRecorder.record(30); - valueRecorder.record(50); - valueRecorder.record(200); + histogram.record(10); + histogram.record(30); + histogram.record(50); + histogram.record(200); await meter.collect(); const [record] = meter.getProcessor().checkPointSet(); @@ -589,30 +589,30 @@ describe('Meter', () => { sum: 290, }); - assert.ok(valueRecorder instanceof Metric); + assert.ok(histogram instanceof Metric); }); it('should pipe through resource', async () => { - const valueRecorder = meter.createValueRecorder( + const histogram = meter.createHistogram( 'name' - ) as ValueRecorderMetric; - assert.ok(valueRecorder.resource instanceof Resource); + ) as HistogramMetric; + assert.ok(histogram.resource instanceof Resource); - valueRecorder.record(1, { foo: 'bar' }); + histogram.record(1, { foo: 'bar' }); - const [record] = await valueRecorder.getMetricRecord(); + const [record] = await histogram.getMetricRecord(); assert.ok(record.resource instanceof Resource); }); it('should pipe through instrumentation library', async () => { - const valueRecorder = meter.createValueRecorder( + const histogram = meter.createHistogram( 'name' - ) as ValueRecorderMetric; - assert.ok(valueRecorder.instrumentationLibrary); + ) as HistogramMetric; + assert.ok(histogram.instrumentationLibrary); - valueRecorder.record(1, { foo: 'bar' }); + histogram.record(1, { foo: 'bar' }); - const [record] = await valueRecorder.getMetricRecord(); + const [record] = await histogram.getMetricRecord(); const { name, version } = record.instrumentationLibrary; assert.strictEqual(name, 'test-meter'); assert.strictEqual(version, undefined); @@ -620,42 +620,42 @@ describe('Meter', () => { describe('names', () => { it('should return no op metric if name is an empty string', () => { - const valueRecorder = meter.createValueRecorder(''); - assert.ok(valueRecorder instanceof api.NoopMetric); + const histogram = meter.createHistogram(''); + assert.ok(histogram instanceof api.NoopMetric); }); it('should return no op metric if name does not start with a letter', () => { - const valueRecorder1 = meter.createValueRecorder('1name'); - const valueRecorder_ = meter.createValueRecorder('_name'); - assert.ok(valueRecorder1 instanceof api.NoopMetric); - assert.ok(valueRecorder_ instanceof api.NoopMetric); + const histogram1 = meter.createHistogram('1name'); + const histogram_ = meter.createHistogram('_name'); + assert.ok(histogram1 instanceof api.NoopMetric); + assert.ok(histogram_ instanceof api.NoopMetric); }); it('should return no op metric if name is an empty string contain only letters, numbers, ".", "_", and "-"', () => { - const valueRecorder = meter.createValueRecorder( + const histogram = meter.createHistogram( 'name with invalid characters^&*(' ); - assert.ok(valueRecorder instanceof api.NoopMetric); + assert.ok(histogram instanceof api.NoopMetric); }); }); describe('.bind()', () => { const performanceTimeOrigin = hrTime(); - it('should create a valueRecorder instrument', () => { - const valueRecorder = meter.createValueRecorder( + it('should create a histogram instrument', () => { + const histogram = meter.createHistogram( 'name' - ) as ValueRecorderMetric; - const boundValueRecorder = valueRecorder.bind(labels); - assert.doesNotThrow(() => boundValueRecorder.record(10)); + ) as HistogramMetric; + const boundHistogram = histogram.bind(labels); + assert.doesNotThrow(() => boundHistogram.record(10)); }); it('should not set the instrument data when disabled', async () => { - const valueRecorder = meter.createValueRecorder('name', { + const histogram = meter.createHistogram('name', { disabled: true, - }) as ValueRecorderMetric; - const boundValueRecorder = valueRecorder.bind(labels); - boundValueRecorder.record(10); + }) as HistogramMetric; + const boundHistogram = histogram.bind(labels); + boundHistogram.record(10); await meter.collect(); const [record1] = meter.getProcessor().checkPointSet(); @@ -673,10 +673,10 @@ describe('Meter', () => { }); it('should accept negative (and positive) values', async () => { - const valueRecorder = meter.createValueRecorder('name'); - const boundValueRecorder = valueRecorder.bind(labels); - boundValueRecorder.record(-10); - boundValueRecorder.record(50); + const histogram = meter.createHistogram('name'); + const boundHistogram = histogram.bind(labels); + boundHistogram.record(-10); + boundHistogram.record(50); await meter.collect(); const [record1] = meter.getProcessor().checkPointSet(); @@ -698,13 +698,13 @@ describe('Meter', () => { }); it('should return same instrument on same label values', async () => { - const valueRecorder = meter.createValueRecorder( + const histogram = meter.createHistogram( 'name' - ) as ValueRecorderMetric; - const boundValueRecorder1 = valueRecorder.bind(labels); - boundValueRecorder1.record(10); - const boundValueRecorder2 = valueRecorder.bind(labels); - boundValueRecorder2.record(100); + ) as HistogramMetric; + const boundHistogram1 = histogram.bind(labels); + boundHistogram1.record(10); + const boundHistogram2 = histogram.bind(labels); + boundHistogram2.record(100); await meter.collect(); const [record1] = meter.getProcessor().checkPointSet(); assert.deepStrictEqual( @@ -718,19 +718,19 @@ describe('Meter', () => { sum: 110, } ); - assert.strictEqual(boundValueRecorder1, boundValueRecorder2); + assert.strictEqual(boundHistogram1, boundHistogram2); }); it('should ignore non-number values', async () => { - const valueRecorder = meter.createValueRecorder( + const histogram = meter.createHistogram( 'name' - ) as ValueRecorderMetric; - const boundValueRecorder = valueRecorder.bind(labels); + ) as HistogramMetric; + const boundHistogram = histogram.bind(labels); await Promise.all( nonNumberValues.map(async val => { // @ts-expect-error verify non number types - boundValueRecorder.record(val); + boundHistogram.record(val); await meter.collect(); const [record1] = meter.getProcessor().checkPointSet(); assert.deepStrictEqual( @@ -750,47 +750,47 @@ describe('Meter', () => { }); describe('.unbind()', () => { - it('should remove the valueRecorder instrument', () => { - const valueRecorder = meter.createValueRecorder( + it('should remove the histogram instrument', () => { + const histogram = meter.createHistogram( 'name' - ) as ValueRecorderMetric; - const boundValueRecorder = valueRecorder.bind(labels); - assert.strictEqual(valueRecorder['_instruments'].size, 1); - valueRecorder.unbind(labels); - assert.strictEqual(valueRecorder['_instruments'].size, 0); - const boundValueRecorder2 = valueRecorder.bind(labels); - assert.strictEqual(valueRecorder['_instruments'].size, 1); - assert.notStrictEqual(boundValueRecorder, boundValueRecorder2); + ) as HistogramMetric; + const boundHistogram = histogram.bind(labels); + assert.strictEqual(histogram['_instruments'].size, 1); + histogram.unbind(labels); + assert.strictEqual(histogram['_instruments'].size, 0); + const boundHistogram2 = histogram.bind(labels); + assert.strictEqual(histogram['_instruments'].size, 1); + assert.notStrictEqual(boundHistogram, boundHistogram2); }); it('should not fail when removing non existing instrument', () => { - const valueRecorder = meter.createValueRecorder('name'); - valueRecorder.unbind({}); + const histogram = meter.createHistogram('name'); + histogram.unbind({}); }); it('should clear all instruments', () => { - const valueRecorder = meter.createValueRecorder( + const histogram = meter.createHistogram( 'name' - ) as ValueRecorderMetric; - valueRecorder.bind(labels); - assert.strictEqual(valueRecorder['_instruments'].size, 1); - valueRecorder.clear(); - assert.strictEqual(valueRecorder['_instruments'].size, 0); + ) as HistogramMetric; + histogram.bind(labels); + assert.strictEqual(histogram['_instruments'].size, 1); + histogram.clear(); + assert.strictEqual(histogram['_instruments'].size, 0); }); }); }); - describe('#SumObserverMetric', () => { - it('should create an Sum observer', () => { - const sumObserver = meter.createSumObserver('name') as SumObserverMetric; - assert.ok(sumObserver instanceof Metric); + describe('#ObservableCounterMetric', () => { + it('should create an ObservableCounter', () => { + const observableCounter = meter.createObservableCounter('name') as ObservableCounterMetric; + assert.ok(observableCounter instanceof Metric); }); - it('should return noop observer when name is invalid', () => { + it('should return noop observable counter when name is invalid', () => { // Need to stub/spy on the underlying logger as the "diag" instance is global const spy = sinon.stub(diag, 'warn'); - const sumObserver = meter.createSumObserver('na me'); - assert.ok(sumObserver === api.NOOP_SUM_OBSERVER_METRIC); + const observableCounter = meter.createObservableCounter('na me'); + assert.ok(observableCounter === api.NOOP_OBSERVABLE_COUNTER_METRIC); const args = spy.args[0]; assert.ok( args[0], @@ -798,13 +798,13 @@ describe('Meter', () => { ); }); - it('should create observer with options', () => { - const sumObserver = meter.createSumObserver('name', { + it('should create observable counter with options', () => { + const observableCounter = meter.createObservableCounter('name', { description: 'desc', unit: '1', disabled: false, - }) as SumObserverMetric; - assert.ok(sumObserver instanceof Metric); + }) as ObservableCounterMetric; + assert.ok(observableCounter instanceof Metric); }); it('should set callback and observe value ', async () => { @@ -818,23 +818,23 @@ describe('Meter', () => { return -1; } - const sumObserver = meter.createSumObserver( + const observableCounter = meter.createObservableCounter( 'name', { description: 'desc', }, - (observerResult: api.ObserverResult) => { + (observableResult: api.ObservableResult) => { // simulate async return new Promise(resolve => { setTimeout(() => { - observerResult.observe(getValue(), { pid: '123', core: '1' }); + observableResult.observe(getValue(), { pid: '123', core: '1' }); resolve(); }, 1); }); } - ) as SumObserverMetric; + ) as ObservableCounterMetric; - let metricRecords = await sumObserver.getMetricRecord(); + let metricRecords = await observableCounter.getMetricRecord(); assert.strictEqual(metricRecords.length, 1); let point = metricRecords[0].aggregator.toPoint(); assert.strictEqual(point.value, -1); @@ -843,29 +843,29 @@ describe('Meter', () => { '|#core:1,pid:123' ); - metricRecords = await sumObserver.getMetricRecord(); + metricRecords = await observableCounter.getMetricRecord(); assert.strictEqual(metricRecords.length, 1); point = metricRecords[0].aggregator.toPoint(); assert.strictEqual(point.value, 3); - metricRecords = await sumObserver.getMetricRecord(); + metricRecords = await observableCounter.getMetricRecord(); assert.strictEqual(metricRecords.length, 1); point = metricRecords[0].aggregator.toPoint(); assert.strictEqual(point.value, 3); }); it('should set callback and observe value when callback returns nothing', async () => { - const sumObserver = meter.createSumObserver( + const observableCounter = meter.createObservableCounter( 'name', { description: 'desc', }, - (observerResult: api.ObserverResult) => { - observerResult.observe(1, { pid: '123', core: '1' }); + (observableResult: api.ObservableResult) => { + observableResult.observe(1, { pid: '123', core: '1' }); } - ) as SumObserverMetric; + ) as ObservableCounterMetric; - const metricRecords = await sumObserver.getMetricRecord(); + const metricRecords = await observableCounter.getMetricRecord(); assert.strictEqual(metricRecords.length, 1); }); @@ -873,34 +873,34 @@ describe('Meter', () => { 'should set callback and observe value when callback returns anything' + ' but Promise', async () => { - const sumObserver = meter.createSumObserver( + const observableCounter = meter.createObservableCounter( 'name', { description: 'desc', }, - (observerResult: api.ObserverResult) => { - observerResult.observe(1, { pid: '123', core: '1' }); + (observableResult: api.ObservableResult) => { + observableResult.observe(1, { pid: '123', core: '1' }); return '1'; } - ) as SumObserverMetric; + ) as ObservableCounterMetric; - const metricRecords = await sumObserver.getMetricRecord(); + const metricRecords = await observableCounter.getMetricRecord(); assert.strictEqual(metricRecords.length, 1); } ); it('should reject getMetricRecord when callback throws an error', async () => { - const sumObserver = meter.createSumObserver( + const observableCounter = meter.createObservableCounter( 'name', { description: 'desc', }, - (observerResult: api.ObserverResult) => { - observerResult.observe(1, { pid: '123', core: '1' }); + (observableResult: api.ObservableResult) => { + observableResult.observe(1, { pid: '123', core: '1' }); throw new Error('Boom'); } - ) as SumObserverMetric; - await sumObserver + ) as ObservableCounterMetric; + await observableCounter .getMetricRecord() .then() .catch(e => { @@ -909,30 +909,30 @@ describe('Meter', () => { }); it('should pipe through resource', async () => { - const sumObserver = meter.createSumObserver('name', {}, result => { + const observableCounter = meter.createObservableCounter('name', {}, result => { result.observe(42, { foo: 'bar' }); return Promise.resolve(); - }) as SumObserverMetric; - assert.ok(sumObserver.resource instanceof Resource); + }) as ObservableCounterMetric; + assert.ok(observableCounter.resource instanceof Resource); - const [record] = await sumObserver.getMetricRecord(); + const [record] = await observableCounter.getMetricRecord(); assert.ok(record.resource instanceof Resource); }); }); - describe('#ValueObserver', () => { - it('should create a value observer', () => { - const valueObserver = meter.createValueObserver( + describe('#ObservableGauge', () => { + it('should create an observable gauge', () => { + const observableGauge = meter.createObservableGauge( 'name' - ) as ValueObserverMetric; - assert.ok(valueObserver instanceof Metric); + ) as ObservableGaugeMetric; + assert.ok(observableGauge instanceof Metric); }); - it('should return noop observer when name is invalid', () => { + it('should return noop observable gauge when name is invalid', () => { // Need to stub/spy on the underlying logger as the "diag" instance is global const spy = sinon.stub(diag, 'warn'); - const valueObserver = meter.createValueObserver('na me'); - assert.ok(valueObserver === api.NOOP_VALUE_OBSERVER_METRIC); + const observableGauge = meter.createObservableGauge('na me'); + assert.ok(observableGauge === api.NOOP_OBSERVABLE_GAUGE_METRIC); const args = spy.args[0]; assert.ok( args[0], @@ -940,40 +940,40 @@ describe('Meter', () => { ); }); - it('should create observer with options', () => { - const valueObserver = meter.createValueObserver('name', { + it('should create observable gauge with options', () => { + const observableGauge = meter.createObservableGauge('name', { description: 'desc', unit: '1', disabled: false, - }) as ValueObserverMetric; - assert.ok(valueObserver instanceof Metric); + }) as ObservableGaugeMetric; + assert.ok(observableGauge instanceof Metric); }); it('should set callback and observe value ', async () => { - const valueObserver = meter.createValueObserver( + const observableGauge = meter.createObservableGauge( 'name', { description: 'desc', }, - (observerResult: api.ObserverResult) => { + (observableResult: api.ObservableResult) => { // simulate async return new Promise(resolve => { setTimeout(() => { - observerResult.observe(getCpuUsage(), { pid: '123', core: '1' }); - observerResult.observe(getCpuUsage(), { pid: '123', core: '2' }); - observerResult.observe(getCpuUsage(), { pid: '123', core: '3' }); - observerResult.observe(getCpuUsage(), { pid: '123', core: '4' }); + observableResult.observe(getCpuUsage(), { pid: '123', core: '1' }); + observableResult.observe(getCpuUsage(), { pid: '123', core: '2' }); + observableResult.observe(getCpuUsage(), { pid: '123', core: '3' }); + observableResult.observe(getCpuUsage(), { pid: '123', core: '4' }); resolve(); }, 1); }); } - ) as ValueObserverMetric; + ) as ObservableGaugeMetric; function getCpuUsage() { return Math.random(); } - const metricRecords: MetricRecord[] = await valueObserver.getMetricRecord(); + const metricRecords: MetricRecord[] = await observableGauge.getMetricRecord(); assert.strictEqual(metricRecords.length, 4); const metric1 = metricRecords[0]; @@ -992,29 +992,29 @@ describe('Meter', () => { }); it('should pipe through resource', async () => { - const valueObserver = meter.createValueObserver('name', {}, result => { + const observableGauge = meter.createObservableGauge('name', {}, result => { result.observe(42, { foo: 'bar' }); - }) as ValueObserverMetric; - assert.ok(valueObserver.resource instanceof Resource); + }) as ObservableGaugeMetric; + assert.ok(observableGauge.resource instanceof Resource); - const [record] = await valueObserver.getMetricRecord(); + const [record] = await observableGauge.getMetricRecord(); assert.ok(record.resource instanceof Resource); }); }); - describe('#UpDownSumObserverMetric', () => { - it('should create an UpDownSum observer', () => { - const upDownSumObserver = meter.createUpDownSumObserver( + describe('#ObservableUpDownCounterMetric', () => { + it('should create an ObservableUpDownCounter', () => { + const observableUpDownCounter = meter.createObservableUpDownCounter( 'name' - ) as UpDownSumObserverMetric; - assert.ok(upDownSumObserver instanceof Metric); + ) as ObservableUpDownCounterMetric; + assert.ok(observableUpDownCounter instanceof Metric); }); - it('should return noop observer when name is invalid', () => { + it('should return noop observable up down counter when name is invalid', () => { // Need to stub/spy on the underlying logger as the "diag" instance is global const spy = sinon.stub(diag, 'warn'); - const upDownSumObserver = meter.createUpDownSumObserver('na me'); - assert.ok(upDownSumObserver === api.NOOP_UP_DOWN_SUM_OBSERVER_METRIC); + const observableUpDownCounter = meter.createObservableUpDownCounter('na me'); + assert.ok(observableUpDownCounter === api.NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC); const args = spy.args[0]; assert.ok( args[0], @@ -1022,13 +1022,13 @@ describe('Meter', () => { ); }); - it('should create observer with options', () => { - const upDownSumObserver = meter.createUpDownSumObserver('name', { + it('should create observable up down counter with options', () => { + const observableUpDownCounter = meter.createObservableUpDownCounter('name', { description: 'desc', unit: '1', disabled: false, - }) as UpDownSumObserverMetric; - assert.ok(upDownSumObserver instanceof Metric); + }) as ObservableUpDownCounterMetric; + assert.ok(observableUpDownCounter instanceof Metric); }); it('should set callback and observe value ', async () => { @@ -1042,23 +1042,23 @@ describe('Meter', () => { return 3; } - const upDownSumObserver = meter.createUpDownSumObserver( + const observableUpDownCounter = meter.createObservableUpDownCounter( 'name', { description: 'desc', }, - (observerResult: api.ObserverResult) => { + (observableResult: api.ObservableResult) => { // simulate async return new Promise(resolve => { setTimeout(() => { - observerResult.observe(getValue(), { pid: '123', core: '1' }); + observableResult.observe(getValue(), { pid: '123', core: '1' }); resolve(); }, 1); }); } - ) as UpDownSumObserverMetric; + ) as ObservableUpDownCounterMetric; - let metricRecords = await upDownSumObserver.getMetricRecord(); + let metricRecords = await observableUpDownCounter.getMetricRecord(); assert.strictEqual(metricRecords.length, 1); let point = metricRecords[0].aggregator.toPoint(); assert.strictEqual(point.value, 3); @@ -1067,29 +1067,29 @@ describe('Meter', () => { '|#core:1,pid:123' ); - metricRecords = await upDownSumObserver.getMetricRecord(); + metricRecords = await observableUpDownCounter.getMetricRecord(); assert.strictEqual(metricRecords.length, 1); point = metricRecords[0].aggregator.toPoint(); assert.strictEqual(point.value, 2); - metricRecords = await upDownSumObserver.getMetricRecord(); + metricRecords = await observableUpDownCounter.getMetricRecord(); assert.strictEqual(metricRecords.length, 1); point = metricRecords[0].aggregator.toPoint(); assert.strictEqual(point.value, 3); }); it('should set callback and observe value when callback returns nothing', async () => { - const upDownSumObserver = meter.createUpDownSumObserver( + const observableUpDownCounter = meter.createObservableUpDownCounter( 'name', { description: 'desc', }, - (observerResult: api.ObserverResult) => { - observerResult.observe(1, { pid: '123', core: '1' }); + (observableResult: api.ObservableResult) => { + observableResult.observe(1, { pid: '123', core: '1' }); } - ) as UpDownSumObserverMetric; + ) as ObservableUpDownCounterMetric; - const metricRecords = await upDownSumObserver.getMetricRecord(); + const metricRecords = await observableUpDownCounter.getMetricRecord(); assert.strictEqual(metricRecords.length, 1); }); @@ -1097,34 +1097,34 @@ describe('Meter', () => { 'should set callback and observe value when callback returns anything' + ' but Promise', async () => { - const upDownSumObserver = meter.createUpDownSumObserver( + const observableUpDownCounter = meter.createObservableUpDownCounter( 'name', { description: 'desc', }, - (observerResult: api.ObserverResult) => { - observerResult.observe(1, { pid: '123', core: '1' }); + (observableResult: api.ObservableResult) => { + observableResult.observe(1, { pid: '123', core: '1' }); return '1'; } - ) as UpDownSumObserverMetric; + ) as ObservableUpDownCounterMetric; - const metricRecords = await upDownSumObserver.getMetricRecord(); + const metricRecords = await observableUpDownCounter.getMetricRecord(); assert.strictEqual(metricRecords.length, 1); } ); it('should reject getMetricRecord when callback throws an error', async () => { - const upDownSumObserver = meter.createUpDownSumObserver( + const observableUpDownCounter = meter.createObservableUpDownCounter( 'name', { description: 'desc', }, - (observerResult: api.ObserverResult) => { - observerResult.observe(1, { pid: '123', core: '1' }); + (observableResult: api.ObservableResult) => { + observableResult.observe(1, { pid: '123', core: '1' }); throw new Error('Boom'); } - ) as UpDownSumObserverMetric; - await upDownSumObserver + ) as ObservableUpDownCounterMetric; + await observableUpDownCounter .getMetricRecord() .then() .catch(e => { @@ -1133,17 +1133,17 @@ describe('Meter', () => { }); it('should pipe through resource', async () => { - const upDownSumObserver = meter.createUpDownSumObserver( + const observableUpDownCounter = meter.createObservableUpDownCounter( 'name', {}, result => { result.observe(42, { foo: 'bar' }); return Promise.resolve(); } - ) as UpDownSumObserverMetric; - assert.ok(upDownSumObserver.resource instanceof Resource); + ) as ObservableUpDownCounterMetric; + assert.ok(observableUpDownCounter.resource instanceof Resource); - const [record] = await upDownSumObserver.getMetricRecord(); + const [record] = await observableUpDownCounter.getMetricRecord(); assert.ok(record.resource instanceof Resource); }); }); @@ -1162,15 +1162,15 @@ describe('Meter', () => { }); it('should use callback to observe values ', async () => { - const tempMetric = meter.createValueObserver('cpu_temp_per_app', { + const tempMetric = meter.createObservableGauge('cpu_temp_per_app', { description: 'desc', - }) as ValueObserverMetric; + }) as ObservableGaugeMetric; - const cpuUsageMetric = meter.createValueObserver('cpu_usage_per_app', { + const cpuUsageMetric = meter.createObservableGauge('cpu_usage_per_app', { description: 'desc', - }) as ValueObserverMetric; + }) as ObservableGaugeMetric; - meter.createBatchObserver(observerBatchResult => { + meter.createBatchObserver(batchObserverResult => { interface StatItem { usage: number; temp: number; @@ -1209,11 +1209,11 @@ describe('Meter', () => { ]).then((stats: unknown[]) => { const apps = (stats[0] as unknown) as Stat[]; apps.forEach(app => { - observerBatchResult.observe({ app: app.name, core: '1' }, [ + batchObserverResult.observe({ app: app.name, core: '1' }, [ tempMetric.observation(app.core1.temp), cpuUsageMetric.observation(app.core1.usage), ]); - observerBatchResult.observe({ app: app.name, core: '2' }, [ + batchObserverResult.observe({ app: app.name, core: '2' }, [ tempMetric.observation(app.core2.temp), cpuUsageMetric.observation(app.core2.usage), ]); @@ -1255,12 +1255,12 @@ describe('Meter', () => { }); it('should not observe values when timeout', done => { - const cpuUsageMetric = meter.createValueObserver('cpu_usage_per_app', { + const cpuUsageMetric = meter.createObservableGauge('cpu_usage_per_app', { description: 'desc', - }) as ValueObserverMetric; + }) as ObservableGaugeMetric; meter.createBatchObserver( - observerBatchResult => { + batchObserverResult => { Promise.all([ // simulate waiting 11ms new Promise((resolve, reject) => { @@ -1268,8 +1268,8 @@ describe('Meter', () => { }), ]).then(async () => { // try to hack to be able to update - (observerBatchResult as BatchObserverResult).cancelled = false; - observerBatchResult.observe({ foo: 'bar' }, [ + (batchObserverResult as BatchObserverResult).cancelled = false; + batchObserverResult.observe({ foo: 'bar' }, [ cpuUsageMetric.observation(123), ]); @@ -1296,16 +1296,16 @@ describe('Meter', () => { }); it('should pipe through instrumentation library', async () => { - const observer = meter.createValueObserver( + const observableGauge = meter.createObservableGauge( 'name', {}, - (observerResult: api.ObserverResult) => { - observerResult.observe(42, { foo: 'bar' }); + (observableResult: api.ObservableResult) => { + observableResult.observe(42, { foo: 'bar' }); } - ) as ValueObserverMetric; - assert.ok(observer.instrumentationLibrary); + ) as ObservableGaugeMetric; + assert.ok(observableGauge.instrumentationLibrary); - const [record] = await observer.getMetricRecord(); + const [record] = await observableGauge.getMetricRecord(); const { name, version } = record.instrumentationLibrary; assert.strictEqual(name, 'test-meter'); assert.strictEqual(version, undefined); @@ -1370,8 +1370,8 @@ describe('Meter', () => { processor: new CustomProcessor(), }); assert.throws(() => { - const valueRecorder = customMeter.createValueRecorder('myValueRecorder'); - valueRecorder.bind({}).record(1); + const histogram = customMeter.createHistogram('myHistogram'); + histogram.bind({}).record(1); }, /aggregatorFor method not implemented/); }); }); @@ -1396,6 +1396,6 @@ function ensureMetric(metric: MetricRecord, name?: string, value?: LastValue) { assert.strictEqual(descriptor.name, name || 'name'); assert.strictEqual(descriptor.description, 'desc'); assert.strictEqual(descriptor.unit, '1'); - assert.strictEqual(descriptor.metricKind, MetricKind.VALUE_OBSERVER); + assert.strictEqual(descriptor.metricKind, MetricKind.OBSERVABLE_GAUGE); assert.strictEqual(descriptor.valueType, api.ValueType.DOUBLE); }