From 1e29d9dfc9afc00e7774a31838f995a8837c1c24 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Thu, 4 Jun 2020 17:50:04 -0700 Subject: [PATCH] fix: add UpDownCounterMetric.ts --- packages/opentelemetry-metrics/src/Meter.ts | 9 +-- packages/opentelemetry-metrics/src/Metric.ts | 33 ----------- .../src/UpDownCounterMetric.ts | 55 +++++++++++++++++++ packages/opentelemetry-metrics/src/index.ts | 1 + 4 files changed, 58 insertions(+), 40 deletions(-) create mode 100644 packages/opentelemetry-metrics/src/UpDownCounterMetric.ts diff --git a/packages/opentelemetry-metrics/src/Meter.ts b/packages/opentelemetry-metrics/src/Meter.ts index 2ac79b0a15d..d55c1955b8d 100644 --- a/packages/opentelemetry-metrics/src/Meter.ts +++ b/packages/opentelemetry-metrics/src/Meter.ts @@ -18,13 +18,8 @@ import * as api from '@opentelemetry/api'; import { ConsoleLogger } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; import { BaseBoundInstrument } from './BoundInstrument'; -import { - Metric, - CounterMetric, - UpDownCounterMetric, - MeasureMetric, - ObserverMetric, -} from './Metric'; +import { UpDownCounterMetric } from './UpDownCounterMetric'; +import { Metric, CounterMetric, MeasureMetric, ObserverMetric } from './Metric'; import { MetricOptions, DEFAULT_METRIC_OPTIONS, diff --git a/packages/opentelemetry-metrics/src/Metric.ts b/packages/opentelemetry-metrics/src/Metric.ts index 1564927ea1c..03a4ce0dd61 100644 --- a/packages/opentelemetry-metrics/src/Metric.ts +++ b/packages/opentelemetry-metrics/src/Metric.ts @@ -18,7 +18,6 @@ import * as api from '@opentelemetry/api'; import { Resource } from '@opentelemetry/resources'; import { BoundCounter, - BoundUpDownCounter, BaseBoundInstrument, BoundMeasure, BoundObserver, @@ -136,38 +135,6 @@ export class CounterMetric extends Metric implements api.Counter { } } -/** This is a SDK implementation of UpDownCounter Metric. */ -export class UpDownCounterMetric extends Metric - implements api.UpDownCounter { - constructor( - name: string, - options: MetricOptions, - private readonly _batcher: Batcher, - resource: Resource - ) { - super(name, options, MetricKind.UP_DOWN_COUNTER, resource); - } - protected _makeInstrument(labels: api.Labels): BoundUpDownCounter { - return new BoundUpDownCounter( - labels, - this._disabled, - this._valueType, - this._logger, - this._batcher.aggregatorFor(this._descriptor) - ); - } - - /** - * Adds the given value to the current value. Values cannot be negative. - * @param value the value to add. - * @param [labels = {}] key-values pairs that are associated with a specific - * metric that you want to record. - */ - add(value: number, labels: api.Labels = {}) { - this.bind(labels).add(value); - } -} - export class MeasureMetric extends Metric implements api.Measure { protected readonly _absolute: boolean; diff --git a/packages/opentelemetry-metrics/src/UpDownCounterMetric.ts b/packages/opentelemetry-metrics/src/UpDownCounterMetric.ts new file mode 100644 index 00000000000..03a4b1c2770 --- /dev/null +++ b/packages/opentelemetry-metrics/src/UpDownCounterMetric.ts @@ -0,0 +1,55 @@ +/*! + * Copyright 2019, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as api from '@opentelemetry/api'; +import { Resource } from '@opentelemetry/resources'; +import { BoundUpDownCounter } from './BoundInstrument'; +import { MetricOptions } from './types'; +import { MetricKind } from './export/types'; +import { Batcher } from './export/Batcher'; +import { Metric } from './Metric'; + +/** This is a SDK implementation of UpDownCounter Metric. */ +export class UpDownCounterMetric extends Metric + implements api.UpDownCounter { + constructor( + name: string, + options: MetricOptions, + private readonly _batcher: Batcher, + resource: Resource + ) { + super(name, options, MetricKind.UP_DOWN_COUNTER, resource); + } + protected _makeInstrument(labels: api.Labels): BoundUpDownCounter { + return new BoundUpDownCounter( + labels, + this._disabled, + this._valueType, + this._logger, + this._batcher.aggregatorFor(this._descriptor) + ); + } + + /** + * Adds the given value to the current value. Values cannot be negative. + * @param value the value to add. + * @param [labels = {}] key-values pairs that are associated with a specific + * metric that you want to record. + */ + add(value: number, labels: api.Labels = {}) { + this.bind(labels).add(value); + } +} diff --git a/packages/opentelemetry-metrics/src/index.ts b/packages/opentelemetry-metrics/src/index.ts index 6cb01ff9a88..bc2cce8475b 100644 --- a/packages/opentelemetry-metrics/src/index.ts +++ b/packages/opentelemetry-metrics/src/index.ts @@ -22,3 +22,4 @@ export * from './MetricObservable'; export * from './export/aggregators'; export * from './export/ConsoleMetricExporter'; export * from './export/types'; +export * from './UpDownCounterMetric';