RFC: Support Report Web Vitals as Opt-In CloudWatch Metrics
See original GitHub issueIs your feature request related to a problem? Please describe.
With reportWebVitals
in a custom _app.js
we can support recording Web Vitals as per docs: https://nextjs.org/docs/advanced-features/measuring-performance#web-vitals
Describe the solution you’d like
- Support a
/analytics
endpoint. - Use same site domain to avoid updating CSP or CORS.
- Upload minimal data with Async POST requests to edge lambda.
- Configure analytics lambda to record custom metrics in CloudWatch, perform Async transforms of minimal data from client and formatting metrics and dimensions.
- Metrics should support per page analysis.
- Metrics package should be decoupled and deployment would be optional configuration.
Describe alternatives you’ve considered
Two popular managed services for this:
These are good services, but they are paid services.
Additional context
- Further support for alarms and regressions could be added by open extensibility.
- Further support for regional dimensions might be wanted.
Background reading: https://developer.mozilla.org/en-US/docs/Learn/Performance/Measuring_performance
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Manually create or edit the CloudWatch agent configuration file
Explains how to manually create the CloudWatch agent configuration file, including the sections and settings inside the CloudWatch agent configuration file.
Read more >Measuring Performance - Web Vitals - Create React App
Web Vitals are a set of useful metrics that aim to capture the user experience of a web page. In Create React App,...
Read more >Sumo Logic Service Release Notes
We're pleased to announce a new chart type for metric queries. A heat map visualizes the count of data points returned by a...
Read more >Amazon Load Balancer - Datadog Docs
Track key Amazon Load Balancer metrics. ... Elastic Load Balancing (ELB) is an AWS service used to dispatch incoming web traffic from your...
Read more >Participant Digital Health Twin for Clinical Trials
data with contextual data and the ability to analyze robust clinical, medical and contextual data to support continuous improvement of clinical trials.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What do you think if we introduce our own
performance-relayer
client implementation? To start with it could be the similar or same as Next.js Vercel one.So if users opt-in to the Analytics functionality we’d bootstrap the backend Analytics endpoint in Lambda@Edge for them.
Client side they could install an NPM module, e.g.
Later on, we could provide some way to allow for extensibility.
That’s right @dphang it doesn’t block rendering. Ideally we would support using the Beacon API which is generally more efficient than using
fetch
directly and it handles when metrics are sent and the page is unloaded (e.g. an external link click).@danielcondemarin, sure, I can elaborate.
Data Collection
It is probably best to begin with the implementation in NextJS source code.
https://www.github.com/vercel/next.js/tree/canary/packages%2Fnext%2Fclient%2Fperformance-relayer.ts
This
performance-layer.ts
module in required inclient/index
. It is mounted in auseEffect
hook to run after DomContentLoaded has occured.Line 49 has the hardcore’s endpoint for
vercel-analytics.com
. I would expect this to be aprocess.env
in the future as this proprietary endpoint hard coding is not OSS in my opinion.This module will observe the metrics required from the
web-vitals
packageCustom CloudWatch Metrics
Capturing these as Custom CloudWatch Metrics would be the proposed solution. There could be unique metric names for each of these five webvitals per deployment.
MyNextServerlessCLS
MyNextServerlessFCP
MyNextServerlessFID
MyNextServerlessLCP
MyNextServerlessTTFB
MetricDatum
can be seconds as sent in the value field of the body from the nextJSperformance-layer.ts
.These can be visualised in percentiles as the user wants, but defaults of P75 (recommended bench marker https://web.dev/vitals/) would be ideal for any dashboard.
To enhance these metrics it would be possible to add some dimensions.
Device='mobile' | 'tablet' | 'desktop'
Page=${body.page}
( Next page .e.g./[slug].js
Region=${process.env.AWS_REGION}
(default lambda env)It is worth noting that you cannot aggregate custom metrics along multiple dimensions, being overly specific means you cannot re-aggregate for the global metric.
Presentation (CloudWatch Dashboard)
These dashboards are some what limited but the main components can be achieved:
The last piece is the pages section. Having this dimension will be helpful I think, but visualizing so many dimensions might be overload.
Some trial and error might be required.
Hope that makes sense. The architecture would be as described previously.