AWS CloudWatch Real User Monitoring (RUM) Web Client

2.1.0 · active · verified Tue Apr 21

The `aws-rum-web` client is a JavaScript library designed for real user monitoring (RUM) of web applications, integrating seamlessly with Amazon CloudWatch. It provides telemetry on critical user experience metrics such as page load timings, JavaScript errors, and HTTP request performance. The current stable version is 2.1.0, and the package maintains a relatively active release cadence with frequent minor and patch updates. Key differentiators include its tight integration into the AWS observability ecosystem, enabling developers to gain deeper insights into their web application's frontend performance and user behavior directly within CloudWatch, and its comprehensive data collection capabilities for various web vitals and errors.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the AWS CloudWatch RUM web client with a basic configuration to start collecting data. This example demonstrates how to instantiate the `AwsRum` class, providing essential parameters like application ID, version, and region, and handles potential initialization errors.

import { AwsRum, AwsRumConfig } from 'aws-rum-web';

// Configure your AWS RUM application details. Replace placeholders.
// Ensure your Identity Pool allows unauthenticated access to the RUM endpoint.
const rumConfig: AwsRumConfig = {
  applicationId: process.env.AWS_RUM_APP_ID ?? 'YOUR_APP_ID',
  applicationVersion: '1.0.0',
  id: process.env.AWS_RUM_MONITOR_ID ?? 'YOUR_MONITOR_ID',
  region: process.env.AWS_RUM_REGION ?? 'us-east-1',
  sessionSampleRate: 0.1, // Sample 10% of sessions for monitoring
  guestRoleArn: process.env.AWS_RUM_GUEST_ROLE_ARN ?? 'arn:aws:iam::123456789012:role/RUM_Guest_Role',
  endpoint: process.env.AWS_RUM_ENDPOINT ?? 'https://dataplane.rum.us-east-1.amazonaws.com',
  // Optional: add a plugin for session replay
  // plugins: [rrwebPlugin()],
  allowCookies: true,
  enableXRay: true
};

try {
  const rum = new AwsRum(rumConfig);
  // The RUM client automatically collects performance data, errors, and web vitals.
  // You can also manually record events or metrics:
  // rum.recordPageView({ name: '/my-custom-page' });
  // rum.recordEvent('UserLogin', { success: true, method: 'email' });
  console.log('AWS RUM client initialized successfully.');
} catch (error) {
  console.error('Failed to initialize AWS RUM client:', error);
}

view raw JSON →