Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api-metrics): remove observable types #2687

Merged
merged 5 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
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>;
dyladan marked this conversation as resolved.
Show resolved Hide resolved
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