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 30, 2021
1 parent 14afcc1 commit 47fde3a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 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 @@ -55,6 +55,9 @@
"publishConfig": {
"access": "public"
},
"dependencies": {
"@opentelemetry/api": "^1.0.0"
},
"devDependencies": {
"@types/mocha": "8.2.3",
"@types/node": "14.17.33",
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 @@ -87,7 +90,7 @@ export interface Meter {
createObservableGauge(
name: string,
callback: (observableResult: ObservableResult) => void,
options?: MetricOptions
options?: ObservableGaugeOptions
): ObservableGauge;

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

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

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

/**
* 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 @@ -29,36 +28,24 @@ export interface MetricOptions {

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

/** The map of constant attributes for the Metric. */
constantAttributes?: 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 @@ -91,21 +78,21 @@ export interface Counter {
/**
* Increment value of counter by the input. Inputs may not be negative.
*/
add(value: number, attributes?: Attributes): void;
add(value: number, attributes?: Attributes, context?: Context): void;
}

export interface UpDownCounter {
/**
* Increment value of counter by the input. Inputs may be negative.
*/
add(value: number, attributes?: Attributes): void;
add(value: number, attributes?: Attributes, 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, attributes?: Attributes): void;
record(value: number, attributes?: Attributes, context?: Context): void;
}

// ObservableBase has to be an Object but for now there is no field or method
Expand Down

0 comments on commit 47fde3a

Please sign in to comment.