@@ -90,7 +90,7 @@ function addToMetricsAggregator(
9090 * @experimental This API is experimental and might have breaking changes in the future.
9191 */
9292function increment ( aggregator : MetricsAggregatorConstructor , name : string , value : number = 1 , data ?: MetricData ) : void {
93- addToMetricsAggregator ( aggregator , COUNTER_METRIC_TYPE , name , value , data ) ;
93+ addToMetricsAggregator ( aggregator , COUNTER_METRIC_TYPE , name , ensureNumber ( value ) , data ) ;
9494}
9595
9696/**
@@ -99,7 +99,7 @@ function increment(aggregator: MetricsAggregatorConstructor, name: string, value
9999 * @experimental This API is experimental and might have breaking changes in the future.
100100 */
101101function distribution ( aggregator : MetricsAggregatorConstructor , name : string , value : number , data ?: MetricData ) : void {
102- addToMetricsAggregator ( aggregator , DISTRIBUTION_METRIC_TYPE , name , value , data ) ;
102+ addToMetricsAggregator ( aggregator , DISTRIBUTION_METRIC_TYPE , name , ensureNumber ( value ) , data ) ;
103103}
104104
105105/**
@@ -117,7 +117,7 @@ function set(aggregator: MetricsAggregatorConstructor, name: string, value: numb
117117 * @experimental This API is experimental and might have breaking changes in the future.
118118 */
119119function gauge ( aggregator : MetricsAggregatorConstructor , name : string , value : number , data ?: MetricData ) : void {
120- addToMetricsAggregator ( aggregator , GAUGE_METRIC_TYPE , name , value , data ) ;
120+ addToMetricsAggregator ( aggregator , GAUGE_METRIC_TYPE , name , ensureNumber ( value ) , data ) ;
121121}
122122
123123export const metrics = {
@@ -130,3 +130,8 @@ export const metrics = {
130130 */
131131 getMetricsAggregatorForClient,
132132} ;
133+
134+ // Although this is typed to be a number, we try to handle strings as well here
135+ function ensureNumber ( number : number | string ) : number {
136+ return typeof number === 'string' ? parseInt ( number ) : number ;
137+ }
0 commit comments