Skip to content

Commit 43ea6f7

Browse files
wittachai-asclaude
andcommitted
ref(node): Remove two Node <20 leftovers (hrtime.bigint, undici channel refs)
Both were guarded by a condition that has since passed: the engine floor moved to Node >=20.19.0 in 4f03438. - anr/worker.ts: `createHrTimer()` now uses `process.hrtime.bigint()`; the TODO asking for it was conditioned on dropping Node 8. - node-fetch/undici-instrumentation.ts: `_channelSubs` only existed to keep a reference alive around nodejs/node#42170, which needed Node 18.18.0 support. Replaced with the `_isInstrumented` boolean its own comment proposed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JGK2ap3HHAy2WuDwoS8yTW
1 parent 59496e0 commit 43ea6f7

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

‎packages/node/src/integrations/anr/worker.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,14 @@ if (options.captureStackTrace) {
286286
}
287287

288288
function createHrTimer(): { getTimeMs: () => number; reset: VoidFunction } {
289-
// TODO (v8): We can use process.hrtime.bigint() after we drop node v8
290-
let lastPoll = process.hrtime();
289+
let lastPoll = process.hrtime.bigint();
291290

292291
return {
293292
getTimeMs: (): number => {
294-
const [seconds, nanoSeconds] = process.hrtime(lastPoll);
295-
return Math.floor(seconds * 1e3 + nanoSeconds / 1e6);
293+
return Number((process.hrtime.bigint() - lastPoll) / 1_000_000n);
296294
},
297295
reset: (): void => {
298-
lastPoll = process.hrtime();
296+
lastPoll = process.hrtime.bigint();
299297
},
300298
};
301299
}

‎packages/node/src/integrations/node-fetch/undici-instrumentation.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ import type {
7474
// `http.request.method_original` is not part of `@sentry/conventions`, so we keep it inline.
7575
const ATTR_HTTP_REQUEST_METHOD_ORIGINAL = 'http.request.method_original';
7676

77-
// Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug
78-
// We can replace this with _isInstrumented once we drop support for Node.js 18.18.0
79-
const _channelSubs: Array<unknown> = [];
77+
let _isInstrumented = false;
8078
const spanFromReq = new WeakMap<UndiciRequest, Span>();
8179
// Whether breadcrumbs (and span-less trace propagation) should be skipped for a given request.
8280
// We evaluate this at request-creation time because the active context is no longer correct by the
@@ -101,9 +99,10 @@ const propagationDecisionMap = new LRUMap<string, boolean>(100);
10199
*/
102100
export function instrumentUndici(config: NodeFetchOptions = {}): void {
103101
// Avoid duplicate subscriptions
104-
if (_channelSubs.length) {
102+
if (_isInstrumented) {
105103
return;
106104
}
105+
_isInstrumented = true;
107106

108107
subscribeToChannel('undici:request:create', message => onRequestCreated(config, message as RequestMessage));
109108
subscribeToChannel('undici:client:sendHeaders', message =>
@@ -118,7 +117,7 @@ function subscribeToChannel(
118117
diagnosticChannel: string,
119118
onMessage: (message: unknown, name: string | symbol) => void,
120119
): void {
121-
_channelSubs.push(diagch.subscribe?.(diagnosticChannel, onMessage));
120+
diagch.subscribe?.(diagnosticChannel, onMessage);
122121
}
123122

124123
function parseRequestHeaders(request: UndiciRequest): Map<string, string | string[]> {

0 commit comments

Comments
 (0)