Skip to content

fix(instrumentation-fetch): use feature detection for browser environment#6200

Merged
overbalance merged 3 commits intoopen-telemetry:mainfrom
embrace-io:overbalance/fix-fetch-browser-detection
Dec 9, 2025
Merged

fix(instrumentation-fetch): use feature detection for browser environment#6200
overbalance merged 3 commits intoopen-telemetry:mainfrom
embrace-io:overbalance/fix-fetch-browser-detection

Conversation

@overbalance
Copy link
Copy Markdown
Contributor

@overbalance overbalance commented Dec 8, 2025

Which problem is this PR solving?

The current browser detection uses Node.js-specific checks (process.release?.name === 'node'), which doesn't account for other server-side runtimes like Deno and Bun that also have fetch(). This browser-only instrumentation shouldn't attempt to patch fetch in any server-side environment.

Short description of the changes

  • Replace Node.js detection with browser feature detection (typeof PerformanceObserver !== 'undefined')
  • Use named imports instead of namespace imports for @opentelemetry/api
  • Update warning message to be runtime-agnostic ("server-side fetch" instead of "Node.js's fetch")

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Existing browser tests cover this functionality. The feature detection approach checks for PerformanceObserver, which the instrumentation already depends on.

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@overbalance overbalance requested a review from a team as a code owner December 8, 2025 21:55
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.43%. Comparing base (6321f48) to head (88eb1f9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6200   +/-   ##
=======================================
  Coverage   95.43%   95.43%           
=======================================
  Files         317      317           
  Lines        9521     9521           
  Branches     2197     2197           
=======================================
  Hits         9086     9086           
  Misses        435      435           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@overbalance overbalance force-pushed the overbalance/fix-fetch-browser-detection branch from cd8b55a to 301a401 Compare December 8, 2025 21:59
@overbalance overbalance enabled auto-merge December 9, 2025 05:52
@overbalance overbalance disabled auto-merge December 9, 2025 09:37
@overbalance overbalance enabled auto-merge December 9, 2025 16:05
@overbalance overbalance added this pull request to the merge queue Dec 9, 2025
Merged via the queue into open-telemetry:main with commit eebdb2a Dec 9, 2025
27 checks passed
@overbalance overbalance deleted the overbalance/fix-fetch-browser-detection branch December 9, 2025 16:16
@otelbot-js otelbot-js Bot mentioned this pull request Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants