Skip to content

Commit 50047b3

Browse files
bg451mayurkale22
authored andcommitted
Adds Metrics API (open-telemetry#105)
* Adds Metrics API https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/metrics-api.md adds gauge and counter types checkpoint checkpoint update docs update index.ts move todo * yarn check
1 parent c96dadf commit 50047b3

File tree

6 files changed

+207
-0
lines changed

6 files changed

+207
-0
lines changed

packages/opentelemetry-types/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export * from './context/propagation/BinaryFormat';
1919
export * from './context/propagation/HttpTextFormat';
2020
export * from './distributed_context/DistributedContext';
2121
export * from './distributed_context/EntryValue';
22+
export * from './metrics/counter';
23+
export * from './metrics/gauge';
24+
export * from './metrics/measure';
25+
export * from './metrics/meter';
26+
export * from './metrics/metrics';
2227
export * from './resources/Resource';
2328
export * from './trace/attributes';
2429
export * from './trace/Event';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2019, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export interface CounterTimeseries {
18+
// Adds the given value to the current value. Values cannot be negative.
19+
add(value: number): void;
20+
21+
// Sets the given value. Value must be larger than the current recorded value.
22+
set(value: number): void;
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2019, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export interface GaugeTimeseries {
18+
// Adds the given value to the current value. Values can be negative.
19+
add(value: number): void;
20+
// Sets the given value. Values can be negative.
21+
set(value: number): void;
22+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2019, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export enum MeasureType {
18+
DOUBLE = 0,
19+
LONG = 1,
20+
}
21+
22+
export interface MeasureOptions {
23+
// Description of the Measure.
24+
description?: string;
25+
26+
// Unit of the Measure.
27+
unit?: string;
28+
29+
// Type of the Measure. Default type is DOUBLE.
30+
type?: MeasureType;
31+
}
32+
33+
export interface Measure {
34+
// Creates a measurement with the supplied value.
35+
createMeasurement(value: number): Measurement;
36+
}
37+
38+
// Measurement describes an individual measurement
39+
export interface Measurement {}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright 2019, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { SpanContext } from '../trace/span_context';
18+
import { DistributedContext } from '../distributed_context/DistributedContext';
19+
import { Measure, MeasureOptions, Measurement } from './measure';
20+
import { Metric, MetricOptions } from './metric';
21+
import { CounterTimeseries } from './counter';
22+
import { GaugeTimeseries } from './gauge';
23+
24+
export interface RecordOptions {
25+
// spanContext represents a measurement exemplar in the form of a SpanContext.
26+
spanContext?: SpanContext;
27+
// distributedContext overrides the current context and adds dimensions
28+
// to the measurements.
29+
distributedContext?: DistributedContext;
30+
}
31+
32+
export interface Meter {
33+
// Creates and returns a new @link{Measure}.
34+
createMeasure(name: string, options?: MeasureOptions): Measure;
35+
36+
// Creates a new counter metric.
37+
createCounter(
38+
name: string,
39+
options?: MetricOptions
40+
): Metric<CounterTimeseries>;
41+
42+
// TODO: Measurements can have a long or double type. However, it looks like
43+
// the metric timeseries API (according to spec) accepts values instead of
44+
// Measurements, meaning that if you accept a `number`, the type gets lost.
45+
// Both java and csharp have gone down the route of having two gauge interfaces,
46+
// GaugeDoubleTimeseries and GaugeLongTimeseries, with param for that type. It'd
47+
// be cool to only have a single interface, but maybe having two is necessary?
48+
// Maybe include the type as a metrics option? Probs a good gh issue, the same goes for Measure types.
49+
50+
// Creates a new gauge metric.
51+
createGauge(name: string, options?: MetricOptions): Metric<GaugeTimeseries>;
52+
53+
// Record a set of raw measurements.
54+
record(measurements: Measurement[], options?: RecordOptions): void;
55+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright 2019, OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { Attributes } from '../trace/attributes';
18+
import { Resource } from '../resources/Resource';
19+
20+
export interface MetricOptions {
21+
// Description of the Metric.
22+
description?: string;
23+
24+
// Unit of the Metric values.
25+
unit?: string;
26+
27+
// List of attribute keys with dynamic values. Order of list is important
28+
// as the same order must be used when supplying values for these attributes.
29+
dynamicAttributes?: string[];
30+
31+
// List of attributes with constant values.
32+
constantAttributes?: Attributes;
33+
34+
// Resource the metric is associated with.
35+
resource?: Resource;
36+
37+
// Name of the component that reports the metric.
38+
component?: string;
39+
}
40+
41+
// Metric represents a base class for different types of metric preaggregations.
42+
export interface Metric<T> {
43+
// Creates a timeseries if the specified attribute values
44+
// are not associated with an existing timeseries, otherwise returns the
45+
// existing timeseries.
46+
// Order and number of attribute values MUST match the order and number of
47+
// dynanic attribute keys when the Metric was created.
48+
getOrCreateTimeseries(values: unknown[]): T;
49+
50+
// Returns a timeseries with all attribute values not set.
51+
getDefaultTimeseries(): T;
52+
53+
// Removes an existing timeseries. Order and number of attribute values MUST
54+
// match the order and number of dynamic attribute keys when the Metric was
55+
// created.
56+
removesTimeseries(values: unknown[]): void;
57+
58+
// Clears all timeseries from the Metric.
59+
clear(): void;
60+
61+
// todo: what should the callback signature be?
62+
setCallback(fn: () => void): void;
63+
}

0 commit comments

Comments
 (0)