Skip to content

feat(browser otlp exporter): add fetch transport for fetch-only environments #5807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

SacDeNoeuds
Copy link

@SacDeNoeuds SacDeNoeuds commented Jul 22, 2025

Which problem is this PR solving?

In service workers, XMLHttpRequest and navigator.sendBeacon are both unavailable, making the OTLPTraceExporter from @opentelemetry/exporter-trace-otlp-http unusable.

Fixes #4631

Short description of the changes

Add the fetch transport and enables it only when both xhr and beacons are unavailable.

Type of change

Please delete options that are not relevant.

  • 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?

I took the xhr transport tests and adapted the arrange step for the fetch transport.
See the test file: experimental/packages/otlp-exporter-base/test/browser/fetch-transport.test.ts

Checklist:

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

Additional context

@SacDeNoeuds SacDeNoeuds requested a review from a team as a code owner July 22, 2025 07:18
Copy link

linux-foundation-easycla bot commented Jul 22, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@SacDeNoeuds SacDeNoeuds changed the title feat(browser otlp exporter): add fetch transport if xhr and beacon are unavailable feat(browser otlp exporter): add fetch transport for fetch-only environments Jul 22, 2025
@SacDeNoeuds SacDeNoeuds force-pushed the feat/otlp-exporter--base-fetch-transport branch from 2c4a8b6 to e3cd53a Compare July 22, 2025 08:28
Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me and I don't see any obvious issues. I'd wait for @pichlermarc review before merging because he's much closer to the exporters but overall LGTM

Copy link

codecov bot commented Jul 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.01%. Comparing base (d63dfae) to head (b722a83).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5807   +/-   ##
=======================================
  Coverage   95.01%   95.01%           
=======================================
  Files         303      303           
  Lines        7946     7946           
  Branches     1607     1607           
=======================================
  Hits         7550     7550           
  Misses        396      396           
🚀 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.

: 'cors'
: 'no-cors',
});
clearTimeout(timeout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's possible you won't clear the timeout if something in the try block throws. Consider moving this to a finally block?

Copy link
Author

@SacDeNoeuds SacDeNoeuds Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review, I made the change. Let me know if I can do anything more.

@SacDeNoeuds
Copy link
Author

Hi guys, any news on this?

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.

TraceExporter for fetch-only environment
3 participants