Production-grade guide to real user monitoring guide covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.
Real User Monitoring (RUM) captures the actual experience of users interacting with an application in production. It measures performance, availability, and errors from the user’s device — the browser, mobile app, or embedded client — providing end-to-end visibility into how users perceive the system. This guide details how to implement and maintain a robust RUM pipeline that surfaces real user behavior, identifies performance regressions before they impact customers, and correlates front-end experiences with backend traces and logs.
To capture real user data, embed a lightweight JavaScript snippet directly in the page HTML or delivered via a build artifact. This script must:
<script>
(function() {
const script = document.createElement('script');
script.src = '/js/rum-client.js';
script.async = true;
script.onload = () fromWindow('rum', 'init');
document.head.appendChild(script);
})();
</script>
The rum-client.js file exposes a global rum object. It must be loaded before any other app script to ensure no interaction is missed.
The client is configured via a window.rum object defined before the script loads.
window.rum = {
projectId: 'ecommerce-frontend',
environment: 'production',
sampleRate: 0.5,
captureErrors: true,
capturePerformance: true,
sendOnPageHide: true,
userAttributes: {
userId: 'u12345',
sessionId: 's67890',
userAgent: navigator.userAgent,
screenResolution: `${screen.width}x${screen.height}`,
networkType: navigator.connection?.effectiveType || 'unknown'
}
};
sampleRate: 0.5 means every second user request is recorded; the client uses a uniform random sampling algorithm.capturePerformance enables measuring first-contentful-paint, largest-contentful-paint, first-input-delay, and time-to-first-byte.sendOnPageHide triggers a final data flush when the user navigates away, even if the page is still in the background.Each RUM event is a JSON object sent via fetch to a /events/rum endpoint:
{
"type": "page-load",
"timestamp": 1712345678901,
"projectId": "ecommerce-frontend",
"environment": "production",
"userId": "u12345",
"sessionId": "s67890",
"url": "https://shop.example.com/products/123",
"pageId": "product-page",
"timing": {
"firstPaint": 1200,
"firstContentfulPaint": 1800,
"largestContentfulPaint": 2400,
"firstInputDelay": 420,
"timeToFirstByte": 500,
"domComplete": 3100,
"load": 3800
},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
"networkType": "4g",
"screenResolution": "1920x1080",
"errors": [
{
"message": "Failed to load product image",
"stack": "Error: Failed to fetch\n at loadProductImage (main.js:42)",
"timestamp": 1712345678901,
"source": "client"
}
],
"custom": {
"viewTime": 14.2,
"scrollDepth": 87
}
}
The timing object uses standard Web Vitals metrics. firstInputDelay is computed from the first interaction after first-contentful-paint, and load is loadEventEnd - navigationStart.
RUM data flows into a central ingestion service. The ingestion endpoint must:
Content-Type: application/json; charset=utf-8.curl -X POST https://ingest.example.com/events/rum \
-H 'Content-Type: application/json' \
-d '[{ ... }, { ... }]'
The service should:
projectId or timestamp.rum-ingest-failures Kafka topic.All events must include:
type: page-load, navigation, error, custom-event, interaction.timestamp: ISO 8601 UTC timestamp, 1712345678901 (milliseconds since Unix epoch).projectId: string, required.environment: string, optional, defaults to development.Additional fields are optional but encouraged:
userId, sessionId, pageId, url, screenResolution, networkType.timing, errors, custom, userAttributes.To link front-end performance to backend operations, RUM events must carry a traceId and spanId.
When a frontend request is made (e.g., fetch('/api/products/123')), the client must:
traceId using UUIDv4.traceparent header in the HTTP request:traceparent: 00-0af765e27ed32446c4444a701d7c3981-5062c28d15d10348-01
The format is the W3C Trace Context standard:
00-<trace-id>-<span-id>-<flags>
trace-id: 32-character hex string.span-id: 16-character hex string.flags: 2-character hex string, 01 indicates sampled.The backend must extract traceparent from the incoming request and attach it to all downstream calls.
The RUM client must:
traceId when a page-load starts.traceId on all navigation events.traceId to the error event.traceId to the backend during a custom-event.Backend services use traceId to:
traceId.A user lands on /products/123. The RUM client emits:
{
"type": "page-load",
"traceId": "a1b2c3d4e5f67890a1b2c3d4e5f67890",
"timing": {
"firstContentfulPaint": 1800,
"largestContentfulPaint": 2400,
"load": 3800
}
}
The backend API logs a trace for this request:
{
"traceId": "a1b2c3d4e5f67890a1b2c3d4e5f67890",
"spans": [
{
"spanId": "1234567890abcdef",
"name": "GET /api/products/123",
"startTime": 1712345678901,
"duration": 450,
"attributes": {
"http.url": "/api/products/123",
"http.method": "GET"
}
},
{
"spanId": "1234567890abcde1",
"name": "GET /api/images/123",
"startTime": 1712345678901,
"duration": 820,
"attributes": {
"http.url": "/api/images/123",
"http.method": "GET"
}
}
]
}
A distributed tracing system can now:
firstContentfulPaint to the first backend span.largestContentfulPaint coincides with the image fetch.RUM must capture client-side errors and enrich them with user context.
The client must listen to error, unhandledrejection, and load events:
window.addEventListener('error', (event) => {
rum.send({
type: 'error',
message: event.error.message,
stack: event.error.stack,
timestamp: Date.now(),
source: 'client',
url: window.location.href,
userAgent: navigator.userAgent,
error: {
type: event.error.name,
file: event.error.fileName,
line: event.error.lineNumber,
column: event.error.columnNumber
}
});
});
window.addEventListener('unhandledrejection', (event) => {
rum.send({
type: 'error',
message: event.reason.message,
stack: event.reason.stack,
timestamp: Date.now(),
source: 'client',
url: window.location.href,
error: {
type: 'UnhandledRejection',
reason: event.reason
}
});
});
RUM events must include a userAttributes map that is updated during the session:
rum.setUserAttributes({
userId: 'u12345',
customerTier: 'premium',
language: 'fr',
deviceType: 'mobile',
theme: 'dark'
});
The client should:
pageView events on every navigation.interaction events for clicks, scrolls, and form inputs.{
"type": "interaction",
"timestamp": 1712345679100,
"pageId": "product-page",
"interactionType": "click",
"target": "button#add-to-cart",
"label": "Add to Cart",
"location": { "x": 560, "y": 1120 }
}
RUM data is used to define service-level objectives (SLOs) and drive alerting.
firstContentfulPaint > 1500ms → user perceives delay.largestContentfulPaint > 3000ms → page feels slow.timeToFirstByte > 800ms → backend is slow.errorRate > 0.05 → 5% of users encounter errors.pageLoadDuration > 5000ms → users abandon.Alerts are defined in a prometheus.yml-style configuration.
alerts:
- name: "Slow Page Load"
query: |
rate(rum_page_load_duration{environment="production"}[5m]) > 5000
duration: 5m
severity: "warning"
description: |
Average page load time exceeds 5 seconds over the last 5 minutes.
Current 5-minute average: {{ $value }}
labels:
service: "frontend"
team: "web"
annotations:
summary: "Page load time > 5s"
details: |
Page load time is slow in production.
Check the `largestContentfulPaint` and `firstContentfulPaint` metrics.
Review recent deployments for regressions.
Alerts trigger on:
firstContentfulPaint > 2000ms for 10 minutes.errorRate > 0.1 (10% of page loads have errors).load > 6000ms and firstInputDelay > 500ms.sampleRate: 0.5 is applied uniformly, so long sessions may have only one page-load event per 10 minutes, missing spikes.traceId on navigation: users navigate between pages, but traceId is not carried over from the initial page-load — causing fragmented traces.window.performance.now() is used for timing, but fetch calls use Date.now() for timestamp, leading to offset event sequences.stack strings cause ingestion to fail or drop events.userAttributes not persisted across page loads: the client initializes userAttributes only once, but updates are lost on navigation.sendOnPageHide not triggered: users leave the page without pageHide event firing — causing incomplete session data.SELECT * FROM rum_events WHERE projectId = 'ecommerce-frontend' AND environment = 'production'.rum_summary tables:avg_largest_contentful_painterror_rateavg_page_load_durationtop_errorsThese summaries power dashboards and drive SLO tracking.
The RUM pipeline is maintained via:
rum-processor service that:projectId.GeoIP2 database.custom fields into individual columns.rum-visualizer that renders user sessions as heatmaps, showing where users scroll, click, and wait.Every change to the RUM client is versioned and sent as clientVersion in events. This enables tracking adoption and identifying performance regressions from client updates.
This page was rewritten on 18 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy