Skip to content
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

🐛 [RUMF-670] wait for the DOM to be ready before getting the trace id #525

Conversation

BenoitZugmeyer
Copy link
Member

Motivation

Because the RUM SDK can be initialized synchronously when the document is loading, the DOM may not be fully accessible when getting the trace id set by APM. In particular, if meta tags are written after the SDK snippet, the SDK will not have access to them during init.

Changes

Wait for DOM to be loaded before getting the trace id and generating the initial document resource.

Testing

Tests have been written in the integration test POC PR #524


I have gone over the contributing documentation.

Because the RUM SDK can be initialized synchronously when the document
is loading, the DOM may not be fully accessible when getting the trace
id set by APM. In particular, if meta tags are written after the SDK
snippet, the SDK will not have access to them during init.
@BenoitZugmeyer BenoitZugmeyer requested a review from a team as a code owner September 8, 2020 16:04
@codecov-commenter
Copy link

codecov-commenter commented Sep 8, 2020

Codecov Report

Merging #525 into master will decrease coverage by 0.18%.
The diff coverage is 56.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #525      +/-   ##
==========================================
- Coverage   87.97%   87.79%   -0.19%     
==========================================
  Files          36       36              
  Lines        2262     2269       +7     
  Branches      466      467       +1     
==========================================
+ Hits         1990     1992       +2     
- Misses        272      277       +5     
Impacted Files Coverage Δ
packages/rum/src/performanceCollection.ts 63.63% <54.54%> (+0.30%) ⬆️
packages/core/src/utils.ts 87.28% <100.00%> (+0.07%) ⬆️
packages/rum/src/rum.ts 86.66% <0.00%> (-2.97%) ⬇️
packages/rum/src/parentContexts.ts 100.00% <0.00%> (+1.75%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d169349...40af2d6. Read the comment docs.

Copy link
Contributor

@mquentin mquentin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go with a NIT comment

packages/rum/src/performanceCollection.ts Outdated Show resolved Hide resolved
Comment on lines +104 to +105
export function retrieveInitialDocumentResourceTiming(callback: (timing: RumPerformanceResourceTiming) => void) {
runOnReadyState('interactive', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other function name is retrieveNavigationTimingWhenLoaded, so I think it could be nice to also reflect in the function name that it is waiting for a specific page state.
However, it could be even clearer to move the runOnReadyState outside of these functions:

runOnReadyState('interactive', () => {
  retrieveInitialDocumentResourceTiming((timing) => {
    handleRumPerformanceEntry(lifeCycle, timing)
  })
}}

runOnReadyState('complete', () => {
  retrieveNavigationTiming((timing) => {
    handleRumPerformanceEntry(lifeCycle, timing)
  })
}}

Copy link
Member Author

@BenoitZugmeyer BenoitZugmeyer Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for the DOM to be ready or document to be loaded is an implementation detail and I think it's better to keep it in the function. In particular, retrieveNavigationTiming is waiting for the document load + a bit of time for the loadEventEnd to be defined: it would be hard to understand what's going on if those tasks were in two different places.

I'm fine with renaming the function to retrieveInitialDocumentResourceTiming to retrieveInitialDocumentResourceTimingWhenDomReady even if I don't see much value in it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so maybe rename retrieveNavigationTimingWhenLoaded to retrieveNavigationTiming to be consistent in considering it as an implementation detail

@BenoitZugmeyer BenoitZugmeyer merged commit 0951a91 into master Sep 9, 2020
@BenoitZugmeyer BenoitZugmeyer deleted the benoit/wait-for-dom-ready-before-getting-document-trace-id branch September 9, 2020 13:38
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.

4 participants