Skip to content

Commit

Permalink
fix: avoid casting
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 committed Oct 24, 2019
1 parent caef7ac commit bc0fcda
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/opentelemetry-metrics/src/Handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions packages/opentelemetry-metrics/src/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<T>(name: string, metric: Metric<T>): void {
private _registerMetric<T extends BaseHandle>(
name: string,
metric: Metric<T>
): void {
if (this._metrics.has(name)) {
throw new Error(
`A metric with the name ${name} has already been registered.`
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-metrics/src/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from './export/types';

/** This is a SDK implementation of {@link Metric} interface. */
export abstract class Metric<T> implements types.Metric<T> {
export abstract class Metric<T extends BaseHandle> implements types.Metric<T> {
protected readonly _monotonic: boolean;
protected readonly _disabled: boolean;
protected readonly _logger: types.Logger;
Expand Down Expand Up @@ -100,7 +100,7 @@ export abstract class Metric<T> implements types.Metric<T> {
return {
descriptor: this._metricDescriptor,
timeseries: Array.from(this._handles, ([_, handle]) =>
((handle as unknown) as BaseHandle).getTimeSeries(timestamp)
handle.getTimeSeries(timestamp)
),
};
}
Expand Down

0 comments on commit bc0fcda

Please sign in to comment.