From 468b8a1c8ab35c389a40675ba3035e874a322c97 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 4 Apr 2024 15:24:53 -0700 Subject: [PATCH] fix(resources): ensure BrowserDetector does not think Node.js v21 is a browser (#4604) Fixes: #4561 --- CHANGELOG.md | 1 + .../src/detectors/BrowserDetectorSync.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index becf83bc68..0c3d6bfe7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :bug: (Bug Fix) * fix(sdk-trace-web): fix invalid timings in span events [#4486](https://github.com/open-telemetry/opentelemetry-js/pull/4486) @Abinet18 +* fix(resources): ensure BrowserDetector does not think Node.js v21 is a browser [#4561](https://github.com/open-telemetry/opentelemetry-js/issues/4561) @trentm ### :books: (Refine Doc) diff --git a/packages/opentelemetry-resources/src/detectors/BrowserDetectorSync.ts b/packages/opentelemetry-resources/src/detectors/BrowserDetectorSync.ts index b58fea94c8..66a4801067 100644 --- a/packages/opentelemetry-resources/src/detectors/BrowserDetectorSync.ts +++ b/packages/opentelemetry-resources/src/detectors/BrowserDetectorSync.ts @@ -24,7 +24,12 @@ import { diag } from '@opentelemetry/api'; */ class BrowserDetectorSync implements DetectorSync { detect(config?: ResourceDetectionConfig): IResource { - const isBrowser = typeof navigator !== 'undefined'; + const isBrowser = + typeof navigator !== 'undefined' && + global.process?.versions?.node === undefined && // Node.js v21 adds `navigator` + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore don't have Bun types + global.Bun?.version === undefined; // Bun (bun.sh) defines `navigator` if (!isBrowser) { return Resource.empty(); }