Skip to content

Commit 0dcc0b8

Browse files
authored
Merge pull request #554 from flashcatcloud/docs/web-on-error-capture
docs(rum): document on-error capture for Web SDK 0.3.0
2 parents b1518a5 + a237c84 commit 0dcc0b8

11 files changed

Lines changed: 113 additions & 15 deletions

File tree

‎en/rum/best-practices/sampling.mdx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ The base rule uses `hash(userId) % 100` instead of `Math.random()`, which brings
309309

310310
## Best practice 3: full error capture with proportional sampling for the rest
311311

312-
A common requirement is "cut data volume to 20%, but never miss an error". Setting `sessionSampleRate` to 20 will not do it: sampling works per session, and a session that loses the draw reports nothing at all — errors included (rule 1). You would lose roughly four fifths of your errors along with the volume. The correct shape is to collect every session so no error is lost, then bucket on a stable key inside `beforeSend` so only the winning share keeps full data:
312+
<Note>
313+
Starting with Web SDK **0.3.0**, enable `sessionOnError` (and `sessionReplayOnError` if you need error replays) to capture error sessions without writing your own `beforeSend`; see [on-error session capture](/en/rum/sdk/web/advanced-config#on-error-session-capture) for configuration, billing, and limitations. The recipe below remains available for older versions or custom event filtering. Its failed-request filtering differs from the new options: a failed resource event alone does not trigger on-error capture.
314+
</Note>
315+
316+
A common requirement is "cut data volume to 20%, but never miss an error". Setting `sessionSampleRate` to 20 will not do it: sampling works per session, and a session that loses the draw reports nothing at all — errors included (rule 1). You would lose roughly four fifths of your errors along with the volume. The custom filtering recipe below collects every session so no error is lost, then buckets on a stable key inside `beforeSend` so only the winning share keeps full data:
313317

314318
- **Error events**: always kept — 100% of errors
315319
- **Failed requests**: always kept — 100% of API failures (HTTP 5xx and request failures are resource events, not error events)

‎en/rum/quickstart/app-management.mdx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,14 @@ The **Remote Configuration** tab lets you adjust collection and privacy paramete
307307
|------|------|------|
308308
| **Session sample rate** | Integer 0–100 (%) | Percentage of sessions collected. Leave it empty to skip delivering this field; clients keep the value set at SDK initialization |
309309
| **Session replay sample rate** | Integer 0–100 (%) | Percentage of sessions recorded by Session Replay. If empty, the SDK setting applies |
310+
| **On-error session capture** (`sessionOnError`) | On / Off / Use SDK setting | For sessions missed by session sampling, uploads up to the last minute of events on error and continues collection; requires Web SDK 0.3.0 or later |
311+
| **On-error replay capture** (`sessionReplayOnError`) | On / Off / Use SDK setting | For collected sessions missed by replay sampling, uploads buffered replay on error and continues recording; requires Web SDK 0.3.0 or later |
310312
| **Trace sample rate** | Integer 0–100 (%) | A second session-level sampling pass within already-collected sessions, deciding which sessions inject trace headers into eligible requests; the outcome is consistent within one session. Overall trace coverage is roughly *session sample rate × trace sample rate*. If empty, the SDK setting applies |
311313
| **Replay privacy level** | `mask` / `mask-user-input` / `allow` | Default masking of page content in Session Replay: `mask` obscures text and hides input values; `mask-user-input` keeps page text and hides only what users typed; `allow` records the page as it is. Loosening the level starts collecting content that was not collected before, and replays already uploaded cannot be retroactively masked. The console asks you to confirm again before publishing |
312314
| **Custom configuration keys** | Key–value pairs typed as string / number / boolean / JSON | Delivered to clients together with the remote configuration and read by your application code; the platform does not interpret them. Up to 5 keys; each key name is at most 64 bytes (counted in UTF-8, not characters), each value at most 4 KB and nesting at most 3 levels (objects and arrays each count one level), and all custom entries together at most 16 KB |
313315

316+
The two on-error options are independent: **On** delivers `true`, **Off** delivers `false`, and **Use SDK setting** omits the field so the corresponding `init()` option applies (off if unset). Browser applications require Web SDK 0.3.0 or later with `remoteConfigurationEnabled: true` at initialization. Turning off on-error capture does not affect sessions selected by ordinary sampling. See [Web SDK on-error session capture](/en/rum/sdk/web/advanced-config#on-error-session-capture) for scope, billing, and limitations.
317+
314318
iOS, Android, Flutter, and WeChat Mini Program applications also show the **Remote Configuration** tab, but their SDKs read only the **session sample rate** and **custom configuration keys** (none of them has Session Replay; the other values are neither delivered nor effective). Every SDK has to opt in with `remoteConfigurationEnabled: true` at initialization (off by default; an application that has not opted in never requests the configuration). On iOS this requires SDK 0.6.0 or later, see [iOS SDK Advanced Configuration](/en/rum/sdk/ios/advanced-config#remote-configuration); on Android it requires SDK 0.7.0 or later, see [Android SDK Advanced Configuration](/en/rum/sdk/android/advanced-config#remote-configuration-adjust-the-sample-rate-from-the-console); on Flutter it requires `flashcat_flutter_plugin` 0.2.0 or later, see [Flutter SDK Advanced Configuration](/en/rum/sdk/flutter/advanced-config#remote-configuration).
315319

316320
<Warning>

‎en/rum/quickstart/faq.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Confirm that the RUM SDK is correctly imported:
2020
<CodeGroup>
2121
```html CDN Integration
2222
<script
23-
src="https://static.flashcat.cloud/browser-sdk/v0.2.0/flashcat-rum.js"
23+
src="https://static.flashcat.cloud/browser-sdk/v0.3.0/flashcat-rum.js"
2424
type="text/javascript"
2525
></script>
2626
<script>

‎en/rum/sdk/web/advanced-config.mdx‎

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,50 @@ flashcatRum.init({
326326
```
327327

328328
<Warning>
329-
Sampled-out sessions will not collect any page views or related telemetry data.
329+
By default, sessions missed by ordinary sampling do not collect page views or related telemetry. Enabling on-error capture below allows buffered data to be uploaded when an error occurs.
330330
</Warning>
331331

332+
### On-error session capture
333+
334+
Web SDK **0.3.0 and later** can capture sessions and replays that report an error in addition to ordinary sampling. Both options are booleans, default to `false`, and apply only to sessions **not selected** by the corresponding sample rate. Sessions already selected keep their normal collection behavior.
335+
336+
| Option | Applies to | On the first error |
337+
|------|----------|----------------|
338+
| `sessionOnError` | Sessions not selected by `sessionSampleRate` | Uploads up to the last minute of buffered RUM events, then continues normal collection and upload |
339+
| `sessionReplayOnError` | Collected sessions whose replay was not selected by `sessionReplaySampleRate` | Uploads up to the last minute of buffered replay, then continues normal recording and upload |
340+
341+
For example, keep 20% of ordinary sessions and capture error sessions and their replays from the remainder:
342+
343+
```javascript
344+
flashcatRum.init({
345+
applicationId: "<YOUR_APPLICATION_ID>",
346+
clientToken: "<YOUR_CLIENT_TOKEN>",
347+
sessionSampleRate: 20,
348+
sessionReplaySampleRate: 0,
349+
sessionOnError: true,
350+
sessionReplayOnError: true
351+
});
352+
```
353+
354+
- **Buffer first, upload on error**: sessions missed by ordinary sampling collect into memory from the start and retain a limited history. The first qualifying error releases that history. The lookback is at most one minute, not a guaranteed full minute, and cannot recover data from before SDK initialization or recording started.
355+
- **No error means no storage or charge**: if a session retained by `sessionOnError` never reports an error, neither its events nor its replay are uploaded, and it incurs no session charge. With only `sessionReplayOnError` enabled, candidate replays without errors are not uploaded or charged, but RUM sessions selected by ordinary sampling are still uploaded and billed normally.
356+
- **Each captured session counts once**: ordinary sampling and on-error capture do not count the same session twice. On-error sessions count as actual sessions in statistics, without extrapolation by `1 / sessionSampleRate`, and repeated errors do not count them again.
357+
- **A RUM error event triggers capture**: examples include automatically captured JavaScript errors and errors reported with `addError()`. Errors discarded by `beforeSend` or rate limiting, and the SDK's own errors, do not trigger capture. A failed request or HTTP 5xx resource event alone does not trigger capture.
358+
359+
<Note>
360+
At `sessionSampleRate: 100`, `sessionOnError` has no additional effect; at `sessionReplaySampleRate: 100`, `sessionReplayOnError` has no additional effect. If `sessionSampleRate` is `0` and `sessionOnError` is off, enabling only `sessionReplayOnError` cannot collect any sessions. To keep only error sessions and their replays, set both sample rates to `0` and enable both on-error options.
361+
</Note>
362+
363+
#### Known limitations
364+
365+
- **SPA replays do not look back across views**: the replay reaches back only to the start of the view where the error occurred, up to one minute. RUM events can look back up to one minute across views.
366+
- **Leaving immediately after an error can lose history**: closing or navigating away within seconds of the first error can lose part of a large upload (roughly above 64 KiB) because browsers limit data sent at page exit. Compression does not guarantee delivery. The SDK sends views and errors first; older other events and the final view update may be lost.
367+
- **Buffering replay still has a performance cost**: a large, frequently changing DOM can overflow the buffer and repeatedly trigger full snapshots, adding main-thread work and shortening the available replay history. Prefer enabling only `sessionOnError` on such pages.
368+
- **Manual recording has no earlier replay history**: if you control recording with `startSessionReplayRecording()`, explicitly set `startSessionReplayRecordingManually: true`. In particular, with remote configuration enabled, the recorder may start automatically even when the initial replay sample rate is `0`. Do not rely on a rate of `0` to wait for consent. Actions before manual recording starts cannot be recovered.
369+
- **Withdrawing consent does not cancel an already-triggered upload**: if a session has already reported an error, withdrawing tracking consent still uploads its buffered data collected while consent was granted.
370+
371+
You can also change both options through [remote configuration](/en/rum/quickstart/app-management#remote-configuration).
372+
332373
## User Tracking Consent
333374

334375
To comply with privacy regulations like GDPR and CCPA, Flashduty RUM allows setting user tracking consent state during initialization:
@@ -511,7 +552,7 @@ flashcatRum.init({
511552
<Tab title="CDN Sync">
512553
```html
513554
<script
514-
src="https://static.flashcat.cloud/browser-sdk/v0.2.0/flashcat-rum.js"
555+
src="https://static.flashcat.cloud/browser-sdk/v0.3.0/flashcat-rum.js"
515556
type="text/javascript">
516557
</script>
517558
<script>
@@ -538,7 +579,7 @@ flashcatRum.init({
538579
h=h[d]=h[d]||{q:[],onReady:function(c){h.q.push(c)}}
539580
d=o.createElement(u);d.async=1;d.src=n
540581
n=o.getElementsByTagName(u)[0];n.parentNode.insertBefore(d,n)
541-
})(window,document,'script','https://static.flashcat.cloud/browser-sdk/v0.2.0/flashcat-rum.js','FC_RUM')
582+
})(window,document,'script','https://static.flashcat.cloud/browser-sdk/v0.3.0/flashcat-rum.js','FC_RUM')
542583
window.FC_RUM.onReady(function() {
543584
window.FC_RUM.init({
544585
applicationId: "<YOUR_APPLICATION_ID>",

‎en/rum/sdk/web/faq.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Confirm that the RUM SDK is correctly included:
2020
<CodeGroup>
2121
```html CDN Import
2222
<script
23-
src="https://static.flashcat.cloud/browser-sdk/v0.2.0/flashcat-rum.js"
23+
src="https://static.flashcat.cloud/browser-sdk/v0.3.0/flashcat-rum.js"
2424
type="text/javascript"
2525
></script>
2626
<script>

‎en/rum/sdk/web/sdk-integration.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Add the following code snippet to the `<head>` tag of each HTML page you want to
7070
window,
7171
document,
7272
"script",
73-
"https://static.flashcat.cloud/browser-sdk/v0.2.0/flashcat-rum.js",
73+
"https://static.flashcat.cloud/browser-sdk/v0.3.0/flashcat-rum.js",
7474
"FC_RUM"
7575
);
7676
window.FC_RUM.onReady(function () {
@@ -92,7 +92,7 @@ Add the following code snippet at the very beginning of the `<head>` tag (before
9292

9393
```html
9494
<script
95-
src="https://static.flashcat.cloud/browser-sdk/v0.2.0/flashcat-rum.js"
95+
src="https://static.flashcat.cloud/browser-sdk/v0.3.0/flashcat-rum.js"
9696
type="text/javascript"
9797
></script>
9898
<script>

‎zh/rum/best-practices/sampling.mdx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ RUM.enable(with: rumConfig)
309309

310310
## 最佳实践三:错误全量采集,其余数据按比例保留
311311

312-
一个常见的诉求是「把数据量降到 20%,但异常一条都不能漏」。直接把 `sessionSampleRate` 设成 20 做不到:采样以会话为单位,未命中的会话连错误也不上报(规则 1),异常会同步丢掉八成。正确做法是会话全量采集保证错误不漏,再在 `beforeSend` 里按稳定 key 分桶,只让中签的那部分保留完整数据:
312+
<Note>
313+
从 Web SDK **0.3.0** 起,可直接开启 `sessionOnError`(需要异常回放时同时开启 `sessionReplayOnError`)实现异常会话补采,无需自行编写 `beforeSend`;配置、计费和限制见[异常会话补采](/zh/rum/sdk/web/advanced-config#异常会话补采)。下文保留旧版或需要自定义事件过滤的方案;其中保留失败请求的逻辑与新版开关不同,单独的失败资源事件不会触发异常补采。
314+
</Note>
315+
316+
一个常见的诉求是「把数据量降到 20%,但异常一条都不能漏」。直接把 `sessionSampleRate` 设成 20 做不到:采样以会话为单位,未命中的会话连错误也不上报(规则 1),异常会同步丢掉八成。下面的自定义过滤方案通过会话全量采集保证错误不漏,再在 `beforeSend` 里按稳定 key 分桶,只让中签的那部分保留完整数据:
313317

314318
- **错误事件**:全部保留,异常 100%
315319
- **失败的请求**:全部保留,接口报错 100%(HTTP 5xx 与请求失败是资源事件,不是错误事件)

‎zh/rum/quickstart/app-management.mdx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,14 @@ Link 集成会从当前事件上下文中提取变量并替换到 URL 模板中
308308
|------|------|------|
309309
| **会话采样率** | 0–100 整数(%) | 采集会话的比例。留空表示不下发该项,各端沿用 SDK 初始化时设置的值 |
310310
| **会话回放采样率** | 0–100 整数(%) | 录制会话回放的比例。留空时沿用 SDK 设置 |
311+
| **异常会话补采**(`sessionOnError`) | 开 / 关 / 沿用 SDK 设置 | 对会话采样未抽中的会话,报错后补报最多最近一分钟的事件,并继续采集;仅支持 Web SDK 0.3.0 及以上 |
312+
| **异常回放补采**(`sessionReplayOnError`) | 开 / 关 / 沿用 SDK 设置 | 对已采集但回放采样未抽中的会话,报错后补报缓存回放并继续录制;仅支持 Web SDK 0.3.0 及以上 |
311313
| **Trace 采样率** | 0–100 整数(%) | 在已采集的会话中再按此比例做一次会话级采样,决定哪些会话为符合条件请求注入 trace 头;同一会话内的结果一致。整体 Trace 覆盖率约为「会话采样率 × Trace 采样率」。留空时沿用 SDK 设置 |
312314
| **回放脱敏级别** | `mask` / `mask-user-input` / `allow` | 会话回放对页面内容的默认遮蔽程度:`mask` 遮蔽文本并隐藏输入值;`mask-user-input` 保留页面文本、仅隐藏用户输入;`allow` 按原样录制。放宽级别会开始录制此前未采集的内容,且已上传的回放无法事后补充脱敏,发布前系统会再次确认 |
313315
| **自定义配置项** | 键值对,类型支持字符串 / 数字 / 布尔值 / JSON | 随远程配置下发到客户端、由应用代码读取,平台不解析其内容。最多 5 个;键名最长 64 字节(按 UTF-8 计,非字符数),单个值最大 4 KB,JSON 值最多嵌套 3 层(对象、数组各计一层),全部自定义项合计最大 16 KB |
314316

317+
两个异常补采开关独立设置:**开**下发 `true`,**关**下发 `false`,**沿用 SDK 设置**不下发该项,由 `init()` 中对应参数决定(未设置时默认关闭)。Browser 应用需使用 Web SDK 0.3.0 及以上,并在初始化时开启 `remoteConfigurationEnabled: true`。关闭补采不影响普通采样已抽中的会话。补采范围、计费与限制见 [Web SDK 异常会话补采](/zh/rum/sdk/web/advanced-config#异常会话补采)。
318+
315319
iOS、Android、Flutter 与微信小程序应用同样展示「远程配置」页签,但这几端的 SDK 仅读取**会话采样率**与**自定义配置项**两项(均无 Session Replay,其余配置不下发也不生效)。各端 SDK 都需要在初始化时开启 `remoteConfigurationEnabled: true`(默认关闭,未开启的应用不会请求配置);iOS 端需要 SDK 0.6.0 及以上,接入方式见 [iOS SDK 高级配置](/zh/rum/sdk/ios/advanced-config);Android 端需要 SDK 0.7.0 及以上,接入方式见 [Android SDK 高级配置](/zh/rum/sdk/android/advanced-config);Flutter 端需要 `flashcat_flutter_plugin` 0.2.0 及以上,接入方式见 [Flutter SDK 高级配置](/zh/rum/sdk/flutter/advanced-config)。
316320

317321
<Warning>

0 commit comments

Comments
 (0)