Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions yarn-project/telemetry-client/src/nodejs_metrics_monitor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Observable } from '@opentelemetry/api';
import { type EventLoopUtilization, type IntervalHistogram, monitorEventLoopDelay, performance } from 'node:perf_hooks';

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

this.eventLoopTime.add(Math.floor(delta.idle), { [Attributes.NODEJS_EVENT_LOOP_STATE]: 'idle' });
this.eventLoopTime.add(Math.floor(delta.active), { [Attributes.NODEJS_EVENT_LOOP_STATE]: 'active' });
this.eventLoopTime.add(Math.trunc(delta.idle), { [Attributes.NODEJS_EVENT_LOOP_STATE]: 'idle' });
this.eventLoopTime.add(Math.trunc(delta.active), { [Attributes.NODEJS_EVENT_LOOP_STATE]: 'active' });

obs.observe(this.eventLoopDelayGauges.min, Math.floor(this.eventLoopDelay.min));
obs.observe(this.eventLoopDelayGauges.mean, Math.floor(this.eventLoopDelay.mean));
obs.observe(this.eventLoopDelayGauges.max, Math.floor(this.eventLoopDelay.max));
obs.observe(this.eventLoopDelayGauges.stddev, Math.floor(this.eventLoopDelay.stddev));
obs.observe(this.eventLoopDelayGauges.p50, Math.floor(this.eventLoopDelay.percentile(50)));
obs.observe(this.eventLoopDelayGauges.p90, Math.floor(this.eventLoopDelay.percentile(90)));
obs.observe(this.eventLoopDelayGauges.p99, Math.floor(this.eventLoopDelay.percentile(99)));
safeObserveInt(obs, this.eventLoopDelayGauges.min, this.eventLoopDelay.min);
safeObserveInt(obs, this.eventLoopDelayGauges.mean, this.eventLoopDelay.mean);
safeObserveInt(obs, this.eventLoopDelayGauges.max, this.eventLoopDelay.max);
safeObserveInt(obs, this.eventLoopDelayGauges.stddev, this.eventLoopDelay.stddev);
safeObserveInt(obs, this.eventLoopDelayGauges.p50, this.eventLoopDelay.percentile(50));
safeObserveInt(obs, this.eventLoopDelayGauges.p90, this.eventLoopDelay.percentile(90));
safeObserveInt(obs, this.eventLoopDelayGauges.p99, this.eventLoopDelay.percentile(99));

this.eventLoopDelay.reset();
};
}

function safeObserveInt(observer: BatchObservableResult, metric: Observable, value: number, attrs?: object) {
// discard NaN, Infinity, -Infinity
if (!Number.isFinite(value)) {
return;
}

observer.observe(metric, Math.trunc(value), attrs);
}
Loading