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

feat(rum): report INP metric #1462

Merged
merged 22 commits into from
Dec 27, 2023
Merged

feat(rum): report INP metric #1462

merged 22 commits into from
Dec 27, 2023

Conversation

devcorpio
Copy link
Contributor

@devcorpio devcorpio commented Dec 12, 2023

Summary

Related to #1293

From now on, the RUM agent will start reporting the INP metric.

  • INP will not be reported if there is no user activity
  • INP will be reported as 0 if the slowest detected interaction duration is < 40
  • INP will pick the slowest interaction if there have been less than 50 interactions
  • INP will result from calculating the P98 if there have been more than 50 interactions.
  • The metric will be reported when the user leaves the page, which can happen multiple times.
  • We will "reset" the tracked interactions every time we report the metric
  • INP will be attached to the page where the user "hard-navigated to".

For further details, please see the code which is heavily documented given the experimental nature of this metric.

Screenshot where we can see the INP metric on the User Experience page:

INP metric

@devcorpio devcorpio force-pushed the report-inp-metric branch 3 times, most recently from 8995717 to 88874ad Compare December 13, 2023 11:33
@devcorpio devcorpio changed the title DRAFT chore: wip commit INP feat(rum): report INP metric Dec 13, 2023
@devcorpio
Copy link
Contributor Author

hi @v1v,

it seems our test steps are failing with this error:

Screenshot 2023-12-13 at 13 05 37

Looking for info I found that might be related with Docker 7.0.0, link to the changelog

and a link to a conversation that a few people are having: docker/docker-py#3194

Do you know what can we do to fix this?

@devcorpio devcorpio marked this pull request as ready for review December 13, 2023 12:28
@v1v
Copy link
Member

v1v commented Dec 13, 2023

Do you know what can we do to fix this?

As far as I see python3.10 is the one set in the GitHub runners. I don't know whether we can use a pinned version for the GitHub runner or do some magic with downgrading the docker version.

Let me see if I can figure out how to solve this

@v1v
Copy link
Member

v1v commented Dec 13, 2023

871d1a0 might help, I followed the steps explained here.

# As long as there are issues with the ssl lets use 6.1.3
# see https://github.com/docker/docker-py/issues/3194
pip uninstall docker
pip install docker==6.1.3
Copy link
Contributor Author

@devcorpio devcorpio Dec 13, 2023

Choose a reason for hiding this comment

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

@v1v amazing, thank you for making this change so fast! for what I'm seeing it works perfectly 🎉

@devcorpio devcorpio linked an issue Dec 13, 2023 that may be closed by this pull request
Makes sure that a transaction ended while the page was becoming hidden
it's not discarded for that very same reason.
*/
endPageHidden(endTime) {
Copy link
Contributor Author

@devcorpio devcorpio Dec 13, 2023

Choose a reason for hiding this comment

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

I created this function because while I was doing the last exploratory testing session I spotted a bug:

The logic where we detect if the website becomes hidden in order to end the ongoing transaction, had a race condition:

  1. transaction.end()
  2. update lastHiddenStart

unfortunately, the code where we check if a transaction should be discarded because "the page was hidden during the transaction" doesn't happen in a sync way in transaction.end(), it happens after executing a javascript Promise.

So, assuming that calling transaction.end() in that part of the code was a synchronous process was wrong. It was updating the lastHiddenStart before doing the end transaction check (even if the end was invoked before)

Fortunately, this was not affecting the page-load transaction, I only reproduced the described behaviour with the INP transaction and with click transactions. (not all the time, it depended on who was "winning" the race)

Copy link
Member

Choose a reason for hiding this comment

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

It was updating the lastHiddenStart before doing the end transaction check (even if the end was invoked before)

This seems wrong, we update the lastHiddenStart on Queue:Add event which should happen post the transaction was ended in async way.

Copy link
Member

Choose a reason for hiding this comment

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

We discussed this offline and planned to add another event transaction:skipped to update the last hidden start time.

Copy link
Contributor Author

@devcorpio devcorpio Dec 22, 2023

Choose a reason for hiding this comment

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

this is the related commit df7423d 🚀

Copy link
Member

@vigneshshanmugam vigneshshanmugam left a comment

Choose a reason for hiding this comment

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

Great job @devcorpio 🎉, Thanks a ton for adding in lots of details around the core INP calculation logic and also adding relevant links to the spec where necessary. It was really nice to see them side by side and also understanding the spec/browser reporting.

@devcorpio devcorpio force-pushed the report-inp-metric branch 2 times, most recently from 582edc1 to 55aca81 Compare December 22, 2023 15:46
Copy link
Member

@vigneshshanmugam vigneshshanmugam left a comment

Choose a reason for hiding this comment

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

LGTM 🎉 , Added small suggestions. Nothing blocking.

reportInp(transactionService)
const inpTr = reportInp(transactionService)
// we don't want to flush the queue for every transaction that is ended when page becomes hidden
// and given the async nature of the ending process of transactions
Copy link
Member

Choose a reason for hiding this comment

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

nit: might reword it as transaction ends are scheduled async as microtasks(promise), so we are coordinating the flushing process

@@ -110,6 +110,7 @@ const TRANSACTION_END = 'transaction:end'
const CONFIG_CHANGE = 'config:change'
const QUEUE_FLUSH = 'queue:flush'
const QUEUE_ADD_TRANSACTION = 'queue:add_transaction'
const TRANSACTION_DISCARD = 'transaction:discard'
Copy link
Member

Choose a reason for hiding this comment

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

should we rename it as trasaction:ignore/skip ? mainly suggesting because ignored also aligns with our config settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it makes sense 🚀

@devcorpio devcorpio merged commit 866f066 into main Dec 27, 2023
19 of 23 checks passed
@devcorpio devcorpio deleted the report-inp-metric branch December 27, 2023 10:43
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.

Add support for Interaction Next Paint (INP)
4 participants