Skip to content

Commit d046310

Browse files
committed
fix(sdk-metrics): ignore in accumulation instead
1 parent 185515b commit d046310

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

packages/sdk-metrics/src/Instruments.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ export class SyncInstrument {
5454
);
5555
return;
5656
}
57-
if (Number.isNaN(value)) {
58-
diag.warn(
59-
`NaN provided to metric ${this._descriptor.name}, ignoring to preserve the integrity of the metrics stream`
60-
);
61-
return;
62-
}
6357
if (
6458
this._descriptor.valueType === ValueType.INT &&
6559
!Number.isInteger(value)

packages/sdk-metrics/src/aggregator/ExponentialHistogram.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ export class ExponentialHistogramAccumulation implements Accumulation {
193193
* @param increment
194194
*/
195195
updateByIncrement(value: number, increment: number) {
196+
// NaN does not fall into any bucket, is not zero and should not be counted,
197+
// NaN is never greater than max nor less than min, therefore return as there's nothing for us to do.
198+
if (Number.isNaN(value)) {
199+
return;
200+
}
201+
196202
if (value > this._max) {
197203
this._max = value;
198204
}

packages/sdk-metrics/src/aggregator/Histogram.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ export class HistogramAccumulation implements Accumulation {
7272
) {}
7373

7474
record(value: number): void {
75+
// NaN does not fall into any bucket, is not zero and should not be counted,
76+
// NaN is never greater than max nor less than min, therefore return as there's nothing for us to do.
77+
if (Number.isNaN(value)) {
78+
return;
79+
}
80+
7581
this._current.count += 1;
7682
this._current.sum += value;
7783

packages/sdk-metrics/test/Instruments.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ describe('Instruments', () => {
135135
counter.add(1.2, { foo: 'bar' });
136136
// non-number values should be ignored.
137137
counter.add('1' as any);
138-
counter.add(NaN);
139138

140139
await validateExport(cumulativeReader, {
141140
dataPointType: DataPointType.SUM,
@@ -248,7 +247,6 @@ describe('Instruments', () => {
248247
upDownCounter.add(1.1, { foo: 'bar' });
249248
// non-number values should be ignored.
250249
upDownCounter.add('1' as any);
251-
upDownCounter.add(NaN);
252250

253251
await validateExport(deltaReader, {
254252
dataPointType: DataPointType.SUM,

0 commit comments

Comments
 (0)