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 {