diff --git a/api/src/index.ts b/api/src/index.ts index 070ed01c05..a4a7406e71 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -26,6 +26,7 @@ export * from './metrics/BoundInstrument'; export * from './metrics/Meter'; export * from './metrics/MeterProvider'; export * from './metrics/Metric'; +export * from './metrics/MetricObservable'; export * from './metrics/NoopMeter'; export * from './metrics/NoopMeterProvider'; export * from './metrics/ObserverResult'; diff --git a/api/src/metrics/MetricObservable.ts b/api/src/metrics/MetricObservable.ts new file mode 100644 index 0000000000..4e25dce4e5 --- /dev/null +++ b/api/src/metrics/MetricObservable.ts @@ -0,0 +1,36 @@ +/*! + * Copyright 2020, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Metric Observable class to handle asynchronous metrics + */ +export interface MetricObservable { + /** + * Sets the next value for observable metric + * @param value + */ + next: (value: number) => void; + /** + * Subscribes for every value change + * @param callback + */ + subscribe: (callback: (value: number) => void) => void; + /** + * Removes the subscriber + * @param [callback] + */ + unsubscribe: (callback?: (value: number) => void) => void; +} diff --git a/api/src/metrics/ObserverResult.ts b/api/src/metrics/ObserverResult.ts index 6fb4edba70..47c3d595c4 100644 --- a/api/src/metrics/ObserverResult.ts +++ b/api/src/metrics/ObserverResult.ts @@ -15,11 +15,11 @@ */ import { Labels } from './Metric'; +import { MetricObservable } from './MetricObservable'; /** * Interface that is being used in function setCallback for Observer Metric */ export interface ObserverResult { - observers: Map; - observe(callback: Function, labels: Labels): void; + observe(callback: Function | MetricObservable, labels: Labels): void; }