Skip to content

Commit

Permalink
fix(resources): ensure BrowserDetector does not think Node.js v21 is …
Browse files Browse the repository at this point in the history
…a browser (#4604)

Fixes: #4561
  • Loading branch information
trentm committed Apr 4, 2024
1 parent b78d443 commit c046867
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit c046867

Please sign in to comment.