@cloudcare/browser-rum 3.3.14 → 3.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +60 -0
  2. package/README.zh.md +48 -0
  3. package/bundle/dataflux-rum.js +1 -1
  4. package/cjs/boot/buildEnv.js +1 -1
  5. package/cjs/boot/perStartRum.js +3 -0
  6. package/cjs/boot/perStartRum.js.map +1 -1
  7. package/cjs/boot/recorderApi.js +72 -56
  8. package/cjs/boot/recorderApi.js.map +1 -1
  9. package/cjs/boot/rumPublicApi.js +35 -3
  10. package/cjs/boot/rumPublicApi.js.map +1 -1
  11. package/cjs/boot/startRecording.js +4 -4
  12. package/cjs/boot/startRecording.js.map +1 -1
  13. package/cjs/constants.js +8 -8
  14. package/cjs/constants.js.map +1 -1
  15. package/cjs/domain/assembly.js +14 -1
  16. package/cjs/domain/assembly.js.map +1 -1
  17. package/cjs/domain/configuration.js +62 -0
  18. package/cjs/domain/configuration.js.map +1 -1
  19. package/cjs/domain/deflate/deflateWorker.js +1 -1
  20. package/cjs/domain/encoderStreamId.js +2 -1
  21. package/cjs/domain/encoderStreamId.js.map +1 -1
  22. package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
  23. package/cjs/domain/replay/record/record.js +2 -3
  24. package/cjs/domain/replay/record/record.js.map +1 -1
  25. package/cjs/domain/replay/record/serializationUtils.js +8 -15
  26. package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
  27. package/cjs/domain/replay/record/serialize.js +14 -6
  28. package/cjs/domain/replay/record/serialize.js.map +1 -1
  29. package/cjs/domain/requestCollection.js +3 -1
  30. package/cjs/domain/requestCollection.js.map +1 -1
  31. package/cjs/domain/rumEventsCollection/error/errorCollection.js +6 -8
  32. package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  33. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +5 -0
  34. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  35. package/cjs/domain/rumSessionManager.js +3 -3
  36. package/cjs/domain/rumSessionManager.js.map +1 -1
  37. package/cjs/domain/tracing/tracer.js +5 -1
  38. package/cjs/domain/tracing/tracer.js.map +1 -1
  39. package/cjs/domain/visitorId/index.js +417 -0
  40. package/cjs/domain/visitorId/index.js.map +1 -0
  41. package/cjs/index.js +7 -0
  42. package/cjs/index.js.map +1 -1
  43. package/cjs/transport/startRumBatch.js +44 -3
  44. package/cjs/transport/startRumBatch.js.map +1 -1
  45. package/esm/boot/buildEnv.js +1 -1
  46. package/esm/boot/perStartRum.js +3 -0
  47. package/esm/boot/perStartRum.js.map +1 -1
  48. package/esm/boot/recorderApi.js +72 -56
  49. package/esm/boot/recorderApi.js.map +1 -1
  50. package/esm/boot/rumPublicApi.js +36 -4
  51. package/esm/boot/rumPublicApi.js.map +1 -1
  52. package/esm/boot/startRecording.js +4 -4
  53. package/esm/boot/startRecording.js.map +1 -1
  54. package/esm/constants.js +1 -8
  55. package/esm/constants.js.map +1 -1
  56. package/esm/domain/assembly.js +15 -2
  57. package/esm/domain/assembly.js.map +1 -1
  58. package/esm/domain/configuration.js +62 -1
  59. package/esm/domain/configuration.js.map +1 -1
  60. package/esm/domain/deflate/deflateWorker.js +1 -1
  61. package/esm/domain/encoderStreamId.js +2 -1
  62. package/esm/domain/encoderStreamId.js.map +1 -1
  63. package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
  64. package/esm/domain/replay/record/record.js +1 -2
  65. package/esm/domain/replay/record/record.js.map +1 -1
  66. package/esm/domain/replay/record/serializationUtils.js +8 -15
  67. package/esm/domain/replay/record/serializationUtils.js.map +1 -1
  68. package/esm/domain/replay/record/serialize.js +13 -5
  69. package/esm/domain/replay/record/serialize.js.map +1 -1
  70. package/esm/domain/requestCollection.js +4 -2
  71. package/esm/domain/requestCollection.js.map +1 -1
  72. package/esm/domain/rumEventsCollection/error/errorCollection.js +6 -8
  73. package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  74. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +5 -0
  75. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  76. package/esm/domain/rumSessionManager.js +3 -3
  77. package/esm/domain/rumSessionManager.js.map +1 -1
  78. package/esm/domain/tracing/tracer.js +6 -2
  79. package/esm/domain/tracing/tracer.js.map +1 -1
  80. package/esm/domain/visitorId/index.js +406 -0
  81. package/esm/domain/visitorId/index.js.map +1 -0
  82. package/esm/index.js +1 -0
  83. package/esm/index.js.map +1 -1
  84. package/esm/transport/startRumBatch.js +45 -4
  85. package/esm/transport/startRumBatch.js.map +1 -1
  86. package/package.json +4 -4
  87. package/src/boot/perStartRum.js +4 -0
  88. package/src/boot/recorderApi.js +73 -59
  89. package/src/boot/rumPublicApi.js +38 -4
  90. package/src/boot/startRecording.js +7 -3
  91. package/src/constants.js +1 -8
  92. package/src/domain/assembly.js +28 -2
  93. package/src/domain/configuration.js +154 -0
  94. package/src/domain/encoderStreamId.js +2 -2
  95. package/src/domain/replay/record/record.js +1 -2
  96. package/src/domain/replay/record/serializationUtils.js +10 -24
  97. package/src/domain/replay/record/serialize.js +25 -5
  98. package/src/domain/requestCollection.js +4 -1
  99. package/src/domain/rumEventsCollection/error/errorCollection.js +10 -8
  100. package/src/domain/rumEventsCollection/resource/resourceCollection.js +3 -0
  101. package/src/domain/rumSessionManager.js +8 -7
  102. package/src/domain/tracing/tracer.js +15 -2
  103. package/src/domain/visitorId/index.js +571 -0
  104. package/src/index.js +1 -0
  105. package/src/transport/startRumBatch.js +61 -3
  106. package/types/index.d.ts +23 -1
package/README.md CHANGED
@@ -111,6 +111,65 @@ Web application integration can be done in three ways: NPM integration, asynchro
111
111
  </script>
112
112
  ```
113
113
 
114
+ ## Visitor ID request header
115
+
116
+ The SDK can inject a stable anonymous Visitor ID into matching XHR and Fetch
117
+ requests and expose the same value as RUM `context.visitor_id`:
118
+
119
+ ```js
120
+ datafluxRum.init({
121
+ // ...
122
+ visitorId: {
123
+ enabled: true,
124
+ header: 'x-rum-visitor-id',
125
+ match: [
126
+ 'https://api.example.com/',
127
+ /^https:\/\/gateway\.example\.com\//,
128
+ function (url) {
129
+ return url.indexOf('/security/') !== -1
130
+ }
131
+ ],
132
+ ttlHours: 24
133
+ }
134
+ })
135
+ ```
136
+
137
+ `header` must be a lowercase writable request header and cannot overlap an
138
+ authentication, CSRF, signature, tracing header, or the SDK resource correlation
139
+ header `x-rum-resource-id`. `match` supports URL-prefix
140
+ strings, `RegExp`, and `(url) => boolean` functions. String prefixes only match
141
+ within their declared origin, so similarly prefixed hostnames are not matched.
142
+ Requests outside `match` retain their existing headers, including headers supplied
143
+ by `injectTraceHeader`. The SDK reserves `context.visitor_id` across global, view,
144
+ and event contexts; a matching Resource event keeps the ID sent with its request,
145
+ even if the ID is reset while the request is in flight. `beforeSend` can still
146
+ modify or remove context fields.
147
+ The default TTL is 24 hours. When local storage is unavailable, the SDK falls
148
+ back to session storage and then current-page memory without generating a new
149
+ value for every request. When multiple valid storage records exist, the newest
150
+ record is used so a refresh cannot restore the value from before a rotation. Call
151
+ `datafluxRum.resetVisitorId()` only after a confirmed logout or account switch.
152
+ Do not call it from repeatable 401 or unauthenticated-request branches, which
153
+ would continually rotate the bucket and bypass the limit.
154
+
155
+ In an allowed WebView, the SDK prefers the synchronous return value of
156
+ `window.FTWebViewJavascriptBridge.getVisitorid()` for request headers and RUM
157
+ context. Use a native SDK version that exposes this optional method; older versions may
158
+ not support it. Return the current App ID as 1–256 non-whitespace printable ASCII
159
+ characters. The value is used unchanged and is never stored in Web storage.
160
+ Native IDs ignore the Web TTL, and `resetVisitorId()` is a no-op while the bridge
161
+ returns a valid ID: the App owns rotation. Each read picks up App-side changes;
162
+ in-flight Resource events retain their request-time ID. Missing, invalid or
163
+ throwing getters, or disallowed hosts, fall back to the Web behavior above.
164
+ A bridge that becomes ready later is used on subsequent reads. Async native
165
+ bridges must expose a synchronously readable JS cache, not a Promise.
166
+
167
+ Cross-origin requests require the configured header in the API's CORS policy.
168
+ The ID is only a rate-limit bucket and observability correlation key, not an
169
+ authentication credential, tenant identity, or audit identity. Because clients
170
+ can forge the ID, keep any rate-limit mitigation period short to limit the
171
+ impact of one visitor reusing another visitor's ID.
172
+
114
173
  ## Configuration {#config}
115
174
 
116
175
  ### Initialization Parameters
@@ -133,6 +192,7 @@ Web application integration can be done in three ways: NPM integration, asynchro
133
192
  | `traceId128Bit` | Boolean | No | `false` | Whether to generate `traceID` using 128-bit format, corresponding to `traceType`, currently supports `zipkin`, `jaeger`. |
134
193
  | `allowedTracingOrigins` | Array | No | `[]` | List of origins or regex patterns allowed to inject tracing headers. Can be request origin or regex, origin format: `protocol (including: //), domain name (or IP address) [and port number]`. Example: <br>`["https://api.example.com", /https:\\/\\/._\\.my-api-domain\\.com/]`. |
135
194
  | `allowedTracingUrls` | Array | No | `[]` | URL matching list for requests associated with APM. Can be request URLs, regex, or match function, example: `["https://api.example.com/xxx", /https:\/\/.*\.my-api-domain\.com\/xxx/, function(url) {if (url === 'xxx') { return false} else { return true }}]`. This parameter extends `allowedTracingOrigins`, configuring either one is sufficient. |
195
+ | `visitorId` | Object | No | `{ enabled: false }` | Inject a stable anonymous Visitor ID into matching XHR and Fetch requests and expose the same value as RUM `context.visitor_id`. When enabled, `header` and a non-empty String/RegExp/Function `match` list are required; `ttlHours` defaults to 24. |
136
196
  | `trackUserInteractions` | Boolean | No | `false` | Whether to enable user interaction tracking. |
137
197
  | `actionNameAttribute` | String | No | | Version requirement:`>3.1.2`. Add custom attributes to elements to specify action names. For more details, refer to [Tracking User Actions](../../docs/rum/tracking-user-actions.md) |
138
198
  | `beforeSend` | Function(event, context):Boolean | No | | Version requirement:`>3.1.2`. Intercept and modify data, refer to [Data Interception](../../docs/rum/before-send.md) |
package/README.zh.md CHANGED
@@ -20,6 +20,54 @@ datafluxRum.init({
20
20
  datafluxRum.startSessionReplayRecording()
21
21
  ```
22
22
 
23
+ ## 访客标识请求头
24
+
25
+ 可以为命中的 XHR 和 Fetch 请求注入稳定、匿名且独立于链路追踪的访客标识,
26
+ 同时将相同值写入 RUM 事件的 `context.visitor_id`:
27
+
28
+ ```js
29
+ datafluxRum.init({
30
+ // ...
31
+ visitorId: {
32
+ enabled: true,
33
+ header: 'x-rum-visitor-id',
34
+ match: [
35
+ 'https://api.example.com/',
36
+ /^https:\/\/gateway\.example\.com\//,
37
+ function (url) {
38
+ return url.indexOf('/security/') !== -1
39
+ }
40
+ ],
41
+ ttlHours: 24
42
+ }
43
+ })
44
+ ```
45
+
46
+ - `header` 必须为合法的小写可写请求头,不能使用鉴权、CSRF、签名、链路追踪请求头或 SDK 资源关联头 `x-rum-resource-id`。
47
+ - `match` 支持 URL 前缀字符串、`RegExp` 和 `(url) => boolean` 函数;字符串只会在其声明的同一 Origin 内命中,不会匹配名称前缀相同的其他域名。
48
+ - 未命中 `match` 的请求保留原有请求头,包括 `injectTraceHeader` 提供的头。
49
+ - `context.visitor_id` 由 SDK 管理,全局、View 和事件自定义上下文中的同名字段不会覆盖它;匹配的 Resource 事件保留请求发起时的 ID。`beforeSend` 仍可修改或删除上下文字段。
50
+ - 默认有效期为 24 小时;优先持久化到 `localStorage`,不可用时依次降级到
51
+ `sessionStorage` 和当前页面内存,降级后也不会按请求重新生成;存在多级有效记录时使用最新记录,避免刷新后恢复轮转前的旧值。
52
+ - 用户成功退出登录或切换账户后调用 `datafluxRum.resetVisitorId()`;不要在 401、未认证请求等可能重复触发的失败分支调用,否则会持续换桶并绕过限流。
53
+ - 跨域请求会触发 CORS 预检,服务端必须允许该自定义请求头。
54
+ - 访客标识只能用于限流分桶和可观测性关联,不能用于鉴权、租户隔离或审计。
55
+ - 访客标识可被客户端伪造,限流处罚时间应保持较短,避免攻击者冒用其他访客 ID
56
+ 造成长时间误封。
57
+
58
+ ### WebView 与 App 统一
59
+
60
+ 开启 `visitorId.enabled` 后,若当前域名允许使用观测云 bridge,SDK 优先读取
61
+ `window.FTWebViewJavascriptBridge.getVisitorid()` 的同步返回值,原样用于请求头和
62
+ `context.visitor_id`。需使用包含该接口的移动 SDK 版本,返回当前原生 ID(1–256 个非空白可打印
63
+ ASCII 字符);仅接入旧版 App SDK 不代表已有此能力。
64
+
65
+ App ID 不写入 Web 存储,不受 Web `ttlHours` 影响;此时 Web `resetVisitorId()` 无操作,
66
+ 退出或切换账户后应由 App 统一轮转。SDK 每次读取最新原生 ID,在途 Resource 仍保留
67
+ 请求发起时的 ID。无方法、未就绪、返回非法值、读取异常或域名未获准时自动回退到上述
68
+ Web 生成逻辑;bridge 后续可用时自动采用 App ID。异步消息桥需先将原生 ID 同步到 JS
69
+ 缓存,再由该方法同步返回,不能直接返回 Promise。
70
+
23
71
  ## Session Replay
24
72
 
25
73
  启用 Session Replay 至少需要: