sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Upgrade to web-vitals v3

Open AbhiPrasad opened this issue 2 years ago • 1 comments

Problem Statement

Web Vitals v3 is currently in beta.

Allows us to start tracking INP, which can replace FID.

https://web.dev/inp/

Writing your own PerformanceObserver to measure INP can be difficult. To measure INP in JavaScript, it's advised that you use the web-vitals JavaScript library, which exports an onINP function to do this work for you. At the moment, getting INP data is only possible in version 3 of web-vitals, currently in beta, which can be installed with the following command:

npm install web-vitals@next --save

You can then get a page's INP by passing a function to the onINP method:

import {onINP} from 'web-vitals';
onINP(({value}) => {
 // Log the value to the console, or send it to your analytics provider.
 console.log(value);
});

As with other methods exported by web-vitals, onINP accepts a function as an argument, and will pass metric data to the function you give it. From there, you can send that data to an endpoint for collection and analysis.

Solution Brainstorm

https://www.npmjs.com/package/web-vitals/v/next

https://github.com/GoogleChrome/web-vitals/compare/next

Seems like its around ~2kb larger. Can we address that?

AbhiPrasad avatar Jul 25 '22 20:07 AbhiPrasad

Release candidate has been released: https://github.com/GoogleChrome/web-vitals/issues/250#issuecomment-1196172221

AbhiPrasad avatar Jul 27 '22 03:07 AbhiPrasad

Has been released: https://github.com/GoogleChrome/web-vitals/issues/250#issuecomment-1226091266

https://github.com/GoogleChrome/web-vitals/releases/tag/v3.0.0

https://github.com/GoogleChrome/web-vitals/blob/main/CHANGELOG.md#v300-2022-08-24

AbhiPrasad avatar Aug 24 '22 19:08 AbhiPrasad

For the moment and scope of this issue, we are only interested to upgrade to web vitals v3.

We shouldn't invest time supporting the INP for the time being as this is something we are looking to get more requests from the performance team.

vladanpaunovic avatar Oct 14 '22 13:10 vladanpaunovic

Note, @timfish's work in #5987 does not include code for INP. That will have to be vendored separately (cc @k-fish)

AbhiPrasad avatar Oct 24 '22 07:10 AbhiPrasad

@AbhiPrasad thanks, I already have a good chunk of the INP code written, but it means we'll have to re-consider the transaction model to include interactions. I think we can cut a branch at the very least to try it out and then graduate it into a beta branch / mainline it as an experimental option if that proves to work for our app at least.

k-fish avatar Oct 24 '22 13:10 k-fish