[RUM-17907] Add optional global Fetch resource tracking - #1360
Conversation
Add trackFetchResources configuration to instrument Expo and other global Fetch implementations while keeping XHR tracking enabled. Coordinate Fetch and XHR proxies to prevent duplicate events for XHR-backed Fetch requests.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f45729efb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| response: Response; | ||
| resourceReporter: ResourceReporter; | ||
| }) => { | ||
| resourceReporter.reportResource({ |
There was a problem hiding this comment.
Extract GraphQL errors before reporting Fetch resources
When DatadogLink({ trackErrors: true }) sends a GraphQL request through the global Fetch path, processRequestHeader records context.graphql.trackErrors, but this function reports immediately without reading the response body. Unlike reportXhr, it therefore never populates context.graphql.errors, so enabling trackFetchResources makes the documented GraphQL response errors disappear from RUM for Fetch/Apollo requests; parse and filter a clone of the response before reporting when the operation type and error-tracking flag are set.
Useful? React with 👍 / 👎.
| this.context = null; | ||
| this.originalFetch = null; | ||
| this.installedFetch = null; |
There was a problem hiding this comment.
Keep retained Fetch wrappers callable after tracking stops
When another library installs a Fetch wrapper after Datadog and captures the current global.fetch, the identity check intentionally leaves that later wrapper installed, but clearing originalFetch makes the captured Datadog wrapper pass null into trackFetch. Subsequent calls through the later wrapper then throw at originalFetch.call(...) instead of making a network request; the retained wrapper must either keep its original delegate or bypass instrumentation after tracking stops.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in RUM resource-tracking capability for global Fetch implementations (including Expo’s global fetch) via a new trackFetchResources configuration flag, while keeping existing XHR instrumentation enabled and coordinating the two to reduce duplicate resource events for XHR-backed fetch implementations.
Changes:
- Introduces a new
FetchProxyand shared “common” request-context/header/reporting utilities to reuse existing tracing, baggage, GraphQL metadata, and filtering logic across Fetch and XHR. - Adds the
trackFetchResourcesconfiguration option across programmatic, auto-instrumentation, and file-based configuration (including schema + docs); default remainsfalse. - Adds unit/integration tests covering Fetch tracking behavior and Fetch/XHR de-duplication behavior.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/sdk/DatadogProvider/tests/initialization.test.tsx | Updates initialization expectations to include trackFetchResources default. |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts | Refactors XHR proxy to use shared request context/header logic and suppress XHR reporting during Fetch-proxy synchronous execution to reduce duplicates. |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/tests/ResourceReporter.test.ts | Points tests at the shared ResourceReporter. |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/tests/internalDevResourceBlocklist.test.ts | Updates tests to use the shared dev-resource blocklist. |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/tests/XHRProxy.test.ts | Updates XHR proxy tests to use the shared ResourceReporter. |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts | Adds Fetch proxy implementation that reports global fetch requests as RUM resources and injects instrumentation headers. |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/tests/FetchProxy.test.ts | Adds unit tests for Fetch proxy reporting, header handling, sampling updates, and unwrapping behavior. |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/common/resourceTiming.ts | Cleans up timing helper comments while keeping behavior intact. |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.ts | Adjusts imports and constructor parameter naming for the shared reporter. |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.ts | Adds shared header processing and instrumentation header generation (tracing, baggage, GraphQL, tracked-by). |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts | Adds shared request context builder (timer, tracing attrs, baggage aggregation, GraphQL attrs). |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.ts | Relocates dev-resource filtering to shared location and updates import paths. |
| packages/core/src/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.ts | Adds shared state to mark synchronous execution under Fetch proxy for XHR de-duplication. |
| packages/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx | Installs both XHR and optional Fetch proxies; manages lifecycle/update/stop across multiple proxies. |
| packages/core/src/rum/instrumentation/resourceTracking/tests/DdRumResourceTracking.test.ts | Adds coverage for enabling/disabling Fetch tracking and Fetch/XHR coordination (including XHR-backed fetch). |
| packages/core/src/DdSdkReactNative.tsx | Plumbs trackFetchResources from configuration into resource tracking start. |
| packages/core/src/config/FileBasedConfiguration.type.ts | Extends JSON config typing to include trackFetchResources. |
| packages/core/src/config/FileBasedConfiguration.ts | Serializes trackFetchResources into file-based JSON config output. |
| packages/core/src/config/features/RumConfiguration.type.ts | Adds typed trackFetchResources option with documentation. |
| packages/core/src/config/features/RumConfiguration.ts | Adds default + instance field for trackFetchResources. |
| packages/core/src/config/async/AutoInstrumentationConfiguration.ts | Adds trackFetchResources into auto-instrumentation config defaults/parameters. |
| packages/core/src/config/tests/FileBasedConfiguration.test.ts | Updates file-based config tests for trackFetchResources. |
| packages/core/src/config/tests/fixtures/configuration-all-fields.json | Adds fixture coverage for trackFetchResources. |
| packages/core/src/tests/DdSdkReactNativeConfiguration.test.ts | Updates configuration expectations to include trackFetchResources default. |
| packages/core/src/tests/DdSdkReactNative.test.tsx | Updates tests to pass trackFetchResources through SDK init and validate plumbing. |
| packages/core/README.md | Documents trackFetchResources behavior and relationship to XHR tracking. |
| packages/core/datadog-configuration.schema.json | Adds schema support for trackFetchResources under RUM configuration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
What does this PR do?
Adds optional resource tracking for global Fetch implementations, including Expo Fetch, through the new trackFetchResources configuration option.
XHR instrumentation remains enabled independently so requests made through Axios or direct XMLHttpRequest calls continue to be tracked. The Fetch and XHR proxies coordinate to prevent duplicate resource events when the active Fetch implementation is itself backed by XHR.
Motivation
Expo Fetch can bypass the SDK’s existing XHR instrumentation, which means those network requests are currently missing from RUM resource tracking.
This change allows users to explicitly enable Fetch instrumentation while preserving the existing XHR coverage and avoiding duplicate events across different Fetch implementations.
Changes
Review checklist (to be filled by reviewers)