@blueking/open-telemetry 0.0.30 → 0.0.32
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 +61 -24
- package/dist/bk-rum.global.js +1 -1
- package/dist/bk-rum.global.js.map +1 -1
- package/dist/index.js +368 -357
- package/dist/index.js.map +1 -1
- package/dist/schema/attributes.d.ts +1 -0
- package/package.json +1 -1
- package/skills/bk-rum-otele/references/actions.md +16 -10
- package/skills/bk-rum-otele/references/api.md +5 -2
- package/skills/bk-rum-otele/references/architecture.md +2 -2
- package/skills/bk-rum-otele/references/blank-screen.md +8 -17
- package/skills/bk-rum-otele/references/capabilities.md +2 -2
- package/skills/bk-rum-otele/references/configuration.md +4 -4
- package/skills/bk-rum-otele/references/data-model.md +14 -14
- package/skills/bk-rum-otele/references/errors-security.md +5 -4
- package/skills/bk-rum-otele/references/extensions.md +8 -0
- package/skills/bk-rum-otele/references/framework-integration.md +1 -1
- package/skills/bk-rum-otele/references/getting-started.md +19 -1
- package/skills/bk-rum-otele/references/network.md +22 -19
- package/skills/bk-rum-otele/references/performance.md +12 -23
- package/skills/bk-rum-otele/references/privacy.md +2 -2
- package/skills/bk-rum-otele/references/session-context.md +13 -9
- package/skills/bk-rum-otele/references/span-protocol.md +265 -100
- package/skills/bk-rum-otele/references/telemetry-reference.md +75 -79
- package/skills/bk-rum-otele/references/transport-sampling.md +18 -13
- package/skills/bk-rum-otele/references/troubleshooting.md +1 -1
- package/skills/bk-rum-otele/references/views-routing.md +5 -3
|
@@ -4,23 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
两份文档不重复维护同一套字段规范:一个记录实现现状,一个定义稳定承诺。
|
|
6
6
|
|
|
7
|
-
「[遥测字段字典](./telemetry-reference.md)
|
|
7
|
+
「[遥测字段字典](./telemetry-reference.md)」对照当前 `src/` 列出 SDK **实际产出**的 Span 与 Attribute。它回答现在上报了哪些字段;其中可以包含新增、灰度和待废弃字段,不代表这些字段都已形成稳定承诺。
|
|
8
8
|
|
|
9
|
-
「RUM
|
|
9
|
+
「RUM 语义约定」是前后端共同遵循的语义契约。字段经过评审并标记为 Stable 后,才成为对外稳定承诺。本页字段口径与当前浏览器 SDK 实现对齐;后端入库后派生的字段单独标记为 Backend。
|
|
10
10
|
|
|
11
|
-
如果两份文档对不上,先查「遥测字段字典」确认 SDK
|
|
11
|
+
如果两份文档对不上,先查「遥测字段字典」确认 SDK 现在上报了什么。代码中出现了某个字段,并不表示它已经稳定;只有在本页标记为 Stable,前后端才需要长期兼容这个字段。
|
|
12
12
|
|
|
13
13
|
| 状态 | 描述 |
|
|
14
14
|
| -------------------------------------------------------------- | -------------- |
|
|
15
|
-
|  | 已上报,保持现状。
|
|
16
|
-
|  | 新补充或字段位置变更。 |
|
|
15
|
+
|  | 当前 SDK 已上报,保持现状。 |
|
|
17
16
|
|  | 已上报,但需要废弃。 |
|
|
17
|
+
|  | 新补充或字段位置变更。 |
|
|
18
18
|
|  | 由后端生成,前端不直接上报。 |
|
|
19
19
|
|
|
20
20
|
原则:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
|
|
22
|
+
- 浏览器 SDK 只上报原始 RUM Span(OTLP/HTTP JSON Trace),不创建 Metric 或 Log Provider。
|
|
23
|
+
- Web Vitals 由 SDK 以 `browser.web_vital` Span 上报(`vital.metric` = `cls` / `fcp` / `inp` / `lcp` / `ttfb`);分位数和跨会话聚合由接收端派生。
|
|
24
|
+
- 控制字段规模:只约定当前实现真正使用的字段;未上报字段不要当作采集端契约。
|
|
24
25
|
|
|
25
26
|
## 0x01 用户真实监控模型
|
|
26
27
|
|
|
@@ -54,9 +55,9 @@ Session
|
|
|
54
55
|
| `events` |  | Event[] | 事件列表 | 异常详情和 Long Task 脚本明细通过 Span Event 承载。 |
|
|
55
56
|
| `links` |  | Link[] | [Span 链接](https://opentelemetry.io/docs/concepts/signals/traces/#span-links) | 链接的存在是为了 Span 同其他 Span 建立关联,从而表明存在因果关系。 |
|
|
56
57
|
| `attributes` |  | object | 属性 | 浏览器、设备、网络、异常等各类语义标签和度量。 |
|
|
57
|
-
| `start_time` |  | int | 开始时间(微秒) | 后端入库字段。SDK 线上传输使用 OTLP `startTimeUnixNano`(纳秒十进制字符串)。 |
|
|
59
|
+
| `end_time` |  | int | 结束时间(微秒) | 同上,对应 `endTimeUnixNano`。 |
|
|
60
|
+
| `elapsed_time` |  | int | 耗时(微秒) | 后端由起止时间相减;浏览器 SDK 不单独上报该 Attribute。 |
|
|
60
61
|
|
|
61
62
|
### b. Resource
|
|
62
63
|
|
|
@@ -68,13 +69,13 @@ Session
|
|
|
68
69
|
| `resource.session.sample_rate` |  | number | Session 采样率 | 取值范围为 `0`~`1`。 |
|
|
69
70
|
| `resource.telemetry.sdk.version` |  | str | SDK 版本 | -- |
|
|
70
71
|
| [`resource.telemetry.sdk.language`](https://opentelemetry.io/docs/specs/semconv/resource/#telemetry-sdk) |  | enum | 语言 | `webjs`。 |
|
|
71
|
-
| `resource.telemetry.sdk.name` *[1]* |  | enum | 设备类型 | `desktop`、`mobile
|
|
72
|
+
| `resource.telemetry.sdk.name` *[1]* |  | str | SDK 名称 | -- |
|
|
73
|
+
| `resource.device.type` |  | enum | 设备类型 | 当前仅为 `desktop`、`mobile`。 |
|
|
73
74
|
| `resource.user_agent.name` |  | str | 代理名称 | 通常指的是浏览器的名称,如 `Chrome`、`Edge`。 |
|
|
74
75
|
| `resource.user_agent.version` |  | str | 代理版本 | 通常指的是浏览器的名称,如 `149`、`151`。 |
|
|
75
76
|
| `resource.user_agent.os.name` |  | str | 操作系统名 | 如 `macOS`、`Windows`、`Android`。 |
|
|
76
77
|
|
|
77
|
-
**[1] `resource.telemetry.sdk.name
|
|
78
|
+
**[1] `resource.telemetry.sdk.name`**:当前浏览器 SDK 固定为 `blueking`。Aegis 等其他生产端可使用各自名称,不要把 npm 包名 `@blueking/open-telemetry` 当作该字段值。
|
|
78
79
|
|
|
79
80
|
### c. Status
|
|
80
81
|
|
|
@@ -88,7 +89,7 @@ Session
|
|
|
88
89
|
| 字段 | 状态 | 类型 | 描述 | 备注 |
|
|
89
90
|
| ----------------------------------------------------------------------- | ---------------------------------------------------------- | ------ | ------------- | -------------------- |
|
|
90
91
|
| `events[].name` *[1]* |  | str | 事件名 | |
|
|
91
|
-
| `events[].timestamp` |  | int |
|
|
92
|
+
| `events[].timestamp` |  | int | 事件发生时间 | SDK 传输为 OTLP Event UnixNano;后端可转为微秒。 |
|
|
92
93
|
| `events[].attributes.exception.type` |  | str | 异常类型 | 如 `TypeError`。 |
|
|
93
94
|
| `events[].attributes.exception.message` |  | str | 异常消息 | 如 `Failed to fetch`。 |
|
|
94
95
|
| `events[].attributes.exception.stacktrace` |  | str | 异常堆栈 | |
|
|
@@ -115,32 +116,33 @@ Session
|
|
|
115
116
|
| `links[].trace_id` |  | str | 关联 TraceID | |
|
|
116
117
|
| `links[].span_id` |  | str | 关联 SpanID | |
|
|
117
118
|
|
|
118
|
-
**[1] `links[].trace_id
|
|
119
|
+
**[1] `links[].trace_id`**:`span_type=resource` 且 `resource.type` 为 `xhr` 或 `fetch`,并注入/探测到 Trace Header 时,把对应后端 Trace ID 记到 Link 上。
|
|
119
120
|
|
|
120
121
|
|
|
121
|
-
##
|
|
122
|
+
## 0x03 Attributes
|
|
122
123
|
|
|
123
124
|
### a. 基础字段
|
|
124
125
|
|
|
125
|
-
| 字段
|
|
126
|
-
|
|
|
127
|
-
| `attributes.user.id`
|
|
128
|
-
| `attributes.span_type` *[1]*
|
|
129
|
-
| `attributes.outcome.type`
|
|
126
|
+
| 字段 | 状态 | 类型 | 描述 | 备注 |
|
|
127
|
+
| ---------------------------- | ---------------------------------------------------------- | ---- | ------- | ---------------------------------------------- |
|
|
128
|
+
| `attributes.user.id` |  | str | 用户 ID | -- |
|
|
129
|
+
| `attributes.span_type` *[1]* |  | enum | Span 类型 | -- |
|
|
130
|
+
| `attributes.outcome.type` |  | enum | 执行结果 | `success`、`warning`、`error`、`timeout`、`abort`。 |
|
|
131
|
+
|
|
130
132
|
|
|
131
133
|
**[1] `attributes.span_type`**:
|
|
132
134
|
|
|
133
|
-
| 值
|
|
134
|
-
|
|
|
135
|
-
| `session`
|
|
136
|
-
| `view`
|
|
137
|
-
| `resource`
|
|
138
|
-
| `error`
|
|
139
|
-
| `vital`
|
|
140
|
-
| `long_task` | Long Task 或长动画帧。
|
|
141
|
-
| `action`
|
|
142
|
-
| `websocket` | WebSocket 生命周期事件。
|
|
143
|
-
| `custom`
|
|
135
|
+
| 值 | 描述 |
|
|
136
|
+
| ----------- | -------------------- |
|
|
137
|
+
| `session` | Session 创建、轮换或结束。 |
|
|
138
|
+
| `view` | 页面首次加载或路由视图生命周期。 |
|
|
139
|
+
| `resource` | 静态资源、Fetch 或 XHR 请求。 |
|
|
140
|
+
| `error` | 浏览器错误、白屏或 CSP 违规。 |
|
|
141
|
+
| `vital` | Web Vitals 指标。 |
|
|
142
|
+
| `long_task` | Long Task 或长动画帧。 |
|
|
143
|
+
| `action` | 用户交互或主动上报的 Action。 |
|
|
144
|
+
| `websocket` | WebSocket 生命周期事件。 |
|
|
145
|
+
| `custom` | 主动上报的自定义事件。 |
|
|
144
146
|
|
|
145
147
|
### b. [error](https://opentelemetry.io/docs/specs/semconv/registry/attributes/error/)
|
|
146
148
|
|
|
@@ -173,21 +175,29 @@ Session
|
|
|
173
175
|
|
|
174
176
|
| 字段 | 状态 | 类型 | 描述 | 备注 |
|
|
175
177
|
| ------------------------------------ | -------------------------------------------------------------- | ---- | ------- | ----------------------------------------------------------- |
|
|
176
|
-
| `attributes.network.connection.type` |  |
|
|
178
|
+
| `attributes.network.connection.type` |  | enum | 连接类型 | 直接使用浏览器 `navigator.connection.type` 的原始值;字段不存在时不上报。 |
|
|
177
179
|
| `attributes.network.effective_type` |  | str | 有效网络质量 | -- |
|
|
178
180
|
| `attributes.network.status` |  | enum | 网络连接状态 | `connected`、`not_connected`。 |
|
|
179
181
|
| `attributes.network.protocol.name` |  | enum | 应用层网络协议 | 仅 WebSocket Span 上报,固定为 `websocket`;HTTP Resource Span 不上报。 |
|
|
180
182
|
|
|
181
|
-
**[1] `attributes.network.connection.type
|
|
183
|
+
**[1] `attributes.network.connection.type`**:表示设备当前使用的物理网络连接方式。SDK 直接上报
|
|
184
|
+
[`navigator.connection.type`](https://wicg.github.io/netinfo/#connectiontype-enum);浏览器不支持该 API
|
|
185
|
+
或没有返回 `type` 时不携带该字段。该字段对应 DataDog 的 `connectivity.interfaces` 和 Aegis 的 `netType`。
|
|
182
186
|
|
|
183
187
|
Aegis 将「连接类型」「网络质量」整合成 `netType`(`wifi`、`wired`、`2G`、`3G`、`5G`、`6G`),不推荐这种做法。
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
|
187
|
-
|
|
|
188
|
-
| `
|
|
189
|
-
| `
|
|
190
|
-
| `
|
|
188
|
+
转换 Aegis 数据时,`wifi` 保持不变,`wired` 映射为 `ethernet`,移动网络代际映射为 `cellular`。
|
|
189
|
+
|
|
190
|
+
| 值 | 描述 | 备注 |
|
|
191
|
+
| ---------- | -------- | --------------------------------------- |
|
|
192
|
+
| `bluetooth` | 蓝牙网络 | 通过蓝牙网络连接。 |
|
|
193
|
+
| `cellular` | 蜂窝移动网络 | 不表示具体移动网络代际。 |
|
|
194
|
+
| `ethernet` | 以太网 | Aegis 的 `wired` 映射为该值。 |
|
|
195
|
+
| `mixed` | 混合连接 | 浏览器同时使用多种连接方式。 |
|
|
196
|
+
| `none` | 无网络连接 | 通常与 `network.status=not_connected` 同时出现。 |
|
|
197
|
+
| `other` | 其他连接方式 | 浏览器知道连接类型,但不属于已列出的类型。 |
|
|
198
|
+
| `unknown` | 未知连接方式 | 已建立网络连接,但浏览器无法或不愿提供连接类型。 |
|
|
199
|
+
| `wifi` | Wi-Fi 网络 | 仅表示通过 Wi-Fi 连接,不代表网络一定快。 |
|
|
200
|
+
| `wimax` | WiMAX 网络 | 通过 WiMAX 连接。 |
|
|
191
201
|
|
|
192
202
|
**[2] `attributes.network.effective_type`**:表示浏览器根据延迟和下载速度估算出的实际网络质量,等同与 DataDog(`connectivity.effective_type`)、Aegis(`netType`)。
|
|
193
203
|
|
|
@@ -220,25 +230,26 @@ Aegis 将「连接类型」「网络质量」整合成 `netType`(`wifi`、`wir
|
|
|
220
230
|
| 字段 | 状态 | 类型 | 描述 | 备注 |
|
|
221
231
|
| ------------------------------------- | -------------------------------------------------------------- | ------ | ----------------------- | --------------------------------------------- |
|
|
222
232
|
| `attributes.view.id` |  | str | 视图 ID | |
|
|
223
|
-
| `attributes.view.name`
|
|
224
|
-
| `attributes.view.loading_type`
|
|
233
|
+
| `attributes.view.name` *[1]* |  | str | 视图名称 | 如 `/apm/home`。 |
|
|
234
|
+
| `attributes.view.loading_type` *[2]* |  | str | 视图加载类型 | -- |
|
|
225
235
|
| `attributes.view.url` |  | str | 视图 URL | 如 `https://example.com/cur`。 |
|
|
226
236
|
| `attributes.view.previous` |  | str | 视图 URL(前一个) | 如 `https://example.com/pre`。 |
|
|
227
|
-
| `attributes.view.
|
|
228
|
-
| `attributes.view.
|
|
237
|
+
| `attributes.view.previous_url_template` |  | str | 前序视图路径模板 | 与 `view.url_template` 使用同一规则;初始 View 为空字符串。 |
|
|
238
|
+
| `attributes.view.referrer` |  | str | 初始来源页面 URL | 仅首次加载且值非空时上报,需进行 URL 脱敏。 |
|
|
239
|
+
| `attributes.view.url_template` *[3]* |  | str | 视图路径分组 | 如 `/apm/home`。 |
|
|
229
240
|
| `attributes.view.loading_time` |  | number | 视图加载耗时(ms) | 加载时间计算完成后上报。 |
|
|
230
|
-
| `attributes.view.loading_time_source` |  | enum | 视图加载耗时来源 | `auto`、`manual`。
|
|
241
|
+
| `attributes.view.loading_time_source` |  | enum | 视图加载耗时来源 | `auto`、`manual`。 |
|
|
231
242
|
| `attributes.view.first_byte` |  | number | 首字节时间(ms) | 仅初始导航存在。 |
|
|
232
243
|
| `attributes.view.dom_interactive` |  | number | DOM 可交互时间(ms) | 仅初始导航存在。 |
|
|
233
244
|
| `attributes.view.dom_content_loaded` |  | number | DOMContentLoaded 时间(ms) | 仅初始导航存在。 |
|
|
234
245
|
| `attributes.view.dom_complete` |  | number | DOM Complete 时间(ms) | 仅初始导航存在。 |
|
|
235
246
|
| `attributes.view.load_event` |  | number | Load Event 时间(ms) | 仅初始导航存在。 |
|
|
236
|
-
| `attributes.view.phase`
|
|
237
|
-
| `attributes.view.started_at` |  | number | 视图开始时间(ms) | 取 `performance.timeOrigin
|
|
247
|
+
| `attributes.view.phase` *[4]* |  | enum | 视图生命周期阶段 | 枚举值:<br>- start<br>- update<br>- end |
|
|
248
|
+
| `attributes.view.started_at` |  | number | 视图开始时间(ms) | 初始 View 取 `performance.timeOrigin`(epoch ms);后续 View 取创建时刻。 |
|
|
238
249
|
| `attributes.view.version` |  | int | 视图事件版本号 | 同一 `attributes.view.id` 从 `1` 开始递增,用于排序和幂等合并。 |
|
|
239
250
|
| `attributes.view.end_reason` |  | str | 结束原因 | -- |
|
|
240
251
|
|
|
241
|
-
**[1] `attributes.view.name
|
|
252
|
+
**[1] `attributes.view.name`**:仅由 `startView({ name })` 或 `setViewName` 显式设置;未设置时,展示层可回退到 `view.url_template`。
|
|
242
253
|
|
|
243
254
|
**[2] `attributes.view.loading_type`**:
|
|
244
255
|
|
|
@@ -249,9 +260,9 @@ Aegis 将「连接类型」「网络质量」整合成 `netType`(`wifi`、`wir
|
|
|
249
260
|
| `session_renewal` | 会话续期后重建 |
|
|
250
261
|
| `bf_cache` | 从浏览器 BFCache 恢复 |
|
|
251
262
|
|
|
252
|
-
**[3] `attributes.view.
|
|
263
|
+
**[3] `attributes.view.url_template`**:用于聚合的页面路径。默认把数字 ID、UUID 和长十六进制段替换为 `:id`,也可由 `tracking.view.getUrlTemplate` 自定义。
|
|
253
264
|
|
|
254
|
-
**[
|
|
265
|
+
**[4] `attributes.view.phase`**:当前 View Span 的生命周期阶段,Schema v3 不再用一条长 Span 表达整个 View,而是发送多条瞬时生命周期 Span。
|
|
255
266
|
|
|
256
267
|
|
|
257
268
|
```text
|
|
@@ -358,23 +369,27 @@ View B █████████████
|
|
|
358
369
|
|
|
359
370
|
**[2] 单位**:`xx_size` 为 bytes,`duration` & `start` 为毫秒。
|
|
360
371
|
|
|
372
|
+
**[3] 阶段图**:产品阶段划分见 [0x04 资源加载时序](#0x04-资源加载时序)。
|
|
373
|
+
|
|
361
374
|
### i. action
|
|
362
375
|
|
|
363
|
-
| 字段 | 状态
|
|
364
|
-
| ------------------------------------------ |
|
|
365
|
-
| `attributes.action.id` | 
|
|
366
|
-
| `attributes.action.type` *[
|
|
367
|
-
| `attributes.action.target.name` | 
|
|
368
|
-
| `attributes.action.target.tag` | 
|
|
369
|
-
| `attributes.action.frustration.type` *[
|
|
376
|
+
| 字段 | 状态 | 类型 | 描述 |
|
|
377
|
+
| ------------------------------------------ | ---------------------------------------------------------- | ----- | ------ |
|
|
378
|
+
| `attributes.action.id` |  | str | -- |
|
|
379
|
+
| `attributes.action.type` *[2]* |  | str | 动作类型 |
|
|
380
|
+
| `attributes.action.target.name` |  | str | 目标元素名称 |
|
|
381
|
+
| `attributes.action.target.tag` |  | str | 目标元素标签 |
|
|
382
|
+
| `attributes.action.frustration.type` *[3]* |  | str[] | 挫败类型 |
|
|
383
|
+
|
|
370
384
|
|
|
385
|
+
**[1] `attributes.action.loading_time`**:当前浏览器 SDK 不写该 Attribute。有页面活动时,用 Span 起止时间(后端 `elapsed_time`)表达持续时长。
|
|
371
386
|
|
|
372
|
-
**[
|
|
387
|
+
**[2] `attributes.action.type`**:
|
|
373
388
|
|
|
374
389
|
| 常见值 | 描述 |
|
|
375
390
|
| -------------------- | ---------------------------------- |
|
|
376
391
|
| `click` | 鼠标或指针设备触发的点击,蓝鲸 Web 自动 Action 当前使用该值。 |
|
|
377
|
-
| `custom` | 通过
|
|
392
|
+
| `custom` | 通过 `reportAction({ name })` 主动上报;Span 名为 `action.<name>`。 |
|
|
378
393
|
| `tap` | 触屏设备上的单次轻触。 |
|
|
379
394
|
| `scroll` | 页面或滚动容器的滚动操作。 |
|
|
380
395
|
| `swipe` | 触屏设备上的滑动手势。 |
|
|
@@ -383,7 +398,7 @@ View B █████████████
|
|
|
383
398
|
|
|
384
399
|
以上是跨端常见值,不是封闭枚举。蓝鲸 Web 当前产生 `click` 和 `custom`。转换 Aegis 数据时,还可能保留接入方配置的 DOM 事件名。
|
|
385
400
|
|
|
386
|
-
**[
|
|
401
|
+
**[3] `attributes.action.frustration.type`**:
|
|
387
402
|
|
|
388
403
|
| 值 | 描述 |
|
|
389
404
|
| ------------- | ------------------------------------------------------------------------------------ |
|
|
@@ -395,35 +410,36 @@ View B █████████████
|
|
|
395
410
|
|
|
396
411
|
### j. http & [url](https://opentelemetry.io/docs/specs/semconv/registry/attributes/url/) & server
|
|
397
412
|
|
|
398
|
-
| 字段 | 状态
|
|
399
|
-
| -------------------------------------- |
|
|
400
|
-
| `attributes.url.full` | 
|
|
401
|
-
| `attributes.url.scheme` | 
|
|
402
|
-
| `attributes.
|
|
403
|
-
| `attributes.http.
|
|
404
|
-
| `attributes.
|
|
405
|
-
| `attributes.server.
|
|
413
|
+
| 字段 | 状态 | 类型 | 描述 | |
|
|
414
|
+
| -------------------------------------- | ---------------------------------------------------------- | --- | ------ | ---------------------------- |
|
|
415
|
+
| `attributes.url.full` |  | str | 完整 URL | 如 `https://example.com/apm`。 |
|
|
416
|
+
| `attributes.url.scheme` |  | str | 协议 | 如 `ws`、`wss`。 |
|
|
417
|
+
| `attributes.url.template` |  | str | 请求路径 | 如 `/api/users/`。 |
|
|
418
|
+
| `attributes.http.request.method` |  | str | 请求方法 | 如 `GET`、`POST`。 |
|
|
419
|
+
| `attributes.http.response.status_code` |  | int | 返回码 | 如 `200`、`404`。 |
|
|
420
|
+
| `attributes.server.address` |  | str | 地址 | 如 `example.com`。 |
|
|
421
|
+
| `attributes.server.port` |  | int | 端口 | -- |
|
|
406
422
|
|
|
407
423
|
### k. vital
|
|
408
424
|
|
|
409
|
-
| 字段 | 状态
|
|
410
|
-
| --------------------------------------------- |
|
|
411
|
-
| `attributes.vital.id` | 
|
|
412
|
-
| `attributes.vital.metric` | 
|
|
413
|
-
| `attributes.vital.value` | 
|
|
414
|
-
| `attributes.vital.inp.input_delay` | 
|
|
415
|
-
| `attributes.vital.inp.interaction_target` | 
|
|
416
|
-
| `attributes.vital.inp.interaction_type` | 
|
|
417
|
-
| `attributes.vital.inp.processing_duration` | 
|
|
418
|
-
| `attributes.vital.inp.presentation_delay` | 
|
|
419
|
-
| `attributes.vital.lcp.target` | 
|
|
420
|
-
| `attributes.vital.lcp.url` | 
|
|
421
|
-
| `attributes.vital.lcp.resource_load_duration` | 
|
|
422
|
-
| `attributes.vital.lcp.element_render_delay` | 
|
|
423
|
-
| `attributes.vital.ttfb.waiting_duration` | 
|
|
424
|
-
| `attributes.vital.ttfb.dns_duration` | 
|
|
425
|
-
| `attributes.vital.ttfb.connection_duration` | 
|
|
426
|
-
| `attributes.vital.ttfb.request_duration` | 
|
|
425
|
+
| 字段 | 状态 | 类型 | 描述 | 备注 |
|
|
426
|
+
| --------------------------------------------- | ---------------------------------------------------------- | ------ | -------------------- | ------------------------------------ |
|
|
427
|
+
| `attributes.vital.id` |  | str | Vital 唯一标识 | |
|
|
428
|
+
| `attributes.vital.metric` |  | enum | 指标名 | |
|
|
429
|
+
| `attributes.vital.value` |  | number | 指标测量值 | |
|
|
430
|
+
| `attributes.vital.inp.input_delay` |  | number | 输入延迟(ms) | 用户发起交互(如点击)到事件处理器开始执行的等待时间,反映主线程繁忙程度 |
|
|
431
|
+
| `attributes.vital.inp.interaction_target` |  | str | 交互目标元素标识 | 如 `div`。 |
|
|
432
|
+
| `attributes.vital.inp.interaction_type` |  | str | 交互类型 | -- |
|
|
433
|
+
| `attributes.vital.inp.processing_duration` |  | number | 处理耗时(ms) | -- |
|
|
434
|
+
| `attributes.vital.inp.presentation_delay` |  | number | 呈现延迟(ms) | -- |
|
|
435
|
+
| `attributes.vital.lcp.target` |  | str | DOM 选择器 | 如 `div`。 |
|
|
436
|
+
| `attributes.vital.lcp.url` |  | str | 元素对应资源 URL(已脱敏) | -- |
|
|
437
|
+
| `attributes.vital.lcp.resource_load_duration` |  | number | 资源加载耗时(ms) | -- |
|
|
438
|
+
| `attributes.vital.lcp.element_render_delay` |  | number | 元素渲染延迟(ms) | -- |
|
|
439
|
+
| `attributes.vital.ttfb.waiting_duration` |  | number | 请求就绪后的等待耗时(ms) | -- |
|
|
440
|
+
| `attributes.vital.ttfb.dns_duration` |  | number | DNS 解析耗时(ms) | -- |
|
|
441
|
+
| `attributes.vital.ttfb.connection_duration` |  | number | TCP + TLS 连接建立耗时(ms) | -- |
|
|
442
|
+
| `attributes.vital.ttfb.request_duration` |  | number | 请求发送后等待首字节耗时(ms) | -- |
|
|
427
443
|
|
|
428
444
|
**[1] `attributes.vital.metric`**:
|
|
429
445
|
|
|
@@ -437,7 +453,9 @@ View B █████████████
|
|
|
437
453
|
|
|
438
454
|
**[2] `attributes.vital.value`**:CLS 单位为 `1`,FCP、INP、LCP、TTFB 单位为 `ms`。
|
|
439
455
|
|
|
440
|
-
**[3] `attributes.vital.
|
|
456
|
+
**[3] `attributes.vital.cls.largest_shift_value` & `attributes.vital.cls.largest_shift_target`**:当前浏览器 SDK 不上报;也不上报 `vital.cls.load_state`。CLS 只带公共 `vital.metric` / `vital.value` / `vital.id`。
|
|
457
|
+
|
|
458
|
+
**[4] `attributes.vital.inp.interaction_type`**:交互类型。
|
|
441
459
|
|
|
442
460
|
| 值 | 描述 |
|
|
443
461
|
| ------------- | ------------- |
|
|
@@ -446,21 +464,23 @@ View B █████████████
|
|
|
446
464
|
| `pointerdown` | 点击(鼠标、触屏、触控笔) |
|
|
447
465
|
| `pointerup` | 松开 |
|
|
448
466
|
|
|
449
|
-
**[
|
|
467
|
+
**[5] `attributes.vital.inp.processing_duration`**:事件处理回调(如 click handler)本身的执行时间,JS 逻辑过重时这个值会变大。
|
|
450
468
|
|
|
451
|
-
**[
|
|
469
|
+
**[6] `attributes.vital.inp.presentation_delay`**:回调操作完成之后到该帧最终显示在用户屏幕上所需的时间。
|
|
452
470
|
|
|
453
|
-
**[
|
|
471
|
+
**[7] `attributes.vital.lcp.element_render_delay`**:LCP 元素资源加载完成后,到浏览器真正渲染该元素之间的等待时间(主要由主线程阻塞(长任务/JS 执行)导致)。
|
|
454
472
|
|
|
455
|
-
**[
|
|
473
|
+
**[8] `attributes.vital.lcp.resource_load_duration`**:LCP 元素依赖的外部资源(图片/字体等)从请求到下载完成的时间(如果 LCP 是纯文本节点,此项可能缺失),用于排查 CDN/网络/资源体积问题。
|
|
456
474
|
|
|
457
|
-
**[
|
|
475
|
+
**[9] `attributes.vital.lcp.time_to_first_byte`**:当前浏览器 SDK 不上报该字段。LCP 归因只包含 url / target / element_render_delay / resource_load_duration。
|
|
458
476
|
|
|
459
|
-
**[
|
|
477
|
+
**[10] `attributes.vital.ttfb.waiting_duration`**:页面激活到浏览器开始 Fetch,或开始启动 Service Worker 前的时间(包含重定向及浏览器前置处理)。
|
|
460
478
|
|
|
461
|
-
**[
|
|
479
|
+
**[11] `attributes.vital.ttfb.dns_duration`**:解析慢通常由 DNS 服务器延迟、复杂 CNAME 链或本地 DNS 缓存失效导致(多国/多地域部署时此值可能偏高)。
|
|
462
480
|
|
|
463
|
-
**[
|
|
481
|
+
**[12] `attributes.vital.ttfb.connection_duration`**:TCP / QUIC 建连及 TLS 协商,连接复用时通常为 `0`。
|
|
482
|
+
|
|
483
|
+
**[13] `attributes.vital.ttfb.request_duration`**:建连结束到收到首字节,包含调度空档、请求发送、网络 RTT 和服务端处理。
|
|
464
484
|
|
|
465
485
|
|
|
466
486
|
### l. blank_screen
|
|
@@ -469,7 +489,7 @@ View B █████████████
|
|
|
469
489
|
| 字段 | 状态 | 类型 | 描述 | 备注 |
|
|
470
490
|
| ---------------------------------------------- | --------------------------------------------------------------- | ------- | ---------------- | ------------------ |
|
|
471
491
|
| `attributes.blank_screen.reason` *[1]* |  | str | 白屏判定原因 | |
|
|
472
|
-
| `attributes.blank_screen.empty_ratio` |  | number | 有效样本中的空白比例 |
|
|
492
|
+
| `attributes.blank_screen.empty_ratio` |  | number | 有效样本中的空白比例 | 回退根节点检测时仍为实际比例,不是固定 `1`。 |
|
|
473
493
|
| `attributes.blank_screen.empty_sample_count` |  | int | 空白采样数 | |
|
|
474
494
|
|
|
475
495
|
**[1] `attributes.blank_screen.reason`**:
|
|
@@ -477,7 +497,7 @@ View B █████████████
|
|
|
477
497
|
| 值 | 描述 |
|
|
478
498
|
| ---------------- | --------------------------------------------------------------------------------------- |
|
|
479
499
|
| `empty_viewport` | 配置的采样根元素存在,有效采样点的空白比例达到白屏阈值。 |
|
|
480
|
-
| `missing_root` |
|
|
500
|
+
| `missing_root` | 未找到 `root_selector` 指定的根元素,SDK 回退到 `body`(不可用时使用 `documentElement`)检测,且回退检测仍达到白屏阈值。 |
|
|
481
501
|
|
|
482
502
|
### m. longtask
|
|
483
503
|
|
|
@@ -500,4 +520,149 @@ View B █████████████
|
|
|
500
520
|
|
|
501
521
|
### n. custom
|
|
502
522
|
|
|
503
|
-
`reportCustomEvent()` 产生 `custom.<name>` Span
|
|
523
|
+
`reportCustomEvent()` 产生 `custom.<name>` Span。`reportAction({ name })` 产生 `action.<name>`,且 `action.type=custom`;不要把手动 Action 的 Span 名写成固定的 `action.custom`。
|
|
524
|
+
|
|
525
|
+
## 0x04 资源加载时序
|
|
526
|
+
|
|
527
|
+
本文对照 W3C Resource Timing、Chrome Timing 和 web.dev,并给出 Resource Span 请求时序的产品划分。适用范围是单次 `resource` Span 的阶段图,不含 View 导航瀑布。
|
|
528
|
+
|
|
529
|
+
阶段名称靠近 Chrome Timing。每段时长用已上报的 `attributes.resource.*.duration` 计算,起点用对应的 `start`,单位为毫秒,相对该资源 `startTime`。
|
|
530
|
+
|
|
531
|
+
产品按 `attributes.view.id` 关联 View 生命周期快照后,可用 `attributes.view.previous_url_template` 展示资源所属页面的前序路由。该字段与 `attributes.view.url_template` 使用同一模板规则,初始 View 为空字符串;它不参与 Resource Timing 阶段计算,也不直接写入 `resource` Span。
|
|
532
|
+
|
|
533
|
+
### a. W3C Resource Timing
|
|
534
|
+
|
|
535
|
+
规范记录的是时间点,不是产品上的色块。浏览器按发生顺序打点,产品上的每一段是相邻两点相减。来源:[Resource Timing](https://www.w3.org/TR/resource-timing/)。
|
|
536
|
+
|
|
537
|
+
| 顺序 | 时间点 | 含义 |
|
|
538
|
+
| --- | --- | --- |
|
|
539
|
+
| 1 | `startTime` | 这次取资源开始 |
|
|
540
|
+
| 2 | `redirectStart` | 第一次重定向开始 |
|
|
541
|
+
| 3 | `redirectEnd` | 最后一次重定向的响应收完 |
|
|
542
|
+
| 4 | `workerStart` | Service Worker 开始处理这次请求;未拦截时为 `0` |
|
|
543
|
+
| 5 | `fetchStart` | 重定向结束后,开始取最终资源 |
|
|
544
|
+
| 6 | `domainLookupStart` | DNS 查询开始 |
|
|
545
|
+
| 7 | `domainLookupEnd` | DNS 查询结束 |
|
|
546
|
+
| 8 | `connectStart` | 开始建立到服务器的连接 |
|
|
547
|
+
| 9 | `secureConnectionStart` | TLS 握手开始;非 HTTPS 时为 `0` |
|
|
548
|
+
| 10 | `connectEnd` | 连接建立完成,TLS 包含在内 |
|
|
549
|
+
| 11 | `requestStart` | 开始向服务器发请求 |
|
|
550
|
+
| 12 | `firstInterimResponseStart` | 中间响应,例如 `103` |
|
|
551
|
+
| 13 | `responseStart` | 收到响应首字节 |
|
|
552
|
+
| 14 | `finalResponseHeadersStart` | 最终响应头开始,通常是 `200` |
|
|
553
|
+
| 15 | `responseEnd` | 最后一字节到达,或连接先关闭 |
|
|
554
|
+
|
|
555
|
+
用上面的时间点可以算出这些耗时:
|
|
556
|
+
|
|
557
|
+
| 顺序 | 耗时 | 计算 |
|
|
558
|
+
| --- | --- | --- |
|
|
559
|
+
| 1 | 重定向 | `redirectEnd − redirectStart` |
|
|
560
|
+
| 2 | Service Worker | `fetchStart − workerStart` |
|
|
561
|
+
| 3 | DNS | `domainLookupEnd − domainLookupStart` |
|
|
562
|
+
| 4 | 建立连接(含 TLS) | `connectEnd − connectStart` |
|
|
563
|
+
| 5 | TLS 握手 | `connectEnd − secureConnectionStart` |
|
|
564
|
+
| 6 | 发出请求后等到首字节 | `responseStart − requestStart` |
|
|
565
|
+
| 7 | 接收响应体 | `responseEnd − responseStart` |
|
|
566
|
+
|
|
567
|
+
规范没有排队时间点。跨源资源未通过 Timing-Allow-Origin 检查时,重定向到 `responseStart` 之间的点会变成 `0`,只保留 `startTime`、`fetchStart`、总时长和 `responseEnd`。
|
|
568
|
+
|
|
569
|
+
`workerStart` 是重定向链最终请求上的 Service Worker 开始时间。`fetchStart` 是 post-redirect start。产品上的「后台脚本处理」发生在重定向之后。
|
|
570
|
+
|
|
571
|
+
### b. Chrome Timing
|
|
572
|
+
|
|
573
|
+
Chrome 开发者工具中,点开一条请求的 Timing。一次请求不会出现全部标签。来源:[Chrome 网络面板说明](https://developer.chrome.com/docs/devtools/network/reference)。
|
|
574
|
+
|
|
575
|
+
| 顺序 | Timing 标签 | 含义 |
|
|
576
|
+
| --- | --- | --- |
|
|
577
|
+
| 1 | Queueing | 连接开始前排队:存在更高优先级请求,或同一源连接数已满 |
|
|
578
|
+
| 2 | Stalled | 连接开始后仍可能因 Queueing 同类原因停滞 |
|
|
579
|
+
| 3 | DNS Lookup | 解析域名对应的 IP |
|
|
580
|
+
| 4 | Initial connection | 建立连接,包含 TCP 握手和 TLS,不单列 TLS |
|
|
581
|
+
| 5 | Proxy negotiation | 与代理协商,仅走代理时出现 |
|
|
582
|
+
| 6 | Request sent | 正在发送 HTTP 请求 |
|
|
583
|
+
| 7 | ServiceWorker Preparation | 正在启动 Service Worker |
|
|
584
|
+
| 8 | Request to ServiceWorker | 请求交给 Service Worker |
|
|
585
|
+
| 9 | Waiting (TTFB) | 请求已发出,等待响应首字节。包含一趟网络往返和服务器准备时间 |
|
|
586
|
+
| 10 | Content Download | 读取响应体 |
|
|
587
|
+
|
|
588
|
+
常见可见:Queueing、DNS Lookup、Initial connection、Waiting (TTFB)、Content Download。连接已建立时,DNS Lookup 和 Initial connection 经常为 `0`。
|
|
589
|
+
|
|
590
|
+
Chrome 不单独上报 Queueing / Stalled / Request sent 到 RUM 字段,产品阶段图无法画出这三行。
|
|
591
|
+
|
|
592
|
+
### c. Google web.dev
|
|
593
|
+
|
|
594
|
+
web.dev 讲解同一组时间点,并单独定义页面导航的 Time to First Byte(TTFB,首字节时间)。来源:[Navigation and Resource Timing](https://web.dev/articles/navigation-and-resource-timing)、[TTFB](https://web.dev/articles/ttfb)。
|
|
595
|
+
|
|
596
|
+
| 顺序 | 阶段 | 时间点 | 含义 |
|
|
597
|
+
| --- | --- | --- | --- |
|
|
598
|
+
| 1 | Redirects | `redirectStart` / `redirectEnd` | HTTP 重定向 |
|
|
599
|
+
| 2 | DNS lookup | `domainLookupStart` / `domainLookupEnd` | DNS 解析 |
|
|
600
|
+
| 3 | Connection | `connectStart` → `secureConnectionStart` → `connectEnd` | 建连,HTTPS 时包含 TLS,TLS 耗时 = `connectEnd − secureConnectionStart` |
|
|
601
|
+
| 4 | Fetch | `fetchStart` | 开始取资源,会先查缓存 |
|
|
602
|
+
| 5 | Service worker | `workerStart` | 未拦截时为 `0` |
|
|
603
|
+
| 6 | Request | `requestStart` → `responseStart` | 发出请求到收到首字节 |
|
|
604
|
+
| 7 | Response | `responseStart` → `responseEnd` | 接收响应体 |
|
|
605
|
+
|
|
606
|
+
web.dev 的页面 TTFB 从导航开始算到 `responseStart`,包含:
|
|
607
|
+
|
|
608
|
+
1. 重定向
|
|
609
|
+
2. Service Worker 启动(如有)
|
|
610
|
+
3. DNS
|
|
611
|
+
4. 建连和 TLS
|
|
612
|
+
5. 发出请求直到首字节到达
|
|
613
|
+
|
|
614
|
+
Chrome Timing 的 Waiting (TTFB) 只等于第 `5` 项。Resource Span 的「等待首字节」跟 Chrome 这一行走,对应 `resource.first_byte.duration`。
|
|
615
|
+
|
|
616
|
+
### d. 产品建议
|
|
617
|
+
|
|
618
|
+
始终展示查找服务器、建立连接、加密连接、等待首字节、下载内容。上报了重定向或 Service Worker 时,再增加对应行。
|
|
619
|
+
|
|
620
|
+
时长用 `resource.*.duration`。建立连接需要减去 TLS:W3C 的 `connectEnd − connectStart` 已包含加密,直接展示完整 `connect.duration` 会和下一行重复。无 `ssl` 时使用完整 `connect.duration`。
|
|
621
|
+
|
|
622
|
+
#### 阶段与计算
|
|
623
|
+
|
|
624
|
+
| 顺序 | 产品名 | 出现条件 | 时长 |
|
|
625
|
+
| --- | --- | --- | --- |
|
|
626
|
+
| 1 | 重定向 | 上报了 `redirect.start` 和 `redirect.duration` | `attributes.resource.redirect.duration` |
|
|
627
|
+
| 2 | 后台脚本处理 | 上报了 `worker.start` 和 `worker.duration` | `attributes.resource.worker.duration` |
|
|
628
|
+
| 3 | 查找服务器 | 始终占一行 | `attributes.resource.dns.duration` |
|
|
629
|
+
| 4 | 建立连接 | 始终占一行 | 有 `ssl` 时:`connect.duration − ssl.duration`<br />无 `ssl` 时:`connect.duration` |
|
|
630
|
+
| 5 | 加密连接 | 始终占一行 | `attributes.resource.ssl.duration` |
|
|
631
|
+
| 6 | 等待首字节 | 始终占一行 | `attributes.resource.first_byte.duration` |
|
|
632
|
+
| 7 | 下载内容 | 始终占一行 | `attributes.resource.download.duration` |
|
|
633
|
+
|
|
634
|
+
时间轴上,建立连接画到 `ssl.start`,加密连接从 `ssl.start` 画到 `connect` 结束。
|
|
635
|
+
|
|
636
|
+
#### 说明与用户感受
|
|
637
|
+
|
|
638
|
+
| 阶段 | 说明 | 用户感受 |
|
|
639
|
+
| --- | --- | --- |
|
|
640
|
+
| 重定向 | [a] 浏览器跟随 HTTP 重定向,直到拿到最终 URL,对应 `redirectEnd − redirectStart`<br />[b] 未发生重定向时不上报 | [a] 目标内容还没开始出现<br />[b] 文档请求会延长白屏,接口请求会延长 loading |
|
|
641
|
+
| 后台脚本处理 | [a] Service Worker 拦截并处理该请求的时间,对应 `fetchStart − workerStart`<br />[b] 记录的是重定向之后、最终请求上的处理<br />[c] 未拦截时不上报 | [a] 界面没有单独提示<br />[b] 用户只会感到这次加载更慢,无法分辨是后台脚本在处理 |
|
|
642
|
+
| 查找服务器 | [a] DNS 解析耗时,对应 `domainLookupEnd − domainLookupStart`<br />[b] 解析结果已缓存、或未发起新查询时,可能为 `0` 或不上报 | [a] 内容尚未出现<br />[b] 用户无法感知「正在解析域名」,体验上仍是点了之后没有反应 |
|
|
643
|
+
| 建立连接 | [a] 传输连接中扣除 TLS 后的部分<br />[b] W3C 的 `connectEnd − connectStart` 包含加密,产品用 `connect.duration − ssl.duration`,避免与下一行重复 | [a] 内容尚未出现<br />[b] 用户无法感知「正在建连」,体验上仍是在等待 |
|
|
644
|
+
| 加密连接 | [a] TLS 握手,对应 `connectEnd − secureConnectionStart`<br />[b] 非 HTTPS、或未发生新握手时不上报 | [a] 内容尚未出现<br />[b] 用户无法感知「正在握手」,体验上仍是在等待 |
|
|
645
|
+
| 等待首字节 | [a] 从发出请求到收到响应首字节,对应 `responseStart − requestStart`<br />[b] 包含网络往返和服务端处理,浏览器时序无法拆分<br />[c] 对齐 Chrome Waiting (TTFB),范围小于 web.dev 的页面 TTFB | [a] 本次请求的内容仍不可见:页面持续白屏或停留在旧画面,接口持续 loading<br />[b] 过慢时会感觉页面没有反应 |
|
|
646
|
+
| 下载内容 | [a] 从收到首字节到响应体接收完毕,对应 `responseEnd − responseStart`<br />[b] 耗时主要随体积和带宽变化 | [a] 内容开始出现并逐渐完整,图片、脚本会陆续可见<br />[b] 接口数据会从空状态填到页面上<br />[c] 体积大时,用户能感到「出来了但还在加载」 |
|
|
647
|
+
|
|
648
|
+
等待首字节拆不开服务端处理与网络往返。要判断服务端是否慢,需要结合 Trace 或 [Server Timing](https://www.w3.org/TR/server-timing/)。
|
|
649
|
+
|
|
650
|
+
#### 缺数字段
|
|
651
|
+
|
|
652
|
+
| 上报情况 | 页面展示 |
|
|
653
|
+
| --- | --- |
|
|
654
|
+
| `start` 与 `duration` 都在,且 `duration > 0` | 显示毫秒数,画出色块 |
|
|
655
|
+
| `start` 与 `duration` 都在,且 `duration = 0` | 写 `0` 毫秒。该步骤没有额外耗时 |
|
|
656
|
+
| 缺少 `start` 或 `duration` | 写「没有上报」,不画色块。可能该步骤未发生,也可能跨源不允许查看细分时间 |
|
|
657
|
+
|
|
658
|
+
查找服务器、建立连接、加密连接都没有上报时,写「没有上报」。跨源资源未暴露细分时间时表现相同,不能据此判断连接复用。
|
|
659
|
+
|
|
660
|
+
### e. 参考资料
|
|
661
|
+
|
|
662
|
+
| 来源 | 文档 |
|
|
663
|
+
| --- | --- |
|
|
664
|
+
| W3C | [Resource Timing](https://www.w3.org/TR/resource-timing/) |
|
|
665
|
+
| W3C | [Server Timing](https://www.w3.org/TR/server-timing/) |
|
|
666
|
+
| Chrome | [网络面板 · Timing](https://developer.chrome.com/docs/devtools/network/reference) |
|
|
667
|
+
| web.dev | [Navigation and Resource Timing](https://web.dev/articles/navigation-and-resource-timing) |
|
|
668
|
+
| web.dev | [Time to First Byte](https://web.dev/articles/ttfb) |
|