From 43ea6f76293d3e9e35849b06ef3de1fabafa48aa Mon Sep 17 00:00:00 2001 From: wittachai-as Date: Mon, 7 Sep 2026 21:12:14 +0700 Subject: [PATCH] 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 4f0343802. - 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) Claude-Session: https://claude.ai/code/session_01JGK2ap3HHAy2WuDwoS8yTW --- packages/node/src/integrations/anr/worker.ts | 8 +++----- .../integrations/node-fetch/undici-instrumentation.ts | 9 ++++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/node/src/integrations/anr/worker.ts b/packages/node/src/integrations/anr/worker.ts index fa6054c850e6..abafa78aaaae 100644 --- a/packages/node/src/integrations/anr/worker.ts +++ b/packages/node/src/integrations/anr/worker.ts @@ -286,16 +286,14 @@ if (options.captureStackTrace) { } function createHrTimer(): { getTimeMs: () => number; reset: VoidFunction } { - // TODO (v8): We can use process.hrtime.bigint() after we drop node v8 - let lastPoll = process.hrtime(); + let lastPoll = process.hrtime.bigint(); return { getTimeMs: (): number => { - const [seconds, nanoSeconds] = process.hrtime(lastPoll); - return Math.floor(seconds * 1e3 + nanoSeconds / 1e6); + return Number((process.hrtime.bigint() - lastPoll) / 1_000_000n); }, reset: (): void => { - lastPoll = process.hrtime(); + lastPoll = process.hrtime.bigint(); }, }; } diff --git a/packages/node/src/integrations/node-fetch/undici-instrumentation.ts b/packages/node/src/integrations/node-fetch/undici-instrumentation.ts index b2989e6c6bdf..62fc4992ef4f 100644 --- a/packages/node/src/integrations/node-fetch/undici-instrumentation.ts +++ b/packages/node/src/integrations/node-fetch/undici-instrumentation.ts @@ -74,9 +74,7 @@ import type { // `http.request.method_original` is not part of `@sentry/conventions`, so we keep it inline. const ATTR_HTTP_REQUEST_METHOD_ORIGINAL = 'http.request.method_original'; -// Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug -// We can replace this with _isInstrumented once we drop support for Node.js 18.18.0 -const _channelSubs: Array = []; +let _isInstrumented = false; const spanFromReq = new WeakMap(); // Whether breadcrumbs (and span-less trace propagation) should be skipped for a given request. // 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(100); */ export function instrumentUndici(config: NodeFetchOptions = {}): void { // Avoid duplicate subscriptions - if (_channelSubs.length) { + if (_isInstrumented) { return; } + _isInstrumented = true; subscribeToChannel('undici:request:create', message => onRequestCreated(config, message as RequestMessage)); subscribeToChannel('undici:client:sendHeaders', message => @@ -118,7 +117,7 @@ function subscribeToChannel( diagnosticChannel: string, onMessage: (message: unknown, name: string | symbol) => void, ): void { - _channelSubs.push(diagch.subscribe?.(diagnosticChannel, onMessage)); + diagch.subscribe?.(diagnosticChannel, onMessage); } function parseRequestHeaders(request: UndiciRequest): Map {