Skip to content

Commit 925f544

Browse files
authored
fix: telemetry warnings (#17186)
Fix A-27
2 parents f56fe7c + a85d128 commit 925f544

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

yarn-project/telemetry-client/src/nodejs_metrics_monitor.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Observable } from '@opentelemetry/api';
12
import { type EventLoopUtilization, type IntervalHistogram, monitorEventLoopDelay, performance } from 'node:perf_hooks';
23

34
import * as Attributes from './attributes.js';
@@ -142,17 +143,26 @@ export class NodejsMetricsMonitor {
142143
// - https://youtu.be/WetXnEPraYM
143144
obs.observe(this.eventLoopUilization, delta.utilization);
144145

145-
this.eventLoopTime.add(Math.floor(delta.idle), { [Attributes.NODEJS_EVENT_LOOP_STATE]: 'idle' });
146-
this.eventLoopTime.add(Math.floor(delta.active), { [Attributes.NODEJS_EVENT_LOOP_STATE]: 'active' });
146+
this.eventLoopTime.add(Math.trunc(delta.idle), { [Attributes.NODEJS_EVENT_LOOP_STATE]: 'idle' });
147+
this.eventLoopTime.add(Math.trunc(delta.active), { [Attributes.NODEJS_EVENT_LOOP_STATE]: 'active' });
147148

148-
obs.observe(this.eventLoopDelayGauges.min, Math.floor(this.eventLoopDelay.min));
149-
obs.observe(this.eventLoopDelayGauges.mean, Math.floor(this.eventLoopDelay.mean));
150-
obs.observe(this.eventLoopDelayGauges.max, Math.floor(this.eventLoopDelay.max));
151-
obs.observe(this.eventLoopDelayGauges.stddev, Math.floor(this.eventLoopDelay.stddev));
152-
obs.observe(this.eventLoopDelayGauges.p50, Math.floor(this.eventLoopDelay.percentile(50)));
153-
obs.observe(this.eventLoopDelayGauges.p90, Math.floor(this.eventLoopDelay.percentile(90)));
154-
obs.observe(this.eventLoopDelayGauges.p99, Math.floor(this.eventLoopDelay.percentile(99)));
149+
safeObserveInt(obs, this.eventLoopDelayGauges.min, this.eventLoopDelay.min);
150+
safeObserveInt(obs, this.eventLoopDelayGauges.mean, this.eventLoopDelay.mean);
151+
safeObserveInt(obs, this.eventLoopDelayGauges.max, this.eventLoopDelay.max);
152+
safeObserveInt(obs, this.eventLoopDelayGauges.stddev, this.eventLoopDelay.stddev);
153+
safeObserveInt(obs, this.eventLoopDelayGauges.p50, this.eventLoopDelay.percentile(50));
154+
safeObserveInt(obs, this.eventLoopDelayGauges.p90, this.eventLoopDelay.percentile(90));
155+
safeObserveInt(obs, this.eventLoopDelayGauges.p99, this.eventLoopDelay.percentile(99));
155156

156157
this.eventLoopDelay.reset();
157158
};
158159
}
160+
161+
function safeObserveInt(observer: BatchObservableResult, metric: Observable, value: number, attrs?: object) {
162+
// discard NaN, Infinity, -Infinity
163+
if (!Number.isFinite(value)) {
164+
return;
165+
}
166+
167+
observer.observe(metric, Math.trunc(value), attrs);
168+
}

0 commit comments

Comments
 (0)