Skip to content

Commit

Permalink
chore: adding metric observable to be able to support async upda… (op…
Browse files Browse the repository at this point in the history
…en-telemetry#964)

* chore: adding metric observable to be able to support async update

* chore: reviews

* chore: reviews

Co-authored-by: Daniel Dyla <[email protected]>
  • Loading branch information
obecny and dyladan committed Feb 18, 2021
1 parent f5234c6 commit a517dc1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
36 changes: 36 additions & 0 deletions api/src/metrics/MetricObservable.ts
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 2 additions & 2 deletions api/src/metrics/ObserverResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Labels, Function>;
observe(callback: Function, labels: Labels): void;
observe(callback: Function | MetricObservable, labels: Labels): void;
}

0 comments on commit a517dc1

Please sign in to comment.