Skip to content

Conversation

@YangJonghun
Copy link
Contributor

Which problem is this PR solving?

Browser environments have a 64KiB limit for sendBeacon and fetch with keepalive: true. When the request exceeds this limit:

  • sendBeacon returns false
  • fetch with keepalive may fail silently in some browsers (Firefox) or throw an error (Chrome)

This causes telemetry data loss for larger batches without any fallback mechanism.

Related #3489

Short description of the changes

  1. FailoverTransport: New transport that switches to a failover transport when the primary transport fails
  2. FetchTransport: Disable keepalive for body size >= 60KiB (leaving room for headers)
  3. SendBeacon delegate: Use FailoverTransport to fall back to fetch when sendBeacon fails
  4. Test fixes: Fix sendBeacon stub to return true in existing tests

⚠️ Note

The size-based approach for fetch transport is not a perfect solution since we cannot know the exact final request size (headers, encoding overhead, etc.). However, this change:

  • Automatically resolves most issues caused by keepalive being unconditionally set to true in browser environments
  • Introduces minimal changes to existing behavior
  • Provides a reasonable safety margin (60KiB body limit vs 64KiB total limit)

For sendBeacon, the FailoverTransport provides a more robust solution since sendBeacon explicitly returns false when the request cannot be queued.

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)

How Has This Been Tested?

  • Unit tests for FailoverTransport (success, failure, retryable, reject cases)
  • Unit tests for FetchTransport keepalive limit (60KiB boundary)
  • All existing browser tests pass
npm run test:browser

Checklist:

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

@YangJonghun YangJonghun requested a review from a team as a code owner January 31, 2026 11:31
@codecov
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.49%. Comparing base (f15aa7e) to head (2b4f6e0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6358   +/-   ##
=======================================
  Coverage   95.48%   95.49%           
=======================================
  Files         363      364    +1     
  Lines       11564    11583   +19     
  Branches     2669     2671    +2     
=======================================
+ Hits        11042    11061   +19     
  Misses        522      522           
Files with missing lines Coverage Δ
...rter-base/src/otlp-browser-http-export-delegate.ts 63.63% <100.00%> (+3.63%) ⬆️
...-exporter-base/src/transport/failover-transport.ts 100.00% <100.00%> (ø)
...tlp-exporter-base/src/transport/fetch-transport.ts 91.42% <100.00%> (+0.51%) ⬆️
🚀 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.

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.

1 participant