Sampling in Resource Monitor
The Resource Monitor, by default, sends a large volume of data. If it is not controlled, it causes performance issues in the customer's environment and in the Discover environment receiving the data.
From 12.2.4 onwards, the Resource Monitor configuration includes a new Sampling option, with a value range of 1 to 100. This setting controls the approximate percentage of sessions for which Resource Monitor data is captured and submitted as part of the payload. For example, a value of 100 captures data for all sessions, while a value of 10 captures data for roughly 10% of sessions, reducing load while still providing a representative sample of Resource Monitor data.
Configuration
In the following code sameple, add the highlighted section in the resourceMonitor
section of the code:
resourceMonitor:
{
responseTime: 50,
samplingPercent: 20, // ← Configurable sampling percentage; default 100
// ...
}How Session Sampling Works
- Page load check — When a page loads, the system checks sessionStorage to see whether a sampling decision already exists for the current session
- First visit in a session (no stored value)
- If sessionStorage is empty, the system generates a random number between 1 and 100.
- This random number is compared against the configured Sampling Percent value.
- If the random number is less than or equal to the Sampling Percent, the session is marked as sampled in; otherwise, it is marked as sampled out.
- The result is stored in sessionStorage as a flag: 1 for sampled in, 0 for sampled out.
- Subsequent pages/events in the same session
- On every later page view or event within the same session, the system checks sessionStorage again.
- If the stored value is 1, the session remains sampled in for its entire duration — Resource Monitor data continues to be captured and sent.
- If the stored value is 0, the session remains sampled out for its entire duration — no Resource Monitor data is sent.
- No new random number is generated as long as the session persists; the original decision is honored consistently.
- New tab or session cleared
- If the user opens a new tab, or the browser session/sessionStorage is otherwise cleared, the stored sampling flag is lost.
- Fresh session begins
- On the next page load under this new session, sessionStorage is empty again, so the process restarts from Step 2: a new random number is generated and a new sampling decision is made independently of the previous session.