@cloudcare/browser-rum 3.2.19 → 3.2.22

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 (222) hide show
  1. package/README.md +128 -194
  2. package/bundle/dataflux-rum.js +1 -1
  3. package/cjs/boot/buildEnv.js +2 -3
  4. package/cjs/boot/buildEnv.js.map +1 -1
  5. package/cjs/boot/perStartRum.js +9 -2
  6. package/cjs/boot/perStartRum.js.map +1 -1
  7. package/cjs/boot/recorderApi.js +1 -1
  8. package/cjs/boot/recorderApi.js.map +1 -1
  9. package/cjs/boot/rum.entry.js +1 -2
  10. package/cjs/boot/rum.entry.js.map +1 -1
  11. package/cjs/boot/rum.js.map +1 -1
  12. package/cjs/boot/rumPublicApi.js +1 -1
  13. package/cjs/boot/rumPublicApi.js.map +1 -1
  14. package/cjs/boot/startRecording.js +51 -39
  15. package/cjs/boot/startRecording.js.map +1 -1
  16. package/cjs/constants.js +13 -26
  17. package/cjs/constants.js.map +1 -1
  18. package/cjs/domain/assembly.js +6 -6
  19. package/cjs/domain/assembly.js.map +1 -1
  20. package/cjs/domain/configuration.js.map +1 -1
  21. package/cjs/domain/contexts/displayContext.js.map +1 -1
  22. package/cjs/domain/contexts/foregroundContexts.js +2 -4
  23. package/cjs/domain/contexts/foregroundContexts.js.map +1 -1
  24. package/cjs/domain/contexts/internalContext.js.map +1 -1
  25. package/cjs/domain/contexts/pageStateHistory.js +4 -8
  26. package/cjs/domain/contexts/pageStateHistory.js.map +1 -1
  27. package/cjs/domain/contexts/urlContexts.js +1 -2
  28. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  29. package/cjs/domain/contexts/viewContexts.js +1 -2
  30. package/cjs/domain/contexts/viewContexts.js.map +1 -1
  31. package/cjs/domain/deflate/deflateEncoder.js +1 -2
  32. package/cjs/domain/deflate/deflateEncoder.js.map +1 -1
  33. package/cjs/domain/deflate/deflateWorker.js +3 -5
  34. package/cjs/domain/deflate/deflateWorker.js.map +1 -1
  35. package/cjs/domain/firstInputPolyfill.js.map +1 -1
  36. package/cjs/domain/locationChangeObservable.js.map +1 -1
  37. package/cjs/domain/performanceObservable.js +1 -2
  38. package/cjs/domain/performanceObservable.js.map +1 -1
  39. package/cjs/domain/performanceUtils.js.map +1 -1
  40. package/cjs/domain/replay/record/elementsScrollPositions.js.map +1 -1
  41. package/cjs/domain/replay/record/mutationBatch.js +1 -2
  42. package/cjs/domain/replay/record/mutationBatch.js.map +1 -1
  43. package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
  44. package/cjs/domain/replay/record/observers.js +5 -6
  45. package/cjs/domain/replay/record/observers.js.map +1 -1
  46. package/cjs/domain/replay/record/privacy.js +2 -4
  47. package/cjs/domain/replay/record/privacy.js.map +1 -1
  48. package/cjs/domain/replay/record/record.js.map +1 -1
  49. package/cjs/domain/replay/record/serializationUtils.js +3 -6
  50. package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
  51. package/cjs/domain/replay/record/serialize.js +5 -7
  52. package/cjs/domain/replay/record/serialize.js.map +1 -1
  53. package/cjs/domain/replay/record/shadowRootsController.js +1 -2
  54. package/cjs/domain/replay/record/shadowRootsController.js.map +1 -1
  55. package/cjs/domain/replay/record/viewports.js +2 -4
  56. package/cjs/domain/replay/record/viewports.js.map +1 -1
  57. package/cjs/domain/replay/replayStats.js +1 -2
  58. package/cjs/domain/replay/replayStats.js.map +1 -1
  59. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +1 -1
  60. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  61. package/cjs/domain/replay/segmentCollection/segment.js +3 -3
  62. package/cjs/domain/replay/segmentCollection/segment.js.map +1 -1
  63. package/cjs/domain/replay/segmentCollection/segmentCollection.js +3 -4
  64. package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  65. package/cjs/domain/replay/startRecordBridge.js +19 -0
  66. package/cjs/domain/replay/startRecordBridge.js.map +1 -0
  67. package/cjs/domain/requestCollection.js.map +1 -1
  68. package/cjs/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
  69. package/cjs/domain/rumEventsCollection/actions/clickChain.js +2 -4
  70. package/cjs/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
  71. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +1 -2
  72. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  73. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +1 -2
  74. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
  75. package/cjs/domain/rumEventsCollection/actions/interactionSelectorCache.js +2 -4
  76. package/cjs/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
  77. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  78. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +2 -2
  79. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  80. package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  81. package/cjs/domain/rumEventsCollection/error/trackConsoleError.js.map +1 -1
  82. package/cjs/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
  83. package/cjs/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js.map +1 -1
  84. package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
  85. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  86. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js +2 -5
  87. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  88. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  89. package/cjs/domain/rumEventsCollection/view/interactionCountPolyfill.js +1 -2
  90. package/cjs/domain/rumEventsCollection/view/interactionCountPolyfill.js.map +1 -1
  91. package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  92. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -2
  93. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  94. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js +1 -2
  95. package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
  96. package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  97. package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
  98. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +1 -2
  99. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
  100. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +1 -2
  101. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  102. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +1 -2
  103. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  104. package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
  105. package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
  106. package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js +1 -2
  107. package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
  108. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
  109. package/cjs/domain/rumEventsCollection/view/trackViews.js +18 -12
  110. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  111. package/cjs/domain/rumSessionManager.js +5 -9
  112. package/cjs/domain/rumSessionManager.js.map +1 -1
  113. package/cjs/domain/tracing/ddtraceTracer.js.map +1 -1
  114. package/cjs/domain/tracing/getDocumentTraceId.js +1 -2
  115. package/cjs/domain/tracing/getDocumentTraceId.js.map +1 -1
  116. package/cjs/domain/tracing/jaegerTracer.js.map +1 -1
  117. package/cjs/domain/tracing/sampler.js +69 -0
  118. package/cjs/domain/tracing/sampler.js.map +1 -0
  119. package/cjs/domain/tracing/skywalkingTracer.js.map +1 -1
  120. package/cjs/domain/tracing/traceIdentifier.js.map +1 -1
  121. package/cjs/domain/tracing/tracer.js +8 -2
  122. package/cjs/domain/tracing/tracer.js.map +1 -1
  123. package/cjs/domain/tracing/w3cTraceParentTracer.js.map +1 -1
  124. package/cjs/domain/tracing/zipkinMultiTracer.js.map +1 -1
  125. package/cjs/domain/tracing/zipkinSingleTracer.js.map +1 -1
  126. package/cjs/domain/trackEventCounts.js.map +1 -1
  127. package/cjs/domain/usr/index.js +3 -6
  128. package/cjs/domain/usr/index.js.map +1 -1
  129. package/cjs/domain/waitPageActivityEnd.js +2 -4
  130. package/cjs/domain/waitPageActivityEnd.js.map +1 -1
  131. package/cjs/types/sessionReplayConstants.js +5 -10
  132. package/cjs/types/sessionReplayConstants.js.map +1 -1
  133. package/esm/boot/buildEnv.js +1 -1
  134. package/esm/boot/perStartRum.js +10 -3
  135. package/esm/boot/perStartRum.js.map +1 -1
  136. package/esm/boot/recorderApi.js +2 -2
  137. package/esm/boot/recorderApi.js.map +1 -1
  138. package/esm/boot/rum.js.map +1 -1
  139. package/esm/boot/rumPublicApi.js +1 -1
  140. package/esm/boot/rumPublicApi.js.map +1 -1
  141. package/esm/boot/startRecording.js +51 -38
  142. package/esm/boot/startRecording.js.map +1 -1
  143. package/esm/domain/assembly.js +6 -6
  144. package/esm/domain/configuration.js.map +1 -1
  145. package/esm/domain/contexts/displayContext.js.map +1 -1
  146. package/esm/domain/contexts/foregroundContexts.js.map +1 -1
  147. package/esm/domain/contexts/internalContext.js.map +1 -1
  148. package/esm/domain/contexts/pageStateHistory.js.map +1 -1
  149. package/esm/domain/contexts/urlContexts.js.map +1 -1
  150. package/esm/domain/contexts/viewContexts.js.map +1 -1
  151. package/esm/domain/deflate/deflateEncoder.js.map +1 -1
  152. package/esm/domain/deflate/deflateWorker.js +1 -1
  153. package/esm/domain/firstInputPolyfill.js.map +1 -1
  154. package/esm/domain/locationChangeObservable.js.map +1 -1
  155. package/esm/domain/performanceUtils.js.map +1 -1
  156. package/esm/domain/replay/record/elementsScrollPositions.js.map +1 -1
  157. package/esm/domain/replay/record/mutationBatch.js.map +1 -1
  158. package/esm/domain/replay/record/mutationObserver.js.map +1 -1
  159. package/esm/domain/replay/record/observers.js +5 -6
  160. package/esm/domain/replay/record/observers.js.map +1 -1
  161. package/esm/domain/replay/record/record.js.map +1 -1
  162. package/esm/domain/replay/record/serialize.js +4 -5
  163. package/esm/domain/replay/record/serialize.js.map +1 -1
  164. package/esm/domain/replay/record/shadowRootsController.js.map +1 -1
  165. package/esm/domain/replay/segmentCollection/buildReplayPayload.js +1 -1
  166. package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  167. package/esm/domain/replay/startRecordBridge.js +13 -0
  168. package/esm/domain/replay/startRecordBridge.js.map +1 -0
  169. package/esm/domain/requestCollection.js.map +1 -1
  170. package/esm/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
  171. package/esm/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
  172. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
  173. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  174. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  175. package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
  176. package/esm/domain/rumEventsCollection/error/trackConsoleError.js.map +1 -1
  177. package/esm/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
  178. package/esm/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js.map +1 -1
  179. package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
  180. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  181. package/esm/domain/rumEventsCollection/resource/resourceUtils.js +0 -1
  182. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  183. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  184. package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
  185. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  186. package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
  187. package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
  188. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  189. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  190. package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
  191. package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
  192. package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
  193. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
  194. package/esm/domain/rumEventsCollection/view/trackViews.js +15 -6
  195. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  196. package/esm/domain/rumSessionManager.js +2 -2
  197. package/esm/domain/rumSessionManager.js.map +1 -1
  198. package/esm/domain/tracing/ddtraceTracer.js.map +1 -1
  199. package/esm/domain/tracing/jaegerTracer.js.map +1 -1
  200. package/esm/domain/tracing/sampler.js +61 -0
  201. package/esm/domain/tracing/sampler.js.map +1 -0
  202. package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
  203. package/esm/domain/tracing/traceIdentifier.js.map +1 -1
  204. package/esm/domain/tracing/tracer.js +8 -2
  205. package/esm/domain/tracing/tracer.js.map +1 -1
  206. package/esm/domain/tracing/w3cTraceParentTracer.js.map +1 -1
  207. package/esm/domain/tracing/zipkinMultiTracer.js.map +1 -1
  208. package/esm/domain/tracing/zipkinSingleTracer.js.map +1 -1
  209. package/esm/domain/trackEventCounts.js.map +1 -1
  210. package/esm/domain/usr/index.js.map +1 -1
  211. package/esm/types/sessionReplayConstants.js +0 -1
  212. package/esm/types/sessionReplayConstants.js.map +1 -1
  213. package/package.json +35 -35
  214. package/src/boot/perStartRum.js +13 -4
  215. package/src/boot/recorderApi.js +6 -2
  216. package/src/boot/rumPublicApi.js +0 -1
  217. package/src/boot/startRecording.js +59 -47
  218. package/src/domain/replay/startRecordBridge.js +14 -0
  219. package/src/domain/rumEventsCollection/view/trackViews.js +18 -9
  220. package/src/domain/rumSessionManager.js +6 -2
  221. package/src/domain/tracing/sampler.js +65 -0
  222. package/src/domain/tracing/tracer.js +11 -5
package/README.md CHANGED
@@ -1,208 +1,142 @@
1
- # DataFlux RUM Web 端数据指标监控(V2 版本)
2
-
3
- ## 简介
4
-
5
- DataFlux RUM 能够通过收集各个应用的指标数据,以可视化的方式分析各个应用端的性能
6
-
7
- ### 你可以从下面几种方式中选择一种接入到你的 Web 应用中
8
-
9
- | 接入方式 | 简介 |
10
- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11
- | NPM | 通过把 SDK 代码一起打包到你的前端项目中,此方式可以确保对前端页面的性能不会有任何影响,不过可能会错过 SDK 初始化之前的的请求、错误的收集。 |
12
- | CDN 异步加载 | 通过 CDN 加速缓存,以异步脚本引入的方式,引入 SDK 脚本,此方式可以确保 SDK 脚本的下载不会影响页面的加载性能,不过可能会错过 SDK 初始化之前的的请求、错误的收集。 |
13
- | CDN 同步加载 | 通过 CDN 加速缓存,以同步脚本引入的方式,引入 SDK 脚本,此方式可以确保能够收集到所有的错误,资源,请求,性能指标。不过可能会影响页面的加载性能。 |
14
-
15
- ### NPM
16
-
17
- ```javascript
18
- import { datafluxRum } from '@cloudcare/browser-rum'
19
-
20
- datafluxRum.init({
21
- applicationId: '<DATAFLUX_APPLICATION_ID>',
22
- datakitOrigin: '<DATAKIT ORIGIN>'
23
- // env: 'production',
24
- // version: '1.0.0',
25
- })
26
- ```
27
-
28
- ### CDN 异步加载
29
-
30
- ```html
31
- <script>
32
- ;(function (h, o, u, n, d) {
33
- h = h[d] = h[d] || {
34
- q: [],
35
- onReady: function (c) {
36
- h.q.push(c)
37
- }
38
- }
39
- d = o.createElement(u)
40
- d.async = 1
41
- d.src = n
42
- n = o.getElementsByTagName(u)[0]
43
- n.parentNode.insertBefore(d, n)
44
- })(
45
- window,
46
- document,
47
- 'script',
48
- 'https://static.dataflux.cn/browser-sdk/v2/dataflux-rum.js',
49
- 'DATAFLUX_RUM'
50
- )
51
- DATAFLUX_RUM.onReady(function () {
52
- DATAFLUX_RUM.init({
53
- applicationId: '<DATAFLUX_APPLICATION_ID>',
54
- datakitOrigin: '<DATAKIT ORIGIN>'
55
- // env: 'production',
56
- // version: '1.0.0',
57
- })
58
- })
59
- </script>
60
- ```
61
-
62
- ### CDN 同步加载
63
-
64
- ```html
65
- <script
66
- src="https://static.dataflux.cn/browser-sdk/v2/dataflux-rum.js"
67
- type="text/javascript"
68
- ></script>
69
- <script>
70
- window.DATAFLUX_RUM &&
71
- window.DATAFLUX_RUM.init({
72
- applicationId: '<DATAFLUX_APPLICATION_ID>',
73
- datakitOrigin: '<DATAKIT ORIGIN>'
74
- // env: 'production',
75
- // version: '1.0.0',
76
- })
77
- </script>
78
- ```
79
-
80
- ## 配置
81
-
82
- ### 初始化参数
83
-
84
- | 参数 | 类型 | 是否必须 | 默认值 | 描述 |
85
- | ------------------------------------------------- | -------- | -------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
86
- | `applicationId` | String | 是 | | 从 dataflux 创建的应用 ID |
87
- | `datakitOrigin` | String | 是 | | datakit 数据上报 Origin 注释: `协议(包括://),域名(或IP地址)[和端口号]` 例如:https://www.datakit.com, http://100.20.34.3:8088 |
88
- | `env` | String | 是 | | web 应用当前环境, 如 prod:线上环境;gray:灰度环境;pre:预发布环境 common:日常环境;local:本地环 |
89
- | `service` | String | 否 | | web 应用对应的服务名称,可以用于关联 APM 服务相关 tag |
90
- | `version` | String | 是 | | web 应用的版本号 |
91
- | `sessionSampleRate` | Number | 否 | `100` | 指标数据收集百分比: `100`表示全收集,`0`表示不收集 |
92
- | `sessionOnErrorSampleRate` | Number | 否 | `0` | 错误会话补偿采样率:当会话未被 `sessionSampleRate` 采样时,若会话期间发生错误,则按此比例采集。此类会话将在错误发生时开始记录事件,并持续记录直到会话结束。 |
93
- | `sessionReplaySampleRate` | Number | 否 | `100` | 会话重放数据收集百分比: `100`表示全收集,`0`表示不收。 |
94
- | `sessionReplayOnErrorSampleRate` | Number | 否 | `0` | 错误会话重放补偿采样率:当会话未被 `sessionReplaySampleRate` 采样时,若会话期间发生错误,则按此比例采集。此类回放将记录错误发生前最多一分钟的事件,并持续记录直到会话结束。 |
95
- | 100 表示全收集;0 表示不收集。 |
96
- | `trackSessionAcrossSubdomains` | Boolean | 否 | `false` | 同一个域名下面的子域名共享缓存 |
97
- | `traceType` $\color{#FF0000}{新增}$ | Enum | 否 | `ddtrace` | 与 APM 采集工具连接的请求 header 类型,目前兼容的类型包括:`ddtrace`、`zipkin`、`skywalking_v3`、`jaeger`、`zipkin_single_header`、`w3c_traceparent`。_注: opentelemetry 支持 `zipkin_single_header`,`w3c_traceparent`,`zipkin`三种类型_ |
98
- | `traceId128Bit` $\color{#FF0000}{新增}$ | Boolean | 否 | `false` | 是否以 128 位的方式生成 `traceID`,与`traceType` 对应,目前支持类型 `zipkin`、`jaeger` |
99
- | `allowedDDTracingOrigins` $\color{#FF0000}{废弃}$ | Array | 否 | `[]` | 允许注入`ddtrace` 采集器所需 header 头部的所有请求列表。可以是请求的 origin,也可以是是正则,origin: `协议(包括://),域名(或IP地址)[和端口号]` 例如:`["https://api.example.com", /https:\/\/.*\.my-api-domain\.com/]` _该参数 旧的配置在新版本中做了兼容, 推荐使用`allowedTracingOrigins`_ |
100
- | `allowedTracingOrigins` $\color{#FF0000}{新增}$ | Array | 否 | `[]` | 允许注入 `trace` 采集器所需 header 头部的所有请求列表。可以是请求的 origin,也可以是是正则,origin: `协议(包括://),域名(或IP地址)[和端口号]` 例如:`["https://api.example.com", /https:\/\/.*\.my-api-domain\.com/]` |
101
- | `tracingSampleRate` | Number | 否 | `100` | 链路数据收集百分比: `100`表示全收集,`0`表示不收集 |
102
- | `trackInteractions` | Boolean | 否 | `false` | 是否开启用户行为采集 |
103
- | `isServerError` | Function | 否 | `function(request) {return false}` | 默认情况下,请求如果 `status code`>= 500 则定义为错误请求,会相应的采集为 `error` 指标数据。为满足部分场景可能并非是通过 `status code` 来判断业务请求的错误情况,提供可通过用户自定义的方式来判断请求是否为 error 请求,callback 参数为请求对应的相关返回参数: `{ isAborted: false, method:"get",response: "{...}",status: 200,url: "xxxx" }`, 如果方法返回为 true,则该请求相关数据会被采集为 `error` 指标, _该参数 方法返回结果必须为 Boolean 类型, 否则认为是无效参数_ |
104
- | `isIntakeUrl` | Function | 否 | `function(url) {return false}` | 自定义方法根据请求资源 url 判断是否需要采集对应资源数据,默认都采集。 返回:`false` 表示要采集,`true` 表示不需要采集 _该参数 方法返回结果必须为 Boolean 类型, 否则认为是无效参数_ |
105
- | `compressIntakeRequests` | Boolean | 否 | | 压缩 RUM 数据请求内容,以减少发送大量数据时的带宽使用量。压缩在 Worker 线程中完成。版本要求`>= 3.2.0` |
106
- | `workerUrl` | Sring | 否 | | sessionReplay 和 compressIntakeRequests 数据压缩都是在 webwork 线程中完成,所以默认情况下,在开启 csp 安全访问的情况下,需要允许 worker-src blob:; 该配置允许添加自行托管 worker 地址。版本要求`>= 3.2.0` |
107
-
108
- ## 问题
109
-
110
- ### 产生 Script error 消息的原因
111
-
112
- 在使用 DataFlux Web Rum Sdk 进行 Web 端错误收集的时候,经常会在`js_error`中看到 Script error. 这样的错误信息,同时并没有包含任何详细信息。
113
-
114
- ### 可能出现上面问题的原因
115
-
116
- 1. 用户使用的浏览器不支持错误的捕获 (概率极小)。
117
- 2. 出错的脚本文件是跨域加载到页面的。
118
- 对于用户浏览器不支持的情况,这种我们是无法处理的;这里主要解决跨域脚本错误无法收集的原因和解决方案。
119
-
120
- ### 原因
121
-
122
- 一般情况下脚本文件是使用 `<script>` 标签加载,对于同源脚本出错,在使用浏览器的 `GlobalEventHandlers API` 时,收集到的错误信息会包含详细的错误信息;当不同源脚本出错时,收集到的错误信息只有 `Script error.` 文本,这是由浏览器的同源策略控制的,也是正常的情况。对于非同源脚本我们只需要进行非同源资源共享(也称 HTTP 访问控制 / CORS)的操作即可。
123
-
124
- ### 解决方法
125
-
126
- #### 1.脚本文件直接存放在服务器
127
-
128
- 在服务器上静态文件输出时添加 Header
129
-
130
- ```
131
- Access-Control-Allow-Origin: *
132
- ```
133
-
134
- 在非同源脚本所在的 Script 标签上添加属 crossorigin="anonymous"
1
+ # Web Application Integration
135
2
 
136
- ```
137
- <script type="text/javascript" src="path/to/your/script.js" crossorigin="anonymous"></script>
138
- ```
3
+ ---
139
4
 
140
- #### 2.脚本文件存放 CDN 上
5
+ Guance application monitoring can collect metrics data from various web applications and analyze the performance of each web application endpoint in a visual manner.
141
6
 
142
- 在 CDN 设置中添加 Header
7
+ ## Prerequisites
143
8
 
144
- ```
145
- Access-Control-Allow-Origin: *
146
- ```
9
+ **Note**: If you have enabled the RUM Headless service, the prerequisites have been automatically configured for you, and you can directly integrate the application.
147
10
 
148
- 在非同源脚本所在的 Script 标签上添加属 crossorigin="anonymous"
11
+ - Install DataKit
12
+ - Configure the RUM Collector
13
+ - Ensure DataKit is accessible over the public network and has the IP geolocation database installed
149
14
 
150
- ```
151
- <script type="text/javascript" src="path/to/your/script.js" crossorigin="anonymous"></script>
152
- ```
15
+ ## Application Integration {#access}
153
16
 
154
- #### 3. 脚本文件从第三方加载
17
+ Log in to the Guance console, go to the **Synthetic Tests** page, click on the top-left corner **Create Application** to start creating a new application.
155
18
 
156
- 在非同源脚本所在的 Script 标签上添加属 crossorigin="anonymous"
19
+ - Guance provides **Public DataWay** to directly receive RUM data without installing the DataKit collector. Configuring `site` and `clientToken` parameters is sufficient. It supports uploading SourceMap directly from the console, allowing multiple files to be uploaded based on different versions and environments.
157
20
 
158
- ```
159
- <script type="text/javascript" src="path/to/your/script.js" crossorigin="anonymous"></script>
160
- ```
21
+ - Guance also supports receiving RUM data via **local environment deployment**, which requires meeting the prerequisites.
161
22
 
162
- ### 参考及扩展阅读
23
+ Web application integration can be done in three ways: NPM integration, asynchronous loading, and synchronous loading.
163
24
 
164
- [GlobalEventHandlers.onerror](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror)
25
+ | Integration Method | Description |
26
+ | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
27
+ | NPM | By bundling the SDK code into the frontend project, this method ensures no impact on the frontend page performance but may miss requests and errors before SDK initialization. |
28
+ | CDN Asynchronous | Through CDN caching and asynchronous script introduction, it ensures that the SDK script download does not affect page load performance but may miss requests and errors before SDK initialization. |
29
+ | CDN Synchronous | Through CDN caching and synchronous script introduction, it ensures capturing all errors, resources, requests, and performance metrics. However, it may impact page load performance. |
165
30
 
166
- [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
31
+ === "NPM"
167
32
 
168
- [The Script element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
33
+ ```javascript
34
+ import { datafluxRum } from '@cloudcare/browser-rum'
169
35
 
170
- [CORS settings attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)
171
-
172
- ### 资源数据(ssl, tcp, dns, trans,ttfb)收集不完整问题
173
-
174
- 在数据上报过程中,部分资源 timing 数据有可能收集不完整。比如 tcp,dns 数据没有收集上报。
175
-
176
- ### 出现上面问题原因
177
-
178
- 1. 比如 dns 数据没有收集到,有可能是您应用的这个资源请求是以`keep-alive`保持链接的,这种情况只有在你第一次请求的时候,会有创建链接的过程,之后的请求都会保持同一连接,不会再重新创建 tcp 连接。所以会出现 dns 数据没有的情况,或者数据为`0`。
179
- 2. 应用的资源是以跨域的形式加载到页面的,和你的网站并非是同源(主要原因)。
180
- 3. 浏览器不支持`Performance API`(极少数情况)
181
-
182
- ### 针对跨域资源的问题
183
-
184
- #### 1.资源文件直接存放在服务器
185
-
186
- 在服务器上资源文件输出时添加 Header
187
-
188
- ```
189
- Timing-Allow-Origin: *
190
- ```
191
-
192
- #### 2.资源文件存放 CDN 上
193
-
194
- 在 CDN 设置中添加 Header
195
-
196
- ```
197
- Timing-Allow-Origin: *
198
- ```
199
-
200
- ### 参考以及拓展
201
-
202
- [Coping_with_CORS](https://developer.mozilla.org/en-US/docs/Web/API/Resource_Timing_API/Using_the_Resource_Timing_API#Coping_with_CORS)
203
-
204
- [Resource Timing Standard; W3C Editor's Draft](https://w3c.github.io/resource-timing/)
205
-
206
- [Resource Timing practical tips; Steve Souders](http://www.stevesouders.com/blog/2014/08/21/resource-timing-practical-tips/)
207
-
208
- [Measuring network performance with Resource Timing API](http://googledevelopers.blogspot.ca/2013/12/measuring-network-performance-with.html)
36
+ datafluxRum.init({
37
+ applicationId: 'guance',
38
+ datakitOrigin: '<DataKit domain or IP>', // Required for DK integration
39
+ clientToken: 'clientToken', // Required for public OpenWay integration
40
+ site: 'public OpenWay address', // Required for public OpenWay integration
41
+ env: 'production',
42
+ version: '1.0.0',
43
+ sessionSampleRate: 100,
44
+ sessionReplaySampleRate: 70,
45
+ trackInteractions: true,
46
+ traceType: 'ddtrace', // Optional, default is ddtrace. Currently supports ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent
47
+ allowedTracingOrigins: ['https://api.example.com', /https:\/\/.*\.my-api-domain\.com/], // Optional, list of origins or regex patterns allowed to inject tracing headers
48
+ })
49
+ ```
50
+
51
+ === "CDN Asynchronous Loading"
52
+
53
+ ```javascript
54
+ <script>
55
+ (function (h, o, u, n, d) {
56
+ h = h[d] = h[d] || {
57
+ q: [],
58
+ onReady: function (c) {
59
+ h.q.push(c)
60
+ }
61
+ }
62
+ d = o.createElement(u)
63
+ d.async = 1
64
+ d.src = n
65
+ n = o.getElementsByTagName(u)[0]
66
+ n.parentNode.insertBefore(d, n)
67
+ })(
68
+ window,
69
+ document,
70
+ 'script',
71
+ 'https://static.guance.com/browser-sdk/v3/dataflux-rum.js',
72
+ 'DATAFLUX_RUM'
73
+ )
74
+ DATAFLUX_RUM.onReady(function () {
75
+ DATAFLUX_RUM.init({
76
+ applicationId: 'guance',
77
+ datakitOrigin: '<DataKit domain or IP>', // Required for DK integration
78
+ clientToken: 'clientToken', // Required for public OpenWay integration
79
+ site: 'public OpenWay address', // Required for public OpenWay integration
80
+ env: 'production',
81
+ version: '1.0.0',
82
+ sessionSampleRate: 100,
83
+ sessionReplaySampleRate: 70,
84
+ trackInteractions: true,
85
+ traceType: 'ddtrace', // Optional, default is ddtrace. Currently supports ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent
86
+ allowedTracingOrigins: ['https://api.example.com', /https:\/\/.*\.my-api-domain\.com/], // Optional, list of origins or regex patterns allowed to inject tracing headers
87
+ })
88
+ })
89
+ </script>
90
+ ```
91
+
92
+ === "CDN Synchronous Loading"
93
+
94
+ ```javascript
95
+ <script src="https://static.guance.com/browser-sdk/v3/dataflux-rum.js" type="text/javascript"></script>
96
+ <script>
97
+ window.DATAFLUX_RUM &&
98
+ window.DATAFLUX_RUM.init({
99
+ applicationId: 'guance',
100
+ datakitOrigin: '<DataKit domain or IP>', // Required for DK integration
101
+ clientToken: 'clientToken', // Required for public OpenWay integration
102
+ site: 'public OpenWay address', // Required for public OpenWay integration
103
+ env: 'production',
104
+ version: '1.0.0',
105
+ sessionSampleRate: 100,
106
+ sessionReplaySampleRate: 70,
107
+ trackInteractions: true,
108
+ traceType: 'ddtrace', // Optional, default is ddtrace. Currently supports ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent
109
+ allowedTracingOrigins: ['https://api.example.com', /https:\/\/.*\.my-api-domain\.com/], // Optional, list of origins or regex patterns allowed to inject tracing headers
110
+ })
111
+ </script>
112
+ ```
113
+
114
+ ## Configuration {#config}
115
+
116
+ ### Initialization Parameters
117
+
118
+ | Parameter | Type | Required | Default Value | Description |
119
+ | -------------------------------------- | -------------------------------- | -------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
120
+ | `applicationId` | String | Yes | | The application ID created in Guance. |
121
+ | `datakitOrigin` | String | Yes | | DataKit data reporting Origin. Format: `protocol (including: //), domain name (or IP address) [and port number]`. Example: [https://www.datakit.com](https://www.datakit.com); [http://100.20.34.3:8088](http://100.20.34.3:8088). |
122
+ | `clientToken` | String | Yes | | The data reporting token for openway access, obtained from the Guance console (required for public openway integration). |
123
+ | `site` | String | Yes | | The data reporting address for public openway access, obtained from the Guance console (required for public openway integration). |
124
+ | `env` | String | No | | The current environment of the web application, such as prod: production; gray: gray release; pre: pre-release; common: daily; local: local. |
125
+ | `version` | String | No | | The version number of the web application. |
126
+ | `service` | String | No | `browser` | The service name of the current application, defaults to `browser`, supports custom configuration. |
127
+ | `sessionSampleRate` | Number | No | `100` | Percentage of metric data collection:<br>`100` means full collection; `0` means no collection. |
128
+ | `sessionReplaySampleRate` | Number | No | `100` | Percentage of [Session Replay](../../docs/replay.md) data collection: <br>`100` means full collection; `0` means no collection. |
129
+ | `trackSessionAcrossSubdomains` | Boolean | No | `false` | Subdomains under the same domain share cache. |
130
+ | `usePartitionedCrossSiteSessionCookie` | Boolean | No | `false` | Whether to enable partitioned secure cross-site session cookie [more details](https://developers.google.com/privacy-sandbox/3pcd/chips?hl=en) |
131
+ | `useSecureSessionCookie` | Boolean | No | `false` | Use secure session cookies. This will disable RUM events sent over insecure (non-HTTPS) connections. |
132
+ | `traceType` | Enum | No | `ddtrace` | Configure the tracing tool type. Defaults to `ddtrace` if not set. Currently supports `ddtrace`, `zipkin`, `skywalking_v3`, `jaeger`, `zipkin_single_header`, `w3c_traceparent`.<br><br>:warning: <br>1. `opentelemetry` supports `zipkin_single_header`, `w3c_traceparent`, `zipkin`, `jaeger`.<br>2. This setting depends on `allowedTracingOrigins`.<br>3. Setting the corresponding `traceType` requires configuring the appropriate `Access-Control-Allow-Headers` for the API services. |
133
+ | `traceId128Bit` | Boolean | No | `false` | Whether to generate `traceID` using 128-bit format, corresponding to `traceType`, currently supports `zipkin`, `jaeger`. |
134
+ | `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
+ | `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. |
136
+ | `trackUserInteractions` | Boolean | No | `false` | Whether to enable user interaction tracking. |
137
+ | `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
+ | `beforeSend` | Function(event, context):Boolean | No | | Version requirement:`>3.1.2`. Intercept and modify data, refer to [Data Interception](../../docs/rum/before-send.md) |
139
+ | `storeContextsToLocal` | Boolean | No | | Version requirement:`>3.1.2`. Whether to cache custom user data locally in localStorage, e.g., data added via `setUser`, `addGlobalContext` APIs. |
140
+ | `storeContextsKey` | String | No | | Version requirement:`>3.1.18`. Define the key used to store data in localStorage, defaults to auto-generated if not specified. This parameter helps differentiate storage across different subpaths within the same domain. |
141
+ | `compressIntakeRequests` | Boolean | No | | Compress RUM data request content to reduce bandwidth usage when sending large amounts of data, reducing the number of data requests. Compression occurs in the WebWorker thread. For CSP security policy, refer to [CSP Security](../../docs/rum/content-security-policy.md#webwork). SDK version requirement `>= 3.2.0`. DataKit version requirement `>=1.60`. Deployment Plan version requirement `>= 1.96.178`. |
142
+ | `workerUrl` | String | No | | Both sessionReplay and compressIntakeRequests data compression occur in the WebWorker thread, so by default, in CSP secure access scenarios, you need to allow worker-src blob:. This configuration allows adding a self-hosted worker URL. For CSP security policy, refer to [CSP Security](../../docs/rum/content-security-policy.md#webwork). SDK version requirement `>= 3.2.0`. |