From 11ae37cfc6d9d15174dae7d1c628670642ef9133 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 3 Apr 2024 15:09:06 -0700 Subject: [PATCH] fix(resources): ensure BrowserDetector does not think Node.js v21 is a browser 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..dec691ee08 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' && + 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 + Bun?.version === undefined; // Bun (bun.sh) defines `navigator` if (!isBrowser) { return Resource.empty(); }