From 9bef4bf40944b1743185afc4466b77bdd2de13a2 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Tue, 22 Oct 2019 17:31:27 -0700 Subject: [PATCH] fix: avoid casting --- packages/opentelemetry-metrics/src/Handle.ts | 2 +- packages/opentelemetry-metrics/src/Meter.ts | 12 ++++++++++-- packages/opentelemetry-metrics/src/Metric.ts | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/opentelemetry-metrics/src/Handle.ts b/packages/opentelemetry-metrics/src/Handle.ts index 88a39245d0f..5d55ebbe08b 100644 --- a/packages/opentelemetry-metrics/src/Handle.ts +++ b/packages/opentelemetry-metrics/src/Handle.ts @@ -98,7 +98,7 @@ export class GaugeHandle extends BaseHandle implements types.GaugeHandle { /** * MeasureHandle is an implementation of the {@link MeasureHandle} interface. */ -export class MeasureHandle implements types.MeasureHandle { +export class MeasureHandle extends BaseHandle implements types.MeasureHandle { record( value: number, distContext?: types.DistributedContext, diff --git a/packages/opentelemetry-metrics/src/Meter.ts b/packages/opentelemetry-metrics/src/Meter.ts index abeb5649505..af48f68df8c 100644 --- a/packages/opentelemetry-metrics/src/Meter.ts +++ b/packages/opentelemetry-metrics/src/Meter.ts @@ -16,7 +16,12 @@ import * as types from '@opentelemetry/types'; import { ConsoleLogger } from '@opentelemetry/core'; -import { CounterHandle, GaugeHandle, MeasureHandle } from './Handle'; +import { + CounterHandle, + GaugeHandle, + MeasureHandle, + BaseHandle, +} from './Handle'; import { Metric, CounterMetric, GaugeMetric } from './Metric'; import { MetricOptions, @@ -115,7 +120,10 @@ export class Meter implements types.Meter { * @param name The name of the metric. * @param metric The metric to register. */ - private _registerMetric(name: string, metric: Metric): void { + private _registerMetric( + name: string, + metric: Metric + ): void { if (this._metrics.has(name)) { throw new Error( `A metric with the name ${name} has already been registered.` diff --git a/packages/opentelemetry-metrics/src/Metric.ts b/packages/opentelemetry-metrics/src/Metric.ts index a20931631dc..d9ade423202 100644 --- a/packages/opentelemetry-metrics/src/Metric.ts +++ b/packages/opentelemetry-metrics/src/Metric.ts @@ -26,7 +26,7 @@ import { } from './export/types'; /** This is a SDK implementation of {@link Metric} interface. */ -export abstract class Metric implements types.Metric { +export abstract class Metric implements types.Metric { protected readonly _monotonic: boolean; protected readonly _disabled: boolean; protected readonly _logger: types.Logger; @@ -100,7 +100,7 @@ export abstract class Metric implements types.Metric { return { descriptor: this._metricDescriptor, timeseries: Array.from(this._handles, ([_, handle]) => - ((handle as unknown) as BaseHandle).getTimeSeries(timestamp) + handle.getTimeSeries(timestamp) ), }; }