-
Notifications
You must be signed in to change notification settings - Fork 142
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
🐛 Resource Timings are inaccurate when ServiceWorker is involved #2566
Labels
bug
Something isn't working
Comments
Thank you for your thorough report! We are looking into it. We'll keep you updated. |
We are still figuring how to best handle this case. In the meantime I opened a Chromium issue: https://issues.chromium.org/issues/323703325 |
4 tasks
BenoitZugmeyer
added a commit
that referenced
this issue
Apr 4, 2024
Before this commit, we dropped any `PerformanceResourceEntry` that had inconsistent timings. With this commit, when the experimental feature "tolerant_resource_timings" is enabled, the various timings are validated independently. This should improve the situation on Chrome when a Service Worker is involved. In this case, most of the time, connection timings are unexpectedly set after the `requestStart` timing (see Chromium issue[1]). Before this change, the whole `PerformanceResourceEntry` would be ignored, and no timings would be included. With this change (and the flag enabled), relevant timings will be correctly defined. Related issue: #2566 [1]: https://issues.chromium.org/issues/323703325
BenoitZugmeyer
added a commit
that referenced
this issue
Apr 4, 2024
Before this commit, we dropped any `PerformanceResourceEntry` that had inconsistent timings. With this commit, when the experimental feature "tolerant_resource_timings" is enabled, the various timings are validated independently. This should improve the situation on Chrome when a Service Worker is involved. In this case, most of the time, connection timings are unexpectedly set after the `requestStart` timing (see Chromium issue[1]). Before this change, the whole `PerformanceResourceEntry` would be ignored, and no timings would be included. With this change (and the flag enabled), relevant timings will be correctly defined. Related issue: #2566 [1]: https://issues.chromium.org/issues/323703325
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
NOTE: This was discussed and shown at length in a call with support on 12/12/2023 with traeger.meyer@datadoghq.com and shayne.sebro@datadoghq.com. There should be a recording available of that call. Datadog 1345744 // 1963 - RUM Resource Timing - Customer call
Service worker based resource network requests are being reported improperly by browser-sdk rum resourceCollection. This causes the duration to be incorrect as well as causing other fields to be missing from the RUM entry.
Browser: Chrome (Firefox and Safari don't seem to support workerStart yet)
BrowserSDK versions affected: Seems to affect multiple major versions including v5 and v4
This seems to happen mainly due to
requestStart
being set toworkerStart
and those falling before theconnectionStart
/connectionEnd
timings when a ServiceWorker. I notice it most commonly when a service worker is intercepting a request over http2 re-using an existing TCP connection to a domain.When a service worker is involved in a network request it changes the fields of the PerformanceResourceTiming.
In addition to setting the
workerStart
property to be non-zero it also changes therequestStart
time to be set to theworkerStart
property. This causes a logic check to fail in theresourceUtils.ts#toValidEntry
function to fail due to theentry.requestStart
time falling before the other timings in theareInOrder
check.browser-sdk/packages/rum-core/src/domain/resource/resourceUtils.ts
Lines 138 to 157 in 43c4456
This causes the
matchRequestTiming
function to not find a correct matching timing due to it filtering out the timing due tofilter(toValidEntry)
removing the timings from service workers.browser-sdk/packages/rum-core/src/domain/resource/matchRequestTiming.ts
Lines 24 to 37 in 43c4456
The
matchingTiming
being set toundefined
frommatchRequestTiming
then results in not calculating anycorrespondingTimingOverrides
withcomputePerformanceEntryMetrics
. This has a couple of knock on effects:Due to not having the correct entry metrics the duration being reported in the RumEvent is the timestamp of when the datadog rum XHR onLoad handler fires instead of when the resource finished.
browser-sdk/packages/rum-core/src/domain/resource/resourceCollection.ts
Lines 76 to 78 in 43c4456
This makes the duration be susceptible to delays on the event loop which can cause a large difference in the reported time from the actual when the event loop is busy and a network resource is waiting to fire its onLoad handlers.
This also results in the various fields from
computePerformanceResourceDetails
not being included in the RumEvent due to not being called fromcomputePerformanceEntryMetrics
.browser-sdk/packages/rum-core/src/domain/resource/resourceUtils.ts
Lines 88 to 136 in 43c4456
To Reproduce
Steps to reproduce the behavior:
I did a reproduction on a call with the support team that was recorded. Included below is a basic reproduction case but can be slightly annoying to setup and show from scratch. I'm happy to jump on a call showing a reproduction.
beforeSend
callback you can view them easily. Otherwise you can view them in the DD rum explorer. If theworkerStart
is set therequestStart
has been set to its value. Might take a few tries but should be able to see that the RumEvents are missingcomputePerformanceResourceDetails
fields and have an incorrect duration.Expected behavior
RumEvents should be reported correctly when a service worker is involved. To fix this you can make a change to the
toValidEntry
function to check if theentry.workerStart
field is non-zero. If so then use a different conditional check to verify fields are valid and in proper order.Related useful information / links:
Spec Links:
ResourceTiming - https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-requeststart
NavigationTiming - https://www.w3.org/TR/navigation-timing-2/#PerformanceResourceTiming
ServiceWorker - https://www.w3.org/TR/service-workers/#service-worker-timing
Fetch - https://fetch.spec.whatwg.org/#http-fetch
W3C workerStart spec questions
w3c PR where they talk about how
workerStart
is interacting withrequestStart
w3c/resource-timing#119workerStart and redirects - w3c/navigation-timing#131
whatwg/fetch#1413
WPT Updates
Fetch, ResourceTiming and ServiceWorkers - web-platform-tests/wpt#31229
The text was updated successfully, but these errors were encountered: