🐛 improve early request collection reliability in Firefox#4573
Draft
BenoitZugmeyer wants to merge 1 commit intov7from
Draft
🐛 improve early request collection reliability in Firefox#4573BenoitZugmeyer wants to merge 1 commit intov7from
BenoitZugmeyer wants to merge 1 commit intov7from
Conversation
a3581e4 to
8558f01
Compare
When a fetch resolves, two things happen around the same time: - the browser dispatches a PerformanceResourceTiming entry to our observer - afterSend() resumes from `await responsePromise` and notifies REQUEST_COMPLETED On Firefox the observer task can fire before the resolve microtask runs, so the request isn't in the registry yet when assembleResource() looks it up, and the resource event ends up without handlingStack / requestInit / etc. Defer the registry lookup for request-type entries by REQUEST_MATCHING_DELAY (50ms) so the matching REQUEST_COMPLETED has time to land. assembleResource now takes the resolved request directly instead of pulling it from the registry. Tests drive the delay through mockClock.tick().
8558f01 to
b645dab
Compare
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: b645dab | Docs | Datadog PR Page | Give us feedback! |
thomas-lebeau
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The microfrontend e2e test
microfrontend > RUM > with beforeSend > expose handling stack for fetch requests › asyncfails ~70% of the time onfirefox-pinned(10 failed / 6 flaky / 4 passed out of 20 reproductions). The same race affects any fetch resource event in production:event.context.handlingStack(and the rest of the request-derived domain context —requestInit,response,error, …) is intermittentlyundefinedfor fetch resources on Firefox.Root cause
When a fetch resolves, two things happen around the same time:
PerformanceResourceTimingentry to our observerafterSend()resumes fromawait responsePromiseand notifiesREQUEST_COMPLETEDOn Firefox the observer task can fire before the resolve microtask runs, so the request isn't in the
requestRegistryyet whenassembleResource()looks it up viarequestRegistry.getMatchingRequest(). The lookup returnsundefinedand the resulting resource event is missing all request-derived domain context.This was introduced by #4285
always collect early requests(commit2b71062e7), which switched from request-driven (performance.getEntriesByName()atREQUEST_COMPLETEDtime) to entry-driven matching.CI logs of the failing case make the ordering obvious:
Changes
startResourceCollection: for request-type entries (fetch/xmlhttprequestinitiator), defer the registry lookup byREQUEST_MATCHING_DELAY(50 ms) viasetTimeout. In practice the matchingREQUEST_COMPLETEDarrives within ~30 ms even on slow CI runners, so 50 ms is a generous bound.assembleResourcenow takes the resolvedrequestdirectly instead of pulling it from the registry — the matching policy is owned by the call site where the timing context is clear.requestRegistryis unchanged;getMatchingRequestis still synchronous.mockClock.tick(REQUEST_MATCHING_DELAY)insiderunTasks.Test instructions
Repro on the e2e suite (Firefox is the most reliable, but the race is browser-agnostic):
CI validation (e2e job scoped to the failing test,
--repeat-each=20):Checklist