Real User Monitoring and Web Vitals
Capture LCP, FID, CLS, and custom performance marks as OTel metrics using the web-vitals library.
The web-vitals Library
Google's web-vitals npm package provides a simple API for measuring Core Web Vitals in real user browsers. Install it with npm install web-vitals and import individual metric callbacks: onLCP, onFID (deprecated), onCLS, onFCP, onTTFB, and the modern onINP for Interaction to Next Paint.
Metric Callbacks and Metric Objects
Each callback (onLCP, onCLS, onINP, etc.) receives a metric object containing: name ('LCP'), value (milliseconds or unitless score), rating ('good', 'needs-improvement', 'poor'), and id (a unique identifier for deduplication). The callback fires once the metric value is finalized.
All lessons in this course
- Frontend Observability: What and Why
- OpenTelemetry Traces from the Browser
- Real User Monitoring and Web Vitals
- Correlating Frontend and Backend Traces