@blueking/open-telemetry 0.0.13 → 0.0.15
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.
- package/README.md +170 -554
- package/dist/bk-rum.global.js +9 -9
- package/dist/bk-rum.global.js.map +1 -1
- package/dist/core/action-activity.d.ts +28 -0
- package/dist/core/config.d.ts +113 -93
- package/dist/core/page-activity.d.ts +14 -0
- package/dist/core/plugin.d.ts +23 -6
- package/dist/core/processor.d.ts +25 -4
- package/dist/core/request-timing.d.ts +5 -0
- package/dist/core/runtime-context.d.ts +51 -3
- package/dist/core/sampling.d.ts +5 -1
- package/dist/core/sdk.d.ts +29 -10
- package/dist/core/url.d.ts +4 -1
- package/dist/index.d.ts +12 -14
- package/dist/index.js +2184 -1175
- package/dist/index.js.map +1 -1
- package/dist/plugins/action.d.ts +6 -2
- package/dist/plugins/activity.d.ts +6 -0
- package/dist/plugins/blank-screen.d.ts +17 -0
- package/dist/plugins/common.d.ts +11 -3
- package/dist/plugins/device.d.ts +2 -0
- package/dist/plugins/long-task.d.ts +3 -12
- package/dist/plugins/page-view.d.ts +1 -0
- package/dist/plugins/request-body.d.ts +14 -0
- package/dist/plugins/resource.d.ts +17 -1
- package/dist/plugins/session-state.d.ts +18 -0
- package/dist/plugins/session.d.ts +4 -4
- package/dist/plugins/web-vitals.d.ts +74 -0
- package/dist/schema/attributes.d.ts +31 -10
- package/dist/schema/span.d.ts +4 -12
- package/package.json +3 -7
- package/skills/bk-rum-otele/SKILL.md +34 -33
- package/skills/bk-rum-otele/evals/evals.json +1 -1
- package/skills/bk-rum-otele/references/api.md +45 -13
- package/skills/bk-rum-otele/references/concepts.md +38 -112
- package/skills/bk-rum-otele/references/configuration.md +135 -228
- package/skills/bk-rum-otele/references/custom-plugin.md +8 -5
- package/skills/bk-rum-otele/references/data-model.md +13 -8
- package/skills/bk-rum-otele/references/framework-integration.md +25 -17
- package/skills/bk-rum-otele/references/getting-started.md +27 -87
- package/skills/bk-rum-otele/references/plugins.md +165 -99
- package/skills/bk-rum-otele/references/privacy.md +42 -33
- package/skills/bk-rum-otele/references/telemetry-reference.md +73 -44
- package/skills/bk-rum-otele/references/troubleshooting.md +72 -38
- package/dist/plugins/http-body.d.ts +0 -3
- package/dist/plugins/route-timing.d.ts +0 -2
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
## 命名规则
|
|
10
10
|
|
|
11
11
|
- **信号名**:`browser.*` 表示内置浏览器事件(如 `browser.web_vital`);`action.<type>`、`custom.<name>` 是运行期动态拼接;`csp.violation`、`websocket.*` 使用领域前缀。
|
|
12
|
-
- **属性 key**:沿用 OpenTelemetry 语义约定的字段用点号(如 `http.request.method`、`exception.type`、`view.id`、`session.id`、`
|
|
12
|
+
- **属性 key**:沿用 OpenTelemetry 语义约定的字段用点号(如 `http.request.method`、`exception.type`、`view.id`、`session.id`、`browser.name`);跨类型检索字段使用下划线(如 `span_type`、`result`、`target_label`)。字段常量集中定义在 `src/schema/attributes.ts`。
|
|
13
13
|
|
|
14
14
|
## 公共上下文属性
|
|
15
15
|
|
|
@@ -17,44 +17,42 @@
|
|
|
17
17
|
|
|
18
18
|
| key | 类型 | 说明 | 低基数 |
|
|
19
19
|
| --- | --- | --- | --- |
|
|
20
|
-
| `service.name` | string | 应用名(`
|
|
21
|
-
| `service.version` | string | 应用版本(`
|
|
22
|
-
| `deployment.environment.name` | string | 环境(`
|
|
20
|
+
| `service.name` | string | 应用名(`application.name`) | 是 |
|
|
21
|
+
| `service.version` | string | 应用版本(`application.version`,可选) | 是 |
|
|
22
|
+
| `deployment.environment.name` | string | 环境(`application.environment`) | 是 |
|
|
23
23
|
| `rum.provider` | string | 固定 `blueking` | 是 |
|
|
24
24
|
| `telemetry.sdk.language` | string | 固定 `webjs` | 是 |
|
|
25
25
|
| `user.id` | string | 接入方提供,原样透传 | 否 |
|
|
26
26
|
| `session.id` | string | session 插件生成/轮换 | 否 |
|
|
27
27
|
| `session.has_replay` | boolean | 当前固定 `false` | 是 |
|
|
28
|
-
| `view.id` | string |
|
|
28
|
+
| `view.id` | string | View 管理器生成的实例 ID | 否 |
|
|
29
|
+
| `view.name` | string | 自动模式默认使用路由分组;手动模式可指定 | 是 |
|
|
29
30
|
| `view.url` | string | 当前 view URL(已脱敏) | 否 |
|
|
30
31
|
| `view.url_path_group` | string | 低基数路由模板 | 是 |
|
|
31
|
-
| `view.loading_type` | string | `initial_load` / `route_change` | 是 |
|
|
32
|
-
| `
|
|
33
|
-
| `
|
|
34
|
-
| `
|
|
32
|
+
| `view.loading_type` | string | `initial_load` / `route_change` / `session_renewal` / `bf_cache` | 是 |
|
|
33
|
+
| `device.type` | string | `mobile` / `desktop` | 是 |
|
|
34
|
+
| `browser.name` / `browser.version` | string | 浏览器信息 | 是 |
|
|
35
|
+
| `os.name` | string | 操作系统 | 是 |
|
|
35
36
|
| `network.effective_type` | string | 网络质量(`4g` 等) | 是 |
|
|
36
37
|
|
|
37
|
-
> span 还会带上 `span_type` / `span_subtype` / `result` / `error_type` / `event_label` / `target_label` 等归一字段(见下方[归一字段](#归一字段)
|
|
38
|
+
> span 还会带上 `span_type` / `span_subtype` / `result` / `error_type` / `event_label` / `target_label` 等归一字段(见下方[归一字段](#归一字段))。接入方可通过 `context.attributes.page` 注入额外的页面属性。
|
|
38
39
|
|
|
39
40
|
## Span 清单
|
|
40
41
|
|
|
41
42
|
| span 名 | span_type | 来源 | 关键属性 | 备注 |
|
|
42
43
|
| --- | --- | --- | --- | --- |
|
|
43
|
-
| `browser.view` | `document` / `route` |
|
|
44
|
-
| `
|
|
45
|
-
| `
|
|
46
|
-
| `documentLoad` / `documentFetch` / `resourceFetch` | `document` / `resource` | documentLoad instrumentation | `trace_scene=page_load` | span 名由官方探针决定 |
|
|
47
|
-
| `browser.resource` | `resource` | resource 插件 | `url.full`、`initiator_type`、`transfer_size`、`next_hop_protocol`、`cache_hit`、`resource.encoded_body_size`、`resource.decoded_body_size` | |
|
|
44
|
+
| `browser.view` | `document` / `route` | View 管理器 | `view.name`、`view.loading_time`、`view.loading_time.source`、`url.previous`、`event.source`、`view.end_reason` | 有持续时间,下一次 View 或 pagehide 时结束 |
|
|
45
|
+
| `HTTP <METHOD>` | `resource` | request 采集 | `resource.type=fetch\|xhr`、`resource.url`、`resource.method`、`resource.status_code`、网络阶段 events | span kind 为 CLIENT;Fetch/XHR 共用同一实现 |
|
|
46
|
+
| `browser.resource` | `resource` | resource 插件 | `resource.type`、`resource.url`、`resource.duration`、网络阶段、`resource.render_blocking_status`、`resource.protocol`、`resource.cache.hit` | 仅静态资源,跳过 Fetch/XHR |
|
|
48
47
|
| `browser.web_vital` | `vital` | webVitals 插件 | `vital.metric`、`vital.value`、`vital.rating`、`vital.id`、`rum.navigation.type`、`vital.<lcp\|cls\|inp\|fcp\|ttfb>.*` | 每个指标一条 |
|
|
49
|
-
| `browser.blank_screen` | `error` | blankScreen
|
|
48
|
+
| `browser.blank_screen` | `error` | blankScreen 插件(二次确认白屏时) | `blank_screen.empty_ratio`、`blank_screen.reason`、`blank_screen.root_selector`、`blank_screen.root_found`、`blank_screen.*_sample_count`、`blank_screen.center_element` | 每个 View 最多一条 |
|
|
50
49
|
| `browser.error` | `error` | error 插件(`window.error`) | `exception.*`、`error.source=window.error`、`error.window_count`、`code.filepath`、`code.lineno`、`code.column`、`error.cross_origin` | |
|
|
51
50
|
| `browser.unhandledrejection` | `error` | error 插件(Promise 异常) | `exception.*`、`error.source=unhandledrejection` | |
|
|
52
51
|
| `browser.resource_error` | `error` | error 插件(资源加载失败) | `exception.*`、`error.source=resource`、`url.full`、`html.tag` | |
|
|
53
|
-
| `browser.long_task` | `longtask` | longTask 插件 | `
|
|
54
|
-
| `browser.route_change` | `route` | routeTiming 插件 | `url.full`、`url.previous`、`route.change.source`、`target_value`(耗时) | |
|
|
52
|
+
| `browser.long_task` | `longtask` | longTask 插件 | `long_task.id`、`long_task.entry_type`、`long_task.start_time`、`long_task.duration`、`long_task.blocking_duration`、`long_task.culprit`、`long_task.script.count`、`target_value` | LoAF 脚本详情写入 `long_task.script` Span Event |
|
|
55
53
|
| `csp.violation` | `error` | cspViolation 插件 | `csp.blocked_uri`、`csp.violated_directive`、`csp.effective_directive`、`csp.source_file`、`csp.line_number`、`csp.status_code`、`csp.fingerprint`、`csp.window_count`、`csp.original_policy`(窗口首条) | |
|
|
56
54
|
| `websocket.connect` | `custom` | websocket 插件(仅建连阶段) | `url.full`、`url.scheme`、`server.address`、`network.protocol.name=websocket`、`target_domain` | 长连接生命周期不绑定 span |
|
|
57
|
-
| `action
|
|
55
|
+
| `action.click` / `action.custom` | `action` | action 插件 / `reportAction()` | `action.id/name/type/target.*`、`action.loading_time`、`action.frustration.*`、`action.*.count` | 自动点击或手动动作;挫败信号仅自动点击 |
|
|
58
56
|
| `custom.<name>` | `custom` | `reportCustomEvent()` / 自定义插件 | `rum.custom.name`、业务自定义属性 | 带 `error` 时附 `exception.*` |
|
|
59
57
|
|
|
60
58
|
## Metric 清单
|
|
@@ -63,16 +61,17 @@
|
|
|
63
61
|
| --- | --- | --- | --- | --- |
|
|
64
62
|
| `browser.web_vital.cls` | Histogram | `1` | `vital.metric`、`vital.rating`、`rum.navigation.type`、`view.url_path_group` | webVitals |
|
|
65
63
|
| `browser.web_vital.duration` | Histogram | `ms` | 同上(FCP/INP/LCP/TTFB 靠 `vital.metric` 区分) | webVitals |
|
|
66
|
-
| `browser.
|
|
67
|
-
| `browser.
|
|
64
|
+
| `browser.view.loading_time` | Histogram | `ms` | `view.url_path_group`、`view.loading_type` | View 管理器,View 结束时记录最终值 |
|
|
65
|
+
| `browser.blank_screen.count` | Counter | - | `view.url_path_group`、`blank_screen.root_selector`、`blank_screen.reason` | blankScreen |
|
|
66
|
+
| `browser.long_task.count` | Counter | - | `view.url_path_group`、`long_task.entry_type` | longTask |
|
|
68
67
|
| `browser.long_task.duration` | Histogram | `ms` | 同上 | longTask |
|
|
69
|
-
| `browser.
|
|
68
|
+
| `browser.long_task.blocking_duration` | Histogram | `ms` | 同上 | longTask,仅 LoAF |
|
|
70
69
|
| `browser.websocket.message.count` | Counter | - | `server.address`、`url.scheme`、`websocket.direction`(in/out) | websocket |
|
|
71
70
|
| `browser.websocket.message.bytes` | Counter | `By` | 同上 | websocket |
|
|
72
71
|
| `browser.websocket.error.count` | Counter | - | `server.address`、`url.scheme`、`websocket.error.phase`(connect/runtime) | websocket |
|
|
73
72
|
| `browser.websocket.connect.duration` | Histogram | `ms` | `server.address`、`url.scheme` | websocket,仅成功建连 |
|
|
74
73
|
|
|
75
|
-
> 各 metric
|
|
74
|
+
> 各 metric 只会合并 `context.attributes.metric` hook 返回的自定义低基数维度,不会合并 `context.attributes.page`,也不会携带 `session.id`、`view.id` 或 `action.id`。精确 View 关联请查询对应 span 或 View Snapshot Log。**metric 维度务必保持低基数**,不要把 URL、订单号、用户输入等放进来。
|
|
76
75
|
|
|
77
76
|
## Log 事件清单
|
|
78
77
|
|
|
@@ -80,8 +79,8 @@
|
|
|
80
79
|
| --- | --- | --- | --- |
|
|
81
80
|
| `session.start` | INFO | session 插件(首次新建) | `session.id`、`session.start_time`、`session.rotate.reason=init` |
|
|
82
81
|
| `session.rotate` | INFO | session 插件(轮换) | + `session.previous_id`、`session.rotate.reason`(`inactivity` / `maxLifetime`) |
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
82
|
+
| `browser.view` | INFO | View 管理器 | `view.snapshot.type=create\|update\|final`、`view.document_version`、`view.duration`、`view.is_active`、`view.loading_time` |
|
|
83
|
+
| `browser.request.body` | ERROR(错误请求)/ INFO(`capture: 'all'` 的成功请求) | request instrumentation(仅显式配置 `request.body`) | `trace.id`、`span.id`、`request.body` / `response.body`、`*.body.content_type`、`*.body.truncated` |
|
|
85
84
|
| `websocket.error` | ERROR | websocket 插件 | `url.full`、`websocket.error.phase`、`websocket.error.window_count` |
|
|
86
85
|
| `websocket.close` | INFO | websocket 插件 | `websocket.close.code`、`websocket.close.reason`、`websocket.close.was_clean` |
|
|
87
86
|
|
|
@@ -95,7 +94,7 @@
|
|
|
95
94
|
|
|
96
95
|
| key | 类型 | 说明 | 低基数 |
|
|
97
96
|
| --- | --- | --- | --- |
|
|
98
|
-
| `span_type` | string | `document`/`
|
|
97
|
+
| `span_type` | string | `document`/`resource`/`vital`/`error`/`longtask`/`action`/`route`/`custom` | 是 |
|
|
99
98
|
| `span_subtype` | string | 子类型,如 `fetch`/`xhr`/`js`/`promise`/`lcp` | 是 |
|
|
100
99
|
| `result` | string | `success`/`warning`/`error`/`timeout`/`abort` | 是 |
|
|
101
100
|
| `error_type` | string | 错误细分,如 `http_5xx`/`network_timeout`/`slow`/`none` | 是 |
|
|
@@ -115,15 +114,30 @@
|
|
|
115
114
|
| `http.request.method` | string | 请求方法(大写) |
|
|
116
115
|
| `http.response.status_code` | number | 响应状态码 |
|
|
117
116
|
| `url.full` | string | 完整 URL(已脱敏) |
|
|
117
|
+
| `resource.type` | string | `fetch`/`xhr` 或静态资源 initiator type |
|
|
118
|
+
| `resource.url` | string | 资源 URL(已脱敏) |
|
|
119
|
+
| `resource.method` | string | 请求方法(Fetch/XHR) |
|
|
120
|
+
| `resource.status_code` | number | 请求状态码(Fetch/XHR) |
|
|
121
|
+
| `resource.duration` | number | 静态资源耗时(ms);请求耗时使用 Span 原生 duration |
|
|
122
|
+
| `resource.redirect.start/duration` | number | 重定向阶段相对开始时间 / 耗时(ms) |
|
|
123
|
+
| `resource.dns.start/duration` | number | DNS 阶段相对开始时间 / 耗时(ms) |
|
|
124
|
+
| `resource.connect.start/duration` | number | TCP 建连阶段相对开始时间 / 耗时(ms) |
|
|
125
|
+
| `resource.ssl.start/duration` | number | TLS 握手阶段相对开始时间 / 耗时(ms) |
|
|
126
|
+
| `resource.first_byte.start/duration` | number | 等待首字节阶段相对开始时间 / 耗时(ms) |
|
|
127
|
+
| `resource.download.start/duration` | number | 响应下载阶段相对开始时间 / 耗时(ms) |
|
|
128
|
+
| `resource.worker.start/duration` | number | Service Worker 阶段相对开始时间 / 耗时(ms) |
|
|
129
|
+
| `resource.delivery_type` | string | `cache` / `navigational-prefetch` 等浏览器交付类型 |
|
|
130
|
+
| `resource.render_blocking_status` | string | `blocking` / `non-blocking` |
|
|
131
|
+
| `resource.size` | number | 传输字节数 |
|
|
118
132
|
| `url.previous` | string | 跳转前 URL |
|
|
119
133
|
| `transfer_size` | number | 传输字节数 |
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
134
|
+
| `resource.cache.hit` | boolean | 是否命中缓存 |
|
|
135
|
+
| `resource.protocol` | string | 协议,如 `h2` |
|
|
122
136
|
| `initiator_type` | string | 资源发起类型 |
|
|
123
137
|
| `resource.encoded_body_size` / `resource.decoded_body_size` | number | 资源体积 |
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
138
|
+
| `request.body` / `response.body` | string | 仅 `browser.request.body` Log;经过接入方 `redact` 且受长度限制 |
|
|
139
|
+
| `request.body.content_type` / `response.body.content_type` | string | body Content-Type(可获取时) |
|
|
140
|
+
| `request.body.truncated` / `response.body.truncated` | boolean | body 是否因长度限制而截断 |
|
|
127
141
|
|
|
128
142
|
### Web Vitals
|
|
129
143
|
|
|
@@ -157,21 +171,30 @@
|
|
|
157
171
|
|
|
158
172
|
| key | 类型 | 说明 |
|
|
159
173
|
| --- | --- | --- |
|
|
160
|
-
| `device.id` | string |
|
|
174
|
+
| `device.id` | string | 匿名设备标识;默认仅当前 SDK 实例稳定,`tracking.device.persistentId=true` 时持久化 |
|
|
161
175
|
| `device.memory` / `device.cpu_cores` | number | 硬件能力 |
|
|
162
176
|
| `device.platform` / `device.mobile` | string/bool | UA-CH 平台信息 |
|
|
163
177
|
| `browser.viewport.width` / `browser.viewport.height` | number | 视口尺寸 |
|
|
164
178
|
| `browser.screen.width` / `browser.screen.height` | number | 屏幕尺寸 |
|
|
165
179
|
| `network.connection_type` / `network.downlink` / `network.rtt` / `network.save_data` | mixed | 网络信息 |
|
|
166
|
-
| `
|
|
180
|
+
| `browser.name` / `browser.version` / `os.name` | string | UA 解析结果 |
|
|
181
|
+
| `device.type` | string | `mobile` / `desktop` |
|
|
167
182
|
|
|
168
183
|
### 用户动作 / 会话
|
|
169
184
|
|
|
170
185
|
| key | 类型 | 说明 |
|
|
171
186
|
| --- | --- | --- |
|
|
172
187
|
| `action.type` | string | 动作类型 |
|
|
173
|
-
| `
|
|
174
|
-
| `
|
|
188
|
+
| `action.id` | string / string[] | action 自身 ID;关联事件上为 action ID 数组 |
|
|
189
|
+
| `action.name` | string | 可读动作名称 |
|
|
190
|
+
| `action.target.name` | string | 自动 action 的目标元素名称 |
|
|
191
|
+
| `action.target.tag` | string | 自动 action 的目标元素标签 |
|
|
192
|
+
| `action.loading_time` | number | 点击后页面活动稳定耗时(ms) |
|
|
193
|
+
| `action.resource.count` | number | action 关联资源数 |
|
|
194
|
+
| `action.error.count` | number | action 关联错误数 |
|
|
195
|
+
| `action.long_task.count` | number | action 关联长任务数 |
|
|
196
|
+
| `action.frustration.type` | string[] | `rage_click` / `dead_click` / `error_click` |
|
|
197
|
+
| `action.frustration.count` | number | 当前 action 的挫败信号数量 |
|
|
175
198
|
| `session.start_time` | number | 会话开始时间戳 |
|
|
176
199
|
| `session.previous_id` | string | 轮换前的 session.id |
|
|
177
200
|
| `session.rotate.reason` | string | `init`/`inactivity`/`maxLifetime` |
|
|
@@ -180,8 +203,15 @@
|
|
|
180
203
|
|
|
181
204
|
| key | 类型 | 说明 |
|
|
182
205
|
| --- | --- | --- |
|
|
183
|
-
| `
|
|
184
|
-
| `
|
|
206
|
+
| `long_task.id` | string | 长任务或长动画帧 ID |
|
|
207
|
+
| `long_task.entry_type` | string | `long-animation-frame` / `long-task` |
|
|
208
|
+
| `long_task.start_time` | number | LoAF 相对 `performance.timeOrigin` 的开始时间(ms) |
|
|
209
|
+
| `long_task.duration` / `long_task.blocking_duration` | number | 总耗时 / 主线程阻塞耗时(ms) |
|
|
210
|
+
| `long_task.is_frozen_frame` | boolean | 总耗时是否达到 700ms |
|
|
211
|
+
| `long_task.culprit` | string | 最重脚本 URL、函数或 legacy attribution |
|
|
212
|
+
| `long_task.script.count` | number | LoAF 脚本数 |
|
|
213
|
+
| `long_task.render_start` / `long_task.style_and_layout_start` | number | LoAF 渲染与样式布局阶段起点 |
|
|
214
|
+
| `long_task.script.*` | mixed | `long_task.script` Span Event 上的脚本耗时、URL、函数、invoker 和强制布局归因 |
|
|
185
215
|
|
|
186
216
|
### CSP
|
|
187
217
|
|
|
@@ -212,17 +242,16 @@
|
|
|
212
242
|
|
|
213
243
|
| key | 类型 | 说明 |
|
|
214
244
|
| --- | --- | --- |
|
|
215
|
-
| `blank_screen.
|
|
216
|
-
| `blank_screen.
|
|
217
|
-
| `blank_screen.
|
|
218
|
-
| `blank_screen.
|
|
219
|
-
| `blank_screen.
|
|
245
|
+
| `blank_screen.empty_ratio` | number | 有效样本中的空白比例 |
|
|
246
|
+
| `blank_screen.reason` | string | `empty_viewport` / `missing_root` |
|
|
247
|
+
| `blank_screen.root_selector` / `blank_screen.root_found` | string/boolean | 根选择器与是否存在 |
|
|
248
|
+
| `blank_screen.sample_count` / `blank_screen.valid_sample_count` | number | 总样本数 / 有效样本数 |
|
|
249
|
+
| `blank_screen.empty_sample_count` / `blank_screen.ignored_sample_count` | number | 空白样本数 / loading 忽略样本数 |
|
|
220
250
|
| `blank_screen.center_element` | string | 视口中心元素选择器 |
|
|
221
|
-
| `blank_screen.dom_node_count` | number | body 下 DOM 节点总数 |
|
|
222
251
|
|
|
223
252
|
### 自定义事件
|
|
224
253
|
|
|
225
254
|
| key | 类型 | 说明 |
|
|
226
255
|
| --- | --- | --- |
|
|
227
256
|
| `rum.custom.name` | string | `reportCustomEvent()` 的事件名 |
|
|
228
|
-
| `rum.page.host` / `rum.page.path` | string | 默认 `attributes.page`
|
|
257
|
+
| `rum.page.host` / `rum.page.path` | string | 默认 `context.attributes.page` 页面上下文;配置自定义 page hook 后由接入方决定字段 |
|
|
@@ -10,13 +10,16 @@
|
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
new BkOpenTelemetry({
|
|
13
|
+
application: { name: 'rum-debug' },
|
|
13
14
|
debug: true,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
rate: 1,
|
|
15
|
+
session: {
|
|
16
|
+
sampleRate: 1,
|
|
17
17
|
},
|
|
18
18
|
transport: {
|
|
19
19
|
endpoint: 'http://localhost:4318',
|
|
20
|
+
signals: {
|
|
21
|
+
traces: { processor: 'simple' },
|
|
22
|
+
},
|
|
20
23
|
},
|
|
21
24
|
});
|
|
22
25
|
```
|
|
@@ -24,7 +27,7 @@ new BkOpenTelemetry({
|
|
|
24
27
|
检查点:
|
|
25
28
|
|
|
26
29
|
- Collector 是否监听 `4318`。
|
|
27
|
-
- 浏览器 Network 中是否有 `/rum`、`/metrics`、`/logs` 请求。
|
|
30
|
+
- 浏览器 Network 中是否有 `/v1/rum`、`/v1/metrics`、`/v1/logs` 请求。
|
|
28
31
|
- 是否被采样丢弃。
|
|
29
32
|
- `enabled` 是否为 `false`。
|
|
30
33
|
|
|
@@ -34,10 +37,12 @@ new BkOpenTelemetry({
|
|
|
34
37
|
|
|
35
38
|
```ts
|
|
36
39
|
new BkOpenTelemetry({
|
|
40
|
+
application: { name: 'rum-debug' },
|
|
37
41
|
debug: true,
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
session: {
|
|
43
|
+
sampleRate: 1,
|
|
40
44
|
},
|
|
45
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
41
46
|
});
|
|
42
47
|
```
|
|
43
48
|
|
|
@@ -47,7 +52,9 @@ new BkOpenTelemetry({
|
|
|
47
52
|
|
|
48
53
|
```ts
|
|
49
54
|
const bkOT = new BkOpenTelemetry({
|
|
55
|
+
application: { name: 'rum-debug' },
|
|
50
56
|
autoStart: false,
|
|
57
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
51
58
|
});
|
|
52
59
|
|
|
53
60
|
bkOT.use(myPlugin);
|
|
@@ -61,7 +68,9 @@ SPA 应用应配置 `rootSelector` 和 loading/skeleton 忽略选择器。
|
|
|
61
68
|
|
|
62
69
|
```ts
|
|
63
70
|
new BkOpenTelemetry({
|
|
64
|
-
|
|
71
|
+
application: { name: 'rum-debug' },
|
|
72
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
73
|
+
tracking: {
|
|
65
74
|
blankScreen: {
|
|
66
75
|
rootSelector: '#app',
|
|
67
76
|
ignoreSelectors: ['.bk-loading', '.skeleton'],
|
|
@@ -73,13 +82,16 @@ new BkOpenTelemetry({
|
|
|
73
82
|
|
|
74
83
|
## 接口 span 太多
|
|
75
84
|
|
|
76
|
-
先确认是否有多个 SDK
|
|
85
|
+
先确认是否有多个 SDK 实例重复初始化,尤其是微前端场景。其次用 `excludedUrls` 排除探活或高频无价值请求。
|
|
77
86
|
|
|
78
87
|
```ts
|
|
79
88
|
new BkOpenTelemetry({
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
application: { name: 'rum-debug' },
|
|
90
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
91
|
+
tracking: {
|
|
92
|
+
request: {
|
|
93
|
+
excludedUrls: [/\/health(?:\?|$)/, /\/polling\//],
|
|
94
|
+
},
|
|
83
95
|
},
|
|
84
96
|
});
|
|
85
97
|
```
|
|
@@ -90,6 +102,8 @@ new BkOpenTelemetry({
|
|
|
90
102
|
|
|
91
103
|
```ts
|
|
92
104
|
new BkOpenTelemetry({
|
|
105
|
+
application: { name: 'rum-debug' },
|
|
106
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
93
107
|
privacy: {
|
|
94
108
|
redactUrl: url => url.replace(/([?&]token=)[^&]+/g, '$1***'),
|
|
95
109
|
redactAttributes: attributes => {
|
|
@@ -107,7 +121,9 @@ Long Task API 并非所有浏览器都支持。Firefox 不支持时插件会跳
|
|
|
107
121
|
|
|
108
122
|
```ts
|
|
109
123
|
new BkOpenTelemetry({
|
|
110
|
-
|
|
124
|
+
application: { name: 'rum-debug' },
|
|
125
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
126
|
+
tracking: {
|
|
111
127
|
longTask: {
|
|
112
128
|
threshold: 50,
|
|
113
129
|
},
|
|
@@ -117,26 +133,36 @@ new BkOpenTelemetry({
|
|
|
117
133
|
|
|
118
134
|
## HTTP body 没有数据
|
|
119
135
|
|
|
120
|
-
`
|
|
136
|
+
请求/响应 body 默认关闭。需要采集时配置 `tracking.request.body`,并提供必填的 `redact`:
|
|
121
137
|
|
|
122
138
|
```ts
|
|
123
139
|
new BkOpenTelemetry({
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
140
|
+
application: { name: 'rum-debug' },
|
|
141
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
142
|
+
tracking: {
|
|
143
|
+
request: {
|
|
144
|
+
body: {
|
|
145
|
+
capture: 'errors',
|
|
146
|
+
allowedContentTypes: ['application/json'],
|
|
147
|
+
maxSize: 10 * 1024,
|
|
148
|
+
redact: ({ body }) => body.replace(/"password"\s*:\s*"[^"]+"/g, '"password":"***"'),
|
|
149
|
+
},
|
|
128
150
|
},
|
|
129
151
|
},
|
|
130
152
|
});
|
|
131
153
|
```
|
|
132
154
|
|
|
155
|
+
`capture` 默认就是 `errors`,成功请求不会产生 body Log;要采集成功请求需显式设为 `all`。如果仍然没有数据,依次检查 Content-Type 是否命中 `allowedContentTypes`、body 是否为支持的文本类型,以及 `redact` 是否返回了 `undefined`。FormData、ArrayBuffer 和二进制响应会跳过。
|
|
156
|
+
|
|
133
157
|
## WebSocket 采集异常
|
|
134
158
|
|
|
135
159
|
WebSocket 插件会 Proxy 全局 `WebSocket`。如果应用或第三方库也 patch 了 WebSocket,应避免重复 patch。
|
|
136
160
|
|
|
137
161
|
```ts
|
|
138
162
|
new BkOpenTelemetry({
|
|
139
|
-
|
|
163
|
+
application: { name: 'rum-debug' },
|
|
164
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
165
|
+
tracking: {
|
|
140
166
|
websocket: true,
|
|
141
167
|
},
|
|
142
168
|
});
|
|
@@ -146,14 +172,15 @@ new BkOpenTelemetry({
|
|
|
146
172
|
|
|
147
173
|
## SDK 会采集哪些数据?
|
|
148
174
|
|
|
149
|
-
|
|
175
|
+
默认采集页面访问与稳定耗时、用户动作、资源加载、fetch/xhr、JavaScript 错误、Web Vitals、空白屏、设备信息和会话信息。HTTP body、Long Task、CSP、WebSocket 默认关闭。
|
|
150
176
|
|
|
151
177
|
```ts
|
|
152
178
|
new BkOpenTelemetry({
|
|
153
|
-
|
|
179
|
+
application: { name: 'demo' },
|
|
180
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
181
|
+
tracking: {
|
|
154
182
|
action: true,
|
|
155
183
|
longTask: true,
|
|
156
|
-
routeTiming: true,
|
|
157
184
|
websocket: true,
|
|
158
185
|
},
|
|
159
186
|
});
|
|
@@ -165,32 +192,37 @@ new BkOpenTelemetry({
|
|
|
165
192
|
|
|
166
193
|
```ts
|
|
167
194
|
new BkOpenTelemetry({
|
|
168
|
-
|
|
169
|
-
|
|
195
|
+
application: { name: 'demo' },
|
|
196
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
197
|
+
context: {
|
|
198
|
+
user: {
|
|
199
|
+
id: hashUserId(rawUserId),
|
|
200
|
+
},
|
|
170
201
|
},
|
|
171
202
|
});
|
|
172
203
|
```
|
|
173
204
|
|
|
174
|
-
## `
|
|
205
|
+
## `session.sampleRate` 是 trace 级采样吗?
|
|
175
206
|
|
|
176
|
-
|
|
207
|
+
不是。它是会话级确定性采样,同一会话内保持一致。
|
|
177
208
|
|
|
178
209
|
```ts
|
|
179
210
|
new BkOpenTelemetry({
|
|
180
|
-
|
|
181
|
-
|
|
211
|
+
application: { name: 'demo' },
|
|
212
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
213
|
+
session: {
|
|
214
|
+
sampleRate: 0.2,
|
|
182
215
|
},
|
|
183
216
|
});
|
|
184
217
|
```
|
|
185
218
|
|
|
186
|
-
##
|
|
219
|
+
## 为什么不使用 OpenTelemetry userInteraction instrumentation?
|
|
187
220
|
|
|
188
|
-
|
|
221
|
+
官方 userInteraction instrumentation 主要用于把交互回调中的异步任务组织成 trace,但没有稳定的 RUM action 语义、动作命名、页面活动窗口和关联计数。本 SDK 统一使用 `action` 插件,避免同一次点击重复上报;内置 request 采集统一负责 Fetch/XHR 网络 trace。
|
|
189
222
|
|
|
190
223
|
```ts
|
|
191
224
|
bkOT.reportAction({
|
|
192
|
-
|
|
193
|
-
targetText: '确认提交',
|
|
225
|
+
name: '确认提交',
|
|
194
226
|
attributes: {
|
|
195
227
|
'biz.scene': 'strategy-create',
|
|
196
228
|
},
|
|
@@ -199,29 +231,31 @@ bkOT.reportAction({
|
|
|
199
231
|
|
|
200
232
|
## 可以只上报 traces,不上报 metrics/logs 吗?
|
|
201
233
|
|
|
202
|
-
|
|
234
|
+
可以。将不需要的信号设为 `false`;根 endpoint 在所有已开启信号都配置独立地址时可以省略。
|
|
203
235
|
|
|
204
236
|
```ts
|
|
205
237
|
new BkOpenTelemetry({
|
|
238
|
+
application: { name: 'demo' },
|
|
206
239
|
transport: {
|
|
207
240
|
signals: {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
logs: 'https://log-gateway.example.com/v1/logs',
|
|
212
|
-
},
|
|
241
|
+
traces: { endpoint: 'https://trace-gateway.example.com/v1/rum' },
|
|
242
|
+
metrics: false,
|
|
243
|
+
logs: false,
|
|
213
244
|
},
|
|
214
245
|
},
|
|
215
246
|
});
|
|
216
247
|
```
|
|
217
248
|
|
|
249
|
+
三类信号不能全部关闭。关闭 Trace 后也不会注入 `traceparent`。
|
|
250
|
+
|
|
218
251
|
## 为什么不建议多个实例同时运行?
|
|
219
252
|
|
|
220
|
-
fetch、xhr、
|
|
253
|
+
fetch、xhr、action、websocket 等能力会监听或 patch 全局 API。多个实例可能重复采集、重复上报或互相影响。
|
|
221
254
|
|
|
222
255
|
```ts
|
|
223
256
|
if (!window.__BK_RUM_INSTANCE__) {
|
|
224
257
|
window.__BK_RUM_INSTANCE__ = new BkOpenTelemetry({
|
|
258
|
+
application: { name: 'demo' },
|
|
225
259
|
transport: {
|
|
226
260
|
endpoint: 'https://rum-collector.example.com',
|
|
227
261
|
},
|