Skip to content

🐛 Avoid duplicate tracing for marked fetch polyfills - #5147

Draft
adityareddy-dev wants to merge 1 commit into
DataDog:mainfrom
adityareddy-dev:fix/marked-fetch-polyfill-tracing
Draft

adityareddy-dev wants to merge 1 commit into
DataDog:mainfrom
adityareddy-dev:fix/marked-fetch-polyfill-tracing

Conversation

@adityareddy-dev

@adityareddy-dev adityareddy-dev commented Oct 15, 2026 •

Copy link
Copy Markdown

Motivation

Addresses the marked global polyfill case in #2940. Observing both fetch and its underlying XHR produces duplicate request observations and appends two sets of tracing headers to one request.

Changes

Use the existing XHR observer for globally installed XHR-backed fetch polyfills with fetch.polyfill === true, such as whatwg-fetch. Native and unmarked fetch functions keep their current behavior. Marked polyfills without an XMLHttpRequest property are still observed through fetch.

These calls use XHR context, so fetch input, init and response context and fetch-only request-header capture are unavailable. Logs handles failures through its XHR path. Global wrappers that drop the marker remain outside this fix.

Test instructions

Run yarn test:unit --spec packages/browser-core/src/browser/fetchObservable.spec.ts --spec packages/browser-core/src/browser/xhrObservable.spec.ts --spec packages/browser-rum-core/src/domain/requestCollection.spec.ts --spec packages/browser-rum-core/src/domain/tracing/tracer.spec.ts, yarn test:unit --spec packages/browser-logs/src/domain/networkError/networkErrorCollection.spec.ts and yarn typecheck.

The regression drives an XHR-backed fetch test double through buffering, request collection and the real tracer. Before the change it produces two started and completed requests and eight tracing-header writes. With the change it produces one completed XHR request and four header writes whose trace and span IDs match that request. The four-header assertion uses only the Datadog propagator, with baggage disabled. These assertions cover request lifecycle events, actual whatwg-fetch integration and staging validation remain unverified.

The four-spec command passes 107 tests and the Logs command passes 13 tests. Typecheck, ESLint and formatting pass for the changed files.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@adityareddy-dev

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@adityareddy-dev adityareddy-dev changed the title 🐛 Avoid duplicate tracing for XHR-backed fetch polyfills 🐛 Avoid duplicate tracing for marked fetch polyfills Oct 15, 2026

This branch has not been deployed

No deployments
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