@@ -90,7 +90,7 @@ function addToMetricsAggregator(
90
90
* @experimental This API is experimental and might have breaking changes in the future.
91
91
*/
92
92
function 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 ) ;
94
94
}
95
95
96
96
/**
@@ -99,7 +99,7 @@ function increment(aggregator: MetricsAggregatorConstructor, name: string, value
99
99
* @experimental This API is experimental and might have breaking changes in the future.
100
100
*/
101
101
function 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 ) ;
103
103
}
104
104
105
105
/**
@@ -117,7 +117,7 @@ function set(aggregator: MetricsAggregatorConstructor, name: string, value: numb
117
117
* @experimental This API is experimental and might have breaking changes in the future.
118
118
*/
119
119
function 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 ) ;
121
121
}
122
122
123
123
export const metrics = {
@@ -130,3 +130,8 @@ export const metrics = {
130
130
*/
131
131
getMetricsAggregatorForClient,
132
132
} ;
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