Real User Monitoring Guide

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.

Instrumenting the Frontend

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.

Configuration

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'
  }
};

Data Sent

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.

Aggregating and Processing RUM Data

RUM data flows into a central ingestion service. The ingestion endpoint must:

curl -X POST https://ingest.example.com/events/rum \
  -H 'Content-Type: application/json' \
  -d '[{ ... }, { ... }]'

The service should:

Schema Requirements

All events must include:

Additional fields are optional but encouraged:

Correlating RUM with Backend Traces

To link front-end performance to backend operations, RUM events must carry a traceId and spanId.

Trace ID Propagation

When a frontend request is made (e.g., fetch('/api/products/123')), the client must:

traceparent: 00-0af765e27ed32446c4444a701d7c3981-5062c28d15d10348-01

The format is the W3C Trace Context standard:

00-<trace-id>-<span-id>-<flags>

The backend must extract traceparent from the incoming request and attach it to all downstream calls.

Linking Events

The RUM client must:

Backend services use traceId to:

Correlation Example

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:

Handling Errors and User Context

RUM must capture client-side errors and enrich them with user context.

Error Capture

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
    }
  });
});

Context Enrichment

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:

{
  "type": "interaction",
  "timestamp": 1712345679100,
  "pageId": "product-page",
  "interactionType": "click",
  "target": "button#add-to-cart",
  "label": "Add to Cart",
  "location": { "x": 560, "y": 1120 }
}

Monitoring and Alerting on RUM Metrics

RUM data is used to define service-level objectives (SLOs) and drive alerting.

Key Metrics

Alerting Rules

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:

Common Failures and Pitfalls

Maintenance and Iteration

These summaries power dashboards and drive SLO tracking.

The RUM pipeline is maintained via:

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.