Skip to content

Commit 555d168

Browse files
committed
fix: add UpDownCounterMetric.ts
1 parent 7d288b1 commit 555d168

File tree

4 files changed

+59
-43
lines changed

4 files changed

+59
-43
lines changed

packages/opentelemetry-metrics/src/Meter.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ import * as api from '@opentelemetry/api';
1818
import { ConsoleLogger } from '@opentelemetry/core';
1919
import { Resource } from '@opentelemetry/resources';
2020
import { BaseBoundInstrument } from './BoundInstrument';
21-
import {
22-
Metric,
23-
CounterMetric,
24-
ValueRecorderMetric,
25-
UpDownCounterMetric,
26-
ObserverMetric,
27-
} from './Metric';
21+
import { UpDownCounterMetric } from './UpDownCounterMetric';
22+
import { Metric, CounterMetric, ValueRecorderMetric, ObserverMetric } from './Metric';
2823
import {
2924
MetricOptions,
3025
DEFAULT_METRIC_OPTIONS,
@@ -230,4 +225,3 @@ export class Meter implements api.Meter {
230225
return Boolean(name.match(/^[a-z][a-z0-9_.-]*$/i));
231226
}
232227
}
233-
s

packages/opentelemetry-metrics/src/Metric.ts

+1-35
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import * as api from '@opentelemetry/api';
1818
import { Resource } from '@opentelemetry/resources';
1919
import {
2020
BoundCounter,
21-
BoundUpDownCounter,
2221
BaseBoundInstrument,
2322
BoundValueRecorder,
2423
BoundObserver,
@@ -135,40 +134,7 @@ export class CounterMetric extends Metric<BoundCounter> implements api.Counter {
135134
}
136135
}
137136

138-
/** This is a SDK implementation of UpDownCounter Metric. */
139-
export class UpDownCounterMetric extends Metric<BoundUpDownCounter>
140-
implements api.UpDownCounter {
141-
constructor(
142-
name: string,
143-
options: MetricOptions,
144-
private readonly _batcher: Batcher,
145-
resource: Resource
146-
) {
147-
super(name, options, MetricKind.UP_DOWN_COUNTER, resource);
148-
}
149-
protected _makeInstrument(labels: api.Labels): BoundUpDownCounter {
150-
return new BoundUpDownCounter(
151-
labels,
152-
this._disabled,
153-
this._valueType,
154-
this._logger,
155-
this._batcher.aggregatorFor(this._descriptor)
156-
);
157-
}
158-
159-
/**
160-
* Adds the given value to the current value. Values cannot be negative.
161-
* @param value the value to add.
162-
* @param [labels = {}] key-values pairs that are associated with a specific
163-
* metric that you want to record.
164-
*/
165-
add(value: number, labels: api.Labels = {}) {
166-
this.bind(labels).add(value);
167-
}
168-
}
169-
170-
export class ValueRecorderMetric extends Metric<BoundValueRecorder>
171-
implements api.ValueRecorder {
137+
export class MeasureMetric extends Metric<BoundMeasure> implements api.Measure {
172138
protected readonly _absolute: boolean;
173139

174140
constructor(
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 * as api from '@opentelemetry/api';
18+
import { Resource } from '@opentelemetry/resources';
19+
import { BoundUpDownCounter } from './BoundInstrument';
20+
import { MetricOptions } from './types';
21+
import { MetricKind } from './export/types';
22+
import { Batcher } from './export/Batcher';
23+
import { Metric } from './Metric';
24+
25+
/** This is a SDK implementation of UpDownCounter Metric. */
26+
export class UpDownCounterMetric extends Metric<BoundUpDownCounter>
27+
implements api.UpDownCounter {
28+
constructor(
29+
name: string,
30+
options: MetricOptions,
31+
private readonly _batcher: Batcher,
32+
resource: Resource
33+
) {
34+
super(name, options, MetricKind.UP_DOWN_COUNTER, resource);
35+
}
36+
protected _makeInstrument(labels: api.Labels): BoundUpDownCounter {
37+
return new BoundUpDownCounter(
38+
labels,
39+
this._disabled,
40+
this._valueType,
41+
this._logger,
42+
this._batcher.aggregatorFor(this._descriptor)
43+
);
44+
}
45+
46+
/**
47+
* Adds the given value to the current value. Values cannot be negative.
48+
* @param value the value to add.
49+
* @param [labels = {}] key-values pairs that are associated with a specific
50+
* metric that you want to record.
51+
*/
52+
add(value: number, labels: api.Labels = {}) {
53+
this.bind(labels).add(value);
54+
}
55+
}

packages/opentelemetry-metrics/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export * from './MetricObservable';
2222
export * from './export/aggregators';
2323
export * from './export/ConsoleMetricExporter';
2424
export * from './export/types';
25+
export * from './UpDownCounterMetric';

0 commit comments

Comments
 (0)