Skip to main content

Sampling

Sampling

1. Basic Sampling - sample % of all sessions

CoralogixRum.init({
// ...
sessionConfig: {
sessionSampleRate: 50, // Percentage of overall sessions being tracked, defaults to 100%
},
});

2. Advanced Sampling - sample % of sessions, but always track sessions with errors

This configuration will ensure all sessions with errors are tracked, and a percentage of sessions without errors are also tracked.

CoralogixRum.init({
// ...
sessionConfig: {
sessionSampleRate: 50,
alwaysTrackSessionsWithErrors: true,
},
});

3. Exclude Specific Instrumentations from Sampling

Keep specific instrumentations running at 100% even when sessions are sampled out. This is useful when you want to reduce data volume with sampling but still capture all errors or custom logs.

CoralogixRum.init({
// ...
sessionConfig: {
sessionSampleRate: 20, // Only 20% of sessions are fully tracked
excludeFromSampling: ['custom'], // These will run at 100% regardless of sampling
},
});

4. Only Sessions with Errors

Track only sessions with errors, and send specific instrumentation data immediately even if error is not occurred. From Session recording perspective, the SDK will record approximately 10–60s(according to maxRecordTime property) before the error occurred.

CoralogixRum.init({
// ...
sessionConfig: {
onlyWithErrorConfig: {
enable: true, // Whether to track only sessions with errors, defaults to false
maxRumEvents: 5000, // Maximum number of cached RUM events to store in cache up until error is coming, defaults to 5000, max 20000
maxRecordTime: 10_000, // Maximum time in milliseconds to store last record events in cache before error occurred, defaults to 10000(10s), max 60000(1m)
/**
* Specifies the instrumentation data to be sent for sessions with errors, defaulting to web-vitals only.
* The instrumentation data will only be sent if it is enabled in the main configuration.
* This data will be sent immediately, even if no error has occurred.
*/
instrumentationsToSend: {
[CoralogixEventType.WEB_VITALS]: true,
// more instrumentation's can be added
// [CoralogixEventType.LONG_TASK]: true,
//...
},
},
},
});
Last updated on
On this page
Was this page helpful?