React
Monitor your React application with the Last9 Web RUM SDK to send browser traces, errors, and performance data to Last9
Use the Last9 Web RUM SDK to monitor your React application. The SDK is built on OpenTelemetry and captures page loads, Core Web Vitals, network requests, JavaScript errors, and user interactions directly from your users’ browsers.
Prerequisites
- Client Token: A
Client — Web Browsertoken from Ingestion Tokens. Create separate tokens for development (restricted tolocalhostorigins) and production (restricted to your production domains). - Applications Base URL: Your base URL from the Applications integration page.
Setup
-
Add the SDK script
Add the RUM SDK script to the
<head>section of yourindex.html(public/index.htmlfor Create React App,index.htmlfor Vite):<script src="https://cdn.last9.io/rum-sdk/builds/stable/v2/l9.umd.js"></script> -
Initialize the SDK
Initialize the SDK once in your root component:
import { useEffect } from "react";function App() {useEffect(() => {L9RUM.init({baseUrl: "https://your-base-url",headers: {clientToken: "your-client-token",},resourceAttributes: {serviceName: "your-app-name",deploymentEnvironment: "production",appVersion: "1.0.0",},});}, []);return <>{/* Your app components */}</>;}export default App;The SDK script defines a global
L9RUMobject. Declare it so TypeScript recognizes it, for example insrc/global.d.ts:declare const L9RUM: any;Then initialize the SDK in your root component:
import { useEffect } from "react";function App() {useEffect(() => {L9RUM.init({baseUrl: "https://your-base-url",headers: {clientToken: "your-client-token",},resourceAttributes: {serviceName: "your-app-name",deploymentEnvironment: "production",appVersion: "1.0.0",},});}, []);return <>{/* Your app components */}</>;}export default App;The SDK ignores repeated
initcalls, so React Strict Mode running effects twice in development is safe. -
Identify users (optional)
L9RUM.identify({ id, email, name, fullName, roles }); // on loginL9RUM.clearUser(); // on logout
Configuration
To configure sampling, error filtering, network tracking, backend trace correlation, and user interaction tracking, see the Web RUM SDK reference.
Verification
Run your application and load a few pages, then navigate to Discover > Applications and confirm data appears within 2-3 minutes.
The SDK samples 40% of sessions by default. While testing, set sampleRate: 100 in L9RUM.init so every session is captured.
If no data appears, set debug: true in L9RUM.init and check the browser console and the network tab for failed requests to your base URL. See Troubleshooting for common causes.