Skip to content

Commit

Permalink
feat: spec compliant metric creation
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Nov 3, 2021
1 parent 85d5110 commit 4de7823
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 44 deletions.
3 changes: 3 additions & 0 deletions experimental/packages/opentelemetry-api-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"publishConfig": {
"access": "public"
},
"dependencies": {
"@opentelemetry/api": "^1.0.0"
},
"devDependencies": {
"@types/mocha": "8.2.3",
"@types/node": "14.17.11",
Expand Down
21 changes: 12 additions & 9 deletions experimental/packages/opentelemetry-api-metrics/src/types/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
* limitations under the License.
*/

import { CounterOptions, HistogramOptions, UpDownCounterOptions } from '..';
import {
MetricOptions,
Counter,
Histogram,
ObservableGauge,
UpDownCounter,
ObservableCounter,
ObservableCounterOptions,
ObservableGauge,
ObservableGaugeOptions,
ObservableUpDownCounter,
ObservableUpDownCounterOptions,
UpDownCounter,
} from './Metric';
import { ObservableResult } from './ObservableResult';

Expand All @@ -48,7 +51,7 @@ export interface Meter {
* @param name the name of the metric.
* @param [options] the metric options.
*/
createHistogram(name: string, options?: MetricOptions): Histogram;
createHistogram(name: string, options?: HistogramOptions): Histogram;

/**
* Creates a new `Counter` metric. Generally, this kind of metric when the
Expand All @@ -57,7 +60,7 @@ export interface Meter {
* @param name the name of the metric.
* @param [options] the metric options.
*/
createCounter(name: string, options?: MetricOptions): Counter;
createCounter(name: string, options?: CounterOptions): Counter;

/**
* Creates a new `UpDownCounter` metric. UpDownCounter is a synchronous
Expand All @@ -76,7 +79,7 @@ export interface Meter {
* @param name the name of the metric.
* @param [options] the metric options.
*/
createUpDownCounter(name: string, options?: MetricOptions): UpDownCounter;
createUpDownCounter(name: string, options?: UpDownCounterOptions): UpDownCounter;

/**
* Creates a new `ObservableGauge` metric.
Expand All @@ -86,7 +89,7 @@ export interface Meter {
*/
createObservableGauge(
name: string,
options?: MetricOptions,
options?: ObservableGaugeOptions,
callback?: (observableResult: ObservableResult) => void
): ObservableGauge;

Expand All @@ -98,7 +101,7 @@ export interface Meter {
*/
createObservableCounter(
name: string,
options?: MetricOptions,
options?: ObservableCounterOptions,
callback?: (observableResult: ObservableResult) => void
): ObservableCounter;

Expand All @@ -110,7 +113,7 @@ export interface Meter {
*/
createObservableUpDownCounter(
name: string,
options?: MetricOptions,
options?: ObservableUpDownCounterOptions,
callback?: (observableResult: ObservableResult) => void
): ObservableUpDownCounter;
}
50 changes: 15 additions & 35 deletions experimental/packages/opentelemetry-api-metrics/src/types/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { Context } from '@opentelemetry/api';
import {
Observation,
} from './Observation';
Expand All @@ -22,9 +23,6 @@ import {
* Options needed for metric creation
*/
export interface MetricOptions {
/** The name of the component that reports the Metric. */
component?: string;

/**
* The description of the Metric.
* @default ''
Expand All @@ -33,36 +31,18 @@ export interface MetricOptions {

/**
* The unit of the Metric values.
* @default '1'
* @default ''
*/
unit?: string;

/** The map of constant labels for the Metric. */
constantLabels?: Map<string, string>;

/**
* Indicates the metric is a verbose metric that is disabled by default
* @default false
*/
disabled?: boolean;

/**
* Indicates the type of the recorded value.
* @default {@link ValueType.DOUBLE}
*/
valueType?: ValueType;

/**
* Boundaries optional for histogram
*/
boundaries?: number[];

/**
* Aggregation Temporality of metric
*/
aggregationTemporality?: AggregationTemporality;
}

export type CounterOptions = MetricOptions;
export type UpDownCounterOptions = MetricOptions;
export type ObservableGaugeOptions = MetricOptions;
export type ObservableCounterOptions = MetricOptions;
export type ObservableUpDownCounterOptions = MetricOptions;
export type HistogramOptions = MetricOptions;

/** The Type of value. It describes how the data is reported. */
export enum ValueType {
INT,
Expand Down Expand Up @@ -93,23 +73,23 @@ export enum AggregationTemporality {
*/
export interface Counter {
/**
* Adds the given value to the current value. Values cannot be negative.
* Adds the given value to the current value. Values may not be negative.
*/
add(value: number, labels?: Labels): void;
add(value: number, labels?: Labels, context?: Context): void;
}

export interface UpDownCounter {
/**
* Adds the given value to the current value. Values can be negative.
* Adds the given value to the current value. Values may be negative.
*/
add(value: number, labels?: Labels): void;
add(value: number, labels?: Labels, context?: Context): void;
}

export interface Histogram {
/**
* Records the given value to this histogram.
* Records a measurement. Value of the measurement must not be negative.
*/
record(value: number, labels?: Labels): void;
record(measurement: number, labels?: Labels, context?: Context): void;
}

/** Base interface for the Observable metrics. */
Expand Down

0 comments on commit 4de7823

Please sign in to comment.