Skip to content

Commit

Permalink
feat(api-metrics): remove observable types (#2687)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Marchaud <[email protected]>
Co-authored-by: Daniel Dyla <[email protected]>
  • Loading branch information
3 people authored Dec 28, 2021
1 parent 0e9f8af commit eba315b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 54 deletions.
31 changes: 7 additions & 24 deletions experimental/packages/opentelemetry-api-metrics/src/NoopMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ import {
Attributes,
Counter,
Histogram,
ObservableGauge,
UpDownCounter,
ObservableBase,
ObservableCounter,
ObservableUpDownCounter,
ObservableCallback,
} from './types/Metric';
import { ObservableResult } from './types/ObservableResult';

/**
* NoopMeter is a noop implementation of the {@link Meter} interface. It reuses
Expand Down Expand Up @@ -70,11 +66,9 @@ export class NoopMeter implements Meter {
*/
createObservableGauge(
_name: string,
_callback: (observableResult: ObservableResult) => void,
_callback: ObservableCallback,
_options?: MetricOptions,
): ObservableGauge {
return NOOP_OBSERVABLE_GAUGE_METRIC;
}
): void {}

/**
* Returns a constant noop observable counter.
Expand All @@ -84,11 +78,9 @@ export class NoopMeter implements Meter {
*/
createObservableCounter(
_name: string,
_callback: (observableResult: ObservableResult) => void,
_callback: ObservableCallback,
_options?: MetricOptions,
): ObservableCounter {
return NOOP_OBSERVABLE_COUNTER_METRIC;
}
): void {}

/**
* Returns a constant noop up down observable counter.
Expand All @@ -98,11 +90,9 @@ export class NoopMeter implements Meter {
*/
createObservableUpDownCounter(
_name: string,
_callback: (observableResult: ObservableResult) => void,
_callback: ObservableCallback,
_options?: MetricOptions,
): ObservableUpDownCounter {
return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
}
): void {}
}

export class NoopMetric {}
Expand All @@ -119,16 +109,9 @@ export class NoopHistogramMetric extends NoopMetric implements Histogram {
record(_value: number, _attributes: Attributes): void {}
}

export class NoopObservableBaseMetric extends NoopMetric implements ObservableBase {}

export const NOOP_METER = new NoopMeter();

// Synchronous instruments
export const NOOP_COUNTER_METRIC = new NoopCounterMetric();
export const NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric();
export const NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();

// Asynchronous instruments
export const NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableBaseMetric();
export const NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableBaseMetric();
export const NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableBaseMetric();
17 changes: 7 additions & 10 deletions experimental/packages/opentelemetry-api-metrics/src/types/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ import { CounterOptions, HistogramOptions, UpDownCounterOptions } from '..';
import {
Counter,
Histogram,
ObservableCounter,
ObservableCallback,
ObservableCounterOptions,
ObservableGauge,
ObservableGaugeOptions,
ObservableUpDownCounter,
ObservableUpDownCounterOptions,
UpDownCounter,
} from './Metric';
import { ObservableResult } from './ObservableResult';

/**
* An interface describes additional metadata of a meter.
Expand Down Expand Up @@ -89,9 +86,9 @@ export interface Meter {
*/
createObservableGauge(
name: string,
callback: (observableResult: ObservableResult) => void,
callback: ObservableCallback,
options?: ObservableGaugeOptions
): ObservableGauge;
): void;

/**
* Creates a new `ObservableCounter` metric.
Expand All @@ -101,9 +98,9 @@ export interface Meter {
*/
createObservableCounter(
name: string,
callback: (observableResult: ObservableResult) => void,
callback: ObservableCallback,
options?: ObservableCounterOptions
): ObservableCounter;
): void;

/**
* Creates a new `ObservableUpDownCounter` metric.
Expand All @@ -113,7 +110,7 @@ export interface Meter {
*/
createObservableUpDownCounter(
name: string,
callback: (observableResult: ObservableResult) => void,
callback: ObservableCallback,
options?: ObservableUpDownCounterOptions
): ObservableUpDownCounter;
): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Context } from '@opentelemetry/api';
import { ObservableResult } from './ObservableResult';

/**
* Options needed for metric creation
Expand Down Expand Up @@ -88,21 +89,12 @@ export interface Histogram {
record(value: number, attributes?: Attributes, context?: Context): void;
}

// ObservableBase has to be an Object but for now there is no field or method
// declared.
/** Base interface for the Observable metrics. */
export type ObservableBase = Record<never, never>;

/** Base interface for the ObservableGauge metrics. */
export type ObservableGauge = ObservableBase;

/** Base interface for the ObservableUpDownCounter metrics. */
export type ObservableUpDownCounter = ObservableBase;

/** Base interface for the ObservableCounter metrics. */
export type ObservableCounter = ObservableBase;

/**
* key-value pairs passed by the user.
*/
export type Attributes = { [key: string]: string };

/**
* The observable callback for Observable instruments.
*/
export type ObservableCallback = (observableResult: ObservableResult) => void | Promise<void>;
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ export class Meter implements metrics.Meter {

createObservableGauge(
_name: string,
_callback: (observableResult: metrics.ObservableResult) => void,
_callback: metrics.ObservableCallback,
_options?: metrics.ObservableGaugeOptions,
): metrics.ObservableGauge {
): void {
throw new Error('Method not implemented.');
}

createObservableCounter(
_name: string,
_callback: (observableResult: metrics.ObservableResult) => void,
_callback: metrics.ObservableCallback,
_options?: metrics.ObservableCounterOptions,
): metrics.ObservableCounter {
): void {
throw new Error('Method not implemented.');
}

createObservableUpDownCounter(
_name: string,
_callback: (observableResult: metrics.ObservableResult) => void,
_callback: metrics.ObservableCallback,
_options?: metrics.ObservableUpDownCounterOptions,
): metrics.ObservableUpDownCounter {
): void {
throw new Error('Method not implemented.');
}

Expand Down

0 comments on commit eba315b

Please sign in to comment.