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: adding ability to track all changes for web vitals #981

Merged
merged 6 commits into from
Feb 20, 2025

Conversation

eskirk
Copy link
Collaborator

@eskirk eskirk commented Feb 18, 2025

Why

solves #947

provides the option to enable the trackAllChanges feature in the web-vitals package

What

add reportAllWebVitalChanges to the config object to enable that feature in the web-vitals package

@eskirk eskirk requested a review from codecapitano February 18, 2025 19:09
* Report all changes for web vitals (default: false)
*
* In most cases, you only want the callback function to be called when the metric is ready to be reported.
* However, it is possible to report every change (e.g. each larger layout shift as it happens)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a comment that reportAllChanges isn't recommended to use in production and more for debugging purposes. See web-vitals docs

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion:
since we now have two props to configure web vitals we can add a config object bundling web-vitals updates. We can still keep the trackWebVitalsAttribution for quick enabling/disabling.
Then we would follow the shape of other config object which have multiple params.

Exmple:

webVitals {
  enabled: boolean
  reportAllWebVitalChanges: boolean
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I understood what you wanted here - I did not want to create a breaking change by adding trackWebVitalsAttribution into this object, but wasnt too sure what else to add in here?
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes exactly.

Nit:
for consistency we can add an enabled attribute to the webVitalsobject as well

Copy link
Collaborator

Choose a reason for hiding this comment

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

One last thing:

Let's add the "Instrumentation" prefix to the config object for consistency with the other instrumentation options like the consoleInstrumentation .

And remove the webVitals part from the nested property bc it is already namespaced by the parent object.

webVitalsInstrumentation: {
  reportAllChanges: true
}

@@ -15,8 +15,8 @@ export class WebVitalsInstrumentation extends BaseInstrumentation {

private intializeWebVitalsInstrumentation() {
if (this.config.trackWebVitalsAttribution) {
return new WebVitalsWithAttribution(this.api.pushMeasurement);
return new WebVitalsWithAttribution(this.api.pushMeasurement, this.config.reportAllWebVitalChanges);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need to update makeCoreConfig so the new property is added to the core config

Please add a small test to ensure that the trackWebVitalsAttribution is available in the config

@codecapitano codecapitano added the improvement Request a change of an existing feature label Feb 19, 2025
@codecapitano
Copy link
Collaborator

Please also update the web-vitals cloud docs.

@codecapitano
Copy link
Collaborator

please update the changelog

- Refactor web vitals configuration to use a nested `webVitals` object
- Add support for `reportAllWebVitalChanges` within the new configuration structure
- Update instrumentation classes to use the new configuration format
- Improve type safety and configuration flexibility for web vitals reporting
@eskirk eskirk requested a review from codecapitano February 19, 2025 20:20
Comment on lines 86 to 101
it('enables web vitals feature when trackWebVitalsAttribution is true', () => {
const browserConfig = {
url: 'http://example.com/my-collector',
app: {},
trackWebVitalsAttribution: true,
webVitals: {
reportAllWebVitalChanges: true,
},
};
const config = makeCoreConfig(browserConfig);

expect(config).toBeTruthy();
expect(config?.trackWebVitalsAttribution).toBe(true);
expect(config?.webVitals?.reportAllWebVitalChanges).toBe(true);
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codecapitano is this what you had in mind?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes exactly.
Only some slight adjustments for consistency with the other options.

Let's add the "Instrumentation" prefix to the config object for consistency with the other instrumentation options like the consoleInstrumentation .

And remove the webVitals part from the nested property bc it is already namespaced by the parent object.

webVitalsInstrumentation: {
reportAllChanges: true
}

@eskirk
Copy link
Collaborator Author

eskirk commented Feb 19, 2025

made changes to cloud docs here

Copy link
Collaborator

@codecapitano codecapitano left a comment

Choose a reason for hiding this comment

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

lgtm but please adjust the property names for consistency before merging 🙏

@eskirk eskirk merged commit 3bab705 into main Feb 20, 2025
9 checks passed
@eskirk eskirk deleted the elliot/947-report-all-wv-changes branch February 20, 2025 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Request a change of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants