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-1577] Collect page lifecycle states #2229

Merged
merged 9 commits into from
May 17, 2023

Conversation

amortemousque
Copy link
Contributor

@amortemousque amortemousque commented May 10, 2023

Motivation

Modern browsers today will sometimes suspend pages or discard them entirely when system resources are constrained, which can lead to unexpected behaviors. The Page Lifecycle API, provides lifecycle hooks so we can detect and handle these browser interventions.

This PR, collect page lifecycle state changes during a view to help Browser SDK issue investigations.

Changes

  • Value history findAll accepts a duration
  • Add maxEntries limit to valueHistory
  • Use valueHistory in pageSateHistory
  • Collect page states changes during views
  • Limit the number of page states collected per view

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@amortemousque amortemousque requested a review from a team as a code owner May 10, 2023 15:16
@amortemousque amortemousque changed the title Aymeric/page lifecycle 🔊 [RUMF-1577] Collect page lifecycle states May 10, 2023
@codecov-commenter
Copy link

codecov-commenter commented May 11, 2023

Codecov Report

Merging #2229 (273911e) into main (0a0e00a) will increase coverage by 0.06%.
The diff coverage is 95.00%.

@@            Coverage Diff             @@
##             main    #2229      +/-   ##
==========================================
+ Coverage   94.01%   94.07%   +0.06%     
==========================================
  Files         201      201              
  Lines        6083     6095      +12     
  Branches     1347     1349       +2     
==========================================
+ Hits         5719     5734      +15     
+ Misses        364      361       -3     
Impacted Files Coverage Δ
...s/rum-core/src/domain/contexts/pageStateHistory.ts 93.02% <92.68%> (+10.09%) ⬆️
packages/core/src/tools/experimentalFeatures.ts 100.00% <100.00%> (ø)
packages/core/src/tools/valueHistory.ts 100.00% <100.00%> (ø)
packages/rum-core/src/boot/startRum.ts 92.00% <100.00%> (+0.16%) ⬆️
.../domain/rumEventsCollection/view/viewCollection.ts 100.00% <100.00%> (ø)
packages/rum-core/test/testSetupBuilder.ts 96.05% <100.00%> (+1.31%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@amortemousque amortemousque force-pushed the aymeric/page-lifecycle branch from 978088b to a16526f Compare May 11, 2023 12:59
Comment on lines 93 to 95
const limit = Math.max(0, pageStateEntries.length - maxPageStateEntriesSelectable)

for (let index = pageStateEntries.length - 1; index >= limit; index--) {
Copy link
Member

Choose a reason for hiding this comment

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

🥜 nitpick: ‏It could be easier to grasp as:

for (let index = pageStateEntries.length - 1; index >= 0 && pageStateServerEntries.length < maxPageStateEntriesSelectable; index--) {
}

Or, maybe you could adapt the previous version as: .findAll().slice(0, maxPageStateEntriesSelectable).reverse().map()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hum, I was hesitating to do that in the first place but as it is less effective performance wise I went with a good old loop. I don't have a strong opinion though. Maybe a third party @bcaudan can help deciding?

Copy link
Contributor

Choose a reason for hiding this comment

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

I had the same thought, maybe adding a couple comments could make this code easier to grasp while keeping the most performant approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added some comments:

// limit the number of entries to return
const limit = Math.max(0, pageStateEntries.length - maxPageStateEntriesSelectable)
// loop page state entries backward to return the selected ones in desc order
for (let index = pageStateEntries.length - 1; index >= limit; index--) {

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