# Sampling

Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fuser-guides%2Frum%2Fsdk-installation%2Fjavascript%2Fbrowser-sdk%2Fconfiguration%2Fsampling.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fuser-guides%2Frum%2Fsdk-installation%2Fjavascript%2Fbrowser-sdk%2Fconfiguration%2Fsampling.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

### Sampling[​](#sampling "Direct link to Sampling")

#### 1. Basic Sampling - sample % of all sessions[​](#1-basic-sampling---sample--of-all-sessions "Direct link to 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[​](#2-advanced-sampling---sample--of-sessions-but-always-track-sessions-with-errors "Direct link to 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[​](#3-exclude-specific-instrumentations-from-sampling "Direct link to 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[​](#4-only-sessions-with-errors "Direct link to 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,

        //...

      },

    },

  },

});
```
