Skip to main content

Real User Monitoring

Setup

Install the dependency:

npm install @logzio/browser

Configure LogzioRUM

Call LogzioRUM.init() to initialize the RUM client. This should be done as early as possible in your application lifecycle.

import { LogzioRUM } from '@logzio/browser';

LogzioRUM.init({
region: <<LOGZIO_REGION_CODE>>,
tokens: {
traces: <<LOGZIO_TRACES_TOKEN>>,
logs: <<LOGZIO_LOGS_TOKEN>>, // Required unless enable.errorTracking, enable.consoleLogs, enable.viewEvents, and enable.webVitals are all set to false
},
endpoint: {
url: "<<LOGZIO_RUM_URL>>",
},
service: {
name: <<SERVICE_NAME>>, // Optional
version: <<SERVICE_VERSION>>, // Optional
},
customAttributes: {
//// Optional, extra fields containing user metadata to be sent with each event
//// example:
// user.name: user.name,
// user.id: user.id,
// "user.role": user.role,

// recommended: add env field (prod, dev, staging...)
env_id: "prod"
},
});

Configuration Options

Parameter NameDescriptionRequired/OptionalDefault
regionThe Logz.io account region code (e.g., us, eu, au, uk, ca)Requiredus
tokens.tracesThe Logz.io traces shipping tokenRequired-
tokens.logsThe Logz.io logs shipping token. Required unless enable.errorTracking, enable.consoleLogs, enable.viewEvents, and enable.webVitals are all set to false.Required*-
endpoint.urlEndpoint URL to send the collected data to in OTLP.Required-
endpoint.addSuffixWhether to append data type suffixes (/traces, /logs) to the endpoint URL.Optionalfalse
service.nameThe name of the service being monitored.Optional""
service.versionThe version of the service being monitored.Optional""
session.maxDurationMsThe maximum duration of a session in ms.Optional4 * 60 * 60 * 1000 (4h)
session.timeoutMsIf a user is inactive for this duration, the session will end.Optional15 * 60 * 1000 (15m)
enable.userActionsEnable user actions tracking.Optionaltrue
enable.navigationEnables SPA route change detection and treats them as new views.Optionaltrue
enable.documentLoadEnables the initial page load span.Optionaltrue
enable.resourceLoadEnable resource loading tracking such as XHR, fetch, scripts, images.Optionaltrue
enable.errorTrackingEnable exceptions tracking.Optionaltrue
enable.frustrationDetectionEnable frustration detection such as rage clicks, dead clicks and heavy load times. Frustration signals will be marked on trace spans.Optionaltrue
enable.webVitalsEnable web vitals tracking (FCP, LCP, CLS, INP, TTFB). Web vitals will be emitted as logs.Optionaltrue
enable.viewEventsEnable view end log event which contains the duration to indicate the current session state.Optionalfalse
enable.consoleLogsEnable console logs tracking. If turned off, no console logs will be sent.Optionalfalse
environmentData.collectOSEnable collection of user operating system name, version and type information.Optionaltrue
environmentData.collectBrowserEnable collection of user browser name, version and engineOptionaltrue
environmentData.collectDeviceEnable collection of user device type and screen dimensionsOptionaltrue
environmentData.collectLanguageEnable collection of user language and timezoneOptionaltrue
customAttributesExtra fields containing data to be sent with each event. (such as user context)Optional{}
propagateTraceHeaderCorsUrlsA list of Backend URLs to propagate the trace header to.Optional[]
samplingRateThe rate in which spans are sampled.Optional100(%)
frustrationThresholds.rageClickCountThe number of clicks within rageClickIntervalMs to consider a click as a rage click.Optional3
frustrationThresholds.rageClickIntervalMsThe time interval in milliseconds to consider for rage clicks.Optional1000 (1s)
frustrationThresholds.heavyLoadThresholdMsThe time in milliseconds to consider a page load as heavy.Optional2000 (2s)
logLevelThe log level of the RUM library.Optional'info'

Dynamically inject attributes

You can dynamically inject attributes that will be added to all data generated by the library by using the LogzioRUM.setAttributes() method. This allows you to add or update attributes at runtime, which can be useful for capturing user-specific data or application state.

LogzioRUM.setAttributes({
...LogzioRUM.getAttributes(),
theme: 'dark',
});
note

Please note that the LogzioRUM.setAttributes() method will override any existing attributes.

Correlate Browser Traces with Backend Traces

To correlate browser traces with backend traces, you need to follow the below steps, to ensure that the traceparent header is sent with requests to your backend services.

Step 1

Configure the propagateTraceHeaderCorsUrls option with the URLs of your backend services. This will ensure that the traceparent header is sent with requests to these services.

LogzioRUM.init({
// ... other options
propagateTraceHeaderCorsUrls: [
'https://api.example.com',
'https://backend.example.com'
]
});

Step 2

The traceparent header is not CORS-safelisted, so you need to configure your backend to accept it and use it in your backend tracing implementation.

Collected Data

Web Vitals (Logs)

When enable.webVitals is set to true, the SDK collects and emits the following web vitals as log events:

MetricDescriptionUnit
FCP (First Contentful Paint)Time to first visible paintms
LCP (Largest Contentful Paint)Time until the largest visible element rendersms
CLS (Cumulative Layout Shift)Visual stability across the sessionscore (unitless)
INP (Interaction to Next Paint)Response time to next paint after user interactionsms
TTFB (Time to First Byte)Time from navigation start to first byte receivedms

Each web vital log includes detailed attribution data to help diagnose performance issues.

Frustration Signals (Traces)

When enable.frustrationDetection is set to true, the SDK detects and marks spans with frustration attributes:

Frustration TypeDescription
Dead ClickUser clicks on an element that doesn't trigger any visible action
Rage ClickMultiple rapid clicks on the same element (configurable threshold)
Error ClickClick followed immediately by an error
Heavy LoadPage or navigation load exceeds threshold (configurable)