You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/rum/best-practices/sampling.mdx
+40-1Lines changed: 40 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -329,5 +329,44 @@ Sampling is an independent probabilistic draw, not a quota (rule 3). The more tr
329
329
</Accordion>
330
330
331
331
<Accordiontitle="Can I report only errors and nothing else?">
332
-
Sampling operates on whole sessions (rule 1), so "unsampled sessions report only errors" is not possible. Alternative: use business-defined custom sampling and treat "users who hit an error last time" as an always-sample cohort, raising your capture rate for error evidence.
332
+
Strictly reporting only errors is not possible — view events are the backbone of a session and cannot be turned off. But you can get very close, by combining two independent controls:
333
+
334
+
-**The sampling rate decides which sessions are collected.** It operates on whole sessions, and an unsampled session reports nothing at all, errors included (rule 1). So lowering the sampling rate is not a way to save volume — it drops your errors along with everything else.
335
+
-**The event switches decide which events each collected session reports.**`trackResources`, `trackLongTasks`, `trackUserInteractions` and `trackWebVitals` are independent of sampling and apply to every session that is collected.
336
+
337
+
So the right configuration for "show me errors and as little else as possible" is: set `sessionSampleRate` to 100 so no error is missed, then use the event switches to suppress non-error data. Resource events are usually the bulk of the volume, so trimming them pays off the most.
338
+
339
+
<Warning>
340
+
**Do not simply set `trackResources: false`.** In the browser, HTTP 5xx responses and failed requests are **not** error events — they are resource events carrying a `status_code`. RUM error events come only from JavaScript runtime exceptions, `console.error`, the browser Report API and manual `addError` calls. Turning resource collection off makes API failures disappear from the platform entirely, and those are often exactly the "errors" you care about most.
341
+
</Warning>
342
+
343
+
Keep resource collection on instead, and use `beforeSend` to discard only the successful requests:
344
+
345
+
```js
346
+
flashcatRum.init({
347
+
applicationId:"<APPLICATION_ID>",
348
+
clientToken:"<CLIENT_TOKEN>",
349
+
sessionSampleRate:100, // Collect every session so no error is missed
350
+
trackResources:true, // Must stay on, otherwise API failures are invisible
351
+
trackLongTasks:false,
352
+
trackUserInteractions:false,
353
+
trackWebVitals:false,
354
+
beforeSend: (event) => {
355
+
// Keep only failed requests; successful ones are discarded and cost nothing
356
+
if (event.type==="resource") {
357
+
conststatusCode=event.resource.status_code;
358
+
return statusCode ===0|| statusCode >=400;
359
+
}
360
+
returntrue;
361
+
},
362
+
});
363
+
```
364
+
365
+
Understand the three costs before adopting this setup:
366
+
367
+
-**View events are still reported.** At least one per page, plus throttled updates whenever metrics or event counts change, plus a keep-alive update every 5 minutes while the session is active. This baseline cannot be removed, and `beforeSend` cannot discard view events either.
368
+
-**Error evidence is reduced to a stack trace.** With `trackUserInteractions` off, you no longer know what the user clicked before the error, which makes investigation noticeably harder.
369
+
-**Traced requests are not affected by the resource switch.** Requests matching `allowedTracingUrls` are still reported even with resource collection off (flagged as not indexed, so they do not count toward volume), so traffic does not drop to zero.
370
+
371
+
If your goal is "errors first, but keep the evidence", business-defined custom sampling is the better fit: treat "users who hit an error last time" as an always-sample cohort, trading full session data for a higher error capture rate.
0 commit comments