@blueking/open-telemetry 0.0.31 → 0.0.33
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 +71 -33
- package/dist/bk-rum.global.js +2 -2
- package/dist/bk-rum.global.js.map +1 -1
- package/dist/core/plugin.d.ts +3 -0
- package/dist/index.js +461 -354
- package/dist/index.js.map +1 -1
- package/dist/plugins/web-vitals.d.ts +1 -1
- package/dist/schema/attributes.d.ts +1 -0
- package/dist/schema/span.d.ts +10 -0
- package/package.json +1 -1
- package/skills/bk-rum-otele/SKILL.md +1 -1
- package/skills/bk-rum-otele/evals/evals.json +1 -1
- package/skills/bk-rum-otele/references/actions.md +16 -10
- package/skills/bk-rum-otele/references/api.md +6 -3
- package/skills/bk-rum-otele/references/architecture.md +4 -4
- package/skills/bk-rum-otele/references/blank-screen.md +10 -19
- package/skills/bk-rum-otele/references/capabilities.md +18 -18
- package/skills/bk-rum-otele/references/configuration.md +5 -5
- package/skills/bk-rum-otele/references/data-model.md +14 -16
- package/skills/bk-rum-otele/references/errors-security.md +9 -8
- 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 +21 -2
- package/skills/bk-rum-otele/references/network.md +21 -22
- package/skills/bk-rum-otele/references/performance.md +14 -25
- package/skills/bk-rum-otele/references/privacy.md +1 -1
- package/skills/bk-rum-otele/references/session-context.md +16 -12
- package/skills/bk-rum-otele/references/span-protocol.md +192 -282
- package/skills/bk-rum-otele/references/telemetry-reference.md +97 -99
- package/skills/bk-rum-otele/references/transport-sampling.md +19 -14
- package/skills/bk-rum-otele/references/troubleshooting.md +4 -4
- package/skills/bk-rum-otele/references/views-routing.md +5 -4
package/README.md
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
# @blueking/open-telemetry
|
|
2
2
|
|
|
3
|
-
面向浏览器真实用户监控(RUM)的 OpenTelemetry SDK。它把 Session、View、Fetch/XHR、静态资源、错误、Web Vitals、Action、白屏、Long Task、WebSocket、CSP 与设备上下文建模为原始 Span,并通过 OTLP/HTTP JSON
|
|
3
|
+
面向浏览器真实用户监控(RUM)的 OpenTelemetry SDK。它把 Session、View、Fetch/XHR、静态资源、错误、Web Vitals、Action、白屏、Long Task、WebSocket、CSP 与设备上下文建模为原始 Span,并通过 OTLP/HTTP JSON 上报。其中 Long Task、WebSocket 和 CSP 默认关闭,见下方能力表。
|
|
4
4
|
|
|
5
5
|
SDK 只创建一个 `WebTracerProvider`:
|
|
6
6
|
|
|
7
7
|
```text
|
|
8
8
|
Browser events
|
|
9
9
|
→ Session / View / Action runtime context
|
|
10
|
-
→
|
|
11
|
-
→
|
|
10
|
+
→ Span 创建:RumSessionSampler 决定是否记录(未采样即 non-recording)
|
|
11
|
+
→ FilteringSpanProcessor.onStart 补齐缺失的运行时属性
|
|
12
|
+
→ FilteringSpanProcessor.onEnd 校验 Session/View、丢弃标记、tracking.beforeSend
|
|
12
13
|
→ Simple/BatchSpanProcessor
|
|
13
14
|
→ POST <transport.endpoint>/v1/rum
|
|
14
15
|
```
|
|
@@ -39,25 +40,43 @@ export const rum = new BkOpenTelemetry({
|
|
|
39
40
|
|
|
40
41
|
`application.name` 和 `transport.endpoint` 必填。endpoint 是根地址,SDK 去掉末尾斜杠后固定追加 `/v1/rum`。构造后默认自动启动。
|
|
41
42
|
|
|
43
|
+
ESM 构建把 OpenTelemetry 依赖保留为外部 package dependencies,由应用的构建工具解析。所有插件在没有 `window` / `document` 的环境里会跳过初始化,因此可以安全地在 SSR 产物中被 import。
|
|
44
|
+
|
|
45
|
+
### CDN
|
|
46
|
+
|
|
47
|
+
无构建流程的页面可以用全局包,依赖已打进 bundle:
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<script src="https://unpkg.com/@blueking/open-telemetry@0.0.32/dist/bk-rum.global.js"></script>
|
|
51
|
+
<script>
|
|
52
|
+
window.rum = new window.BkOpenTelemetry({
|
|
53
|
+
application: { name: 'legacy-portal', environment: 'production' },
|
|
54
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
55
|
+
});
|
|
56
|
+
</script>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
CDN 入口只暴露 `window.BkOpenTelemetry` 这一个构造函数,不提供 `createXxxPlugin()`、`RUM_ATTRIBUTES` 等具名导出和 TypeScript 类型;需要这些请走 npm ESM 构建。生产环境应固定版本号并配合自有 CDN/SRI 策略,不要长期跟随 latest。
|
|
60
|
+
|
|
42
61
|
完整接入步骤见[快速上手](./wikis/getting-started.md),上线前请继续阅读[生产接入指南](./wikis/production.md)。
|
|
43
62
|
|
|
44
63
|
## 默认能力
|
|
45
64
|
|
|
46
65
|
| 能力 | 默认 | 浏览器来源 | 主要产出 |
|
|
47
66
|
| --- | --- | --- | --- |
|
|
48
|
-
| Session | 基础能力 | localStorage、用户活动、visibility | `
|
|
49
|
-
| View / Router | auto | Navigation Timing、History、hash、BFCache |
|
|
67
|
+
| Session | 基础能力 | localStorage、用户活动、visibility | `session.start` / `session.rotate` / `session.end` |
|
|
68
|
+
| View / Router | auto | Navigation Timing、History、hash、BFCache | `<view.name>` start/update/end |
|
|
50
69
|
| View Loading Time | 开 | 请求、DOM、资源、`window.open` activity | `view.loading_time` |
|
|
51
|
-
| Fetch/XHR | 开 | fetch、XMLHttpRequest、Resource Timing |
|
|
52
|
-
| 静态资源 | 开 | Resource PerformanceObserver | `
|
|
70
|
+
| Fetch/XHR | 开 | fetch、XMLHttpRequest、Resource Timing | `<METHOD> <url.template>` CLIENT |
|
|
71
|
+
| 静态资源 | 开 | Resource PerformanceObserver | `GET <url.template>` CLIENT |
|
|
53
72
|
| Error | 开 | error、unhandledrejection、资源加载错误 | 三类 Error Span + exception event |
|
|
54
73
|
| Web Vitals | 开 | web-vitals / PerformanceObserver | CLS/FCP/INP/LCP/TTFB Span |
|
|
55
|
-
| Action | 开 | click 与 activity | `action.
|
|
56
|
-
| Blank Screen | 开 | 页面稳定 + DOM 九点采样 | `
|
|
74
|
+
| Action | 开 | 主键 click 与 activity | `action.name`、挫败信号 |
|
|
75
|
+
| Blank Screen | 开 | 页面稳定 + DOM 九点采样 | `blank_screen.<reason>` |
|
|
57
76
|
| Device | 开 | UA/UA-CH、Screen、Network Information | Resource 与运行时属性 |
|
|
58
|
-
| Long Task | 关 | Long Animation Frame / Long Tasks | `
|
|
59
|
-
| WebSocket | 关 | WebSocket 生命周期 |
|
|
60
|
-
| CSP | 关 | securitypolicyviolation | `csp
|
|
77
|
+
| Long Task | 关 | Long Animation Frame / Long Tasks | `long_task.entry_type` |
|
|
78
|
+
| WebSocket | 关 | WebSocket 生命周期 | `websocket.<phase>` |
|
|
79
|
+
| CSP | 关 | securitypolicyviolation | `csp.<effective_directive>` |
|
|
61
80
|
|
|
62
81
|
Session 和 View 是普通 Span 的必要关联边界,不能通过一个 `tracking.session: false` 关闭。精确默认值、降级行为和成本见[能力矩阵](./wikis/capabilities.md)。
|
|
63
82
|
|
|
@@ -147,9 +166,9 @@ Authorization: Bearer <token> # 配置 token 时
|
|
|
147
166
|
}
|
|
148
167
|
```
|
|
149
168
|
|
|
150
|
-
当前使用 `@opentelemetry/exporter-trace-otlp-http@0.217.0` 的浏览器 JSON exporter
|
|
169
|
+
当前使用 `@opentelemetry/exporter-trace-otlp-http@0.217.0` 的浏览器 JSON exporter:429/502/503/504 和部分网络错误可重试,并支持 `Retry-After`。
|
|
151
170
|
|
|
152
|
-
|
|
171
|
+
超时、并发和批处理参数本包不硬编码,未配置时沿用锁定依赖的默认值:请求超时 10 秒、并发出口上限 30、BatchSpanProcessor queue 2048 / batch 512 / delay 5000ms / export timeout 30000ms。队列满后新结束的 Span 被丢弃。升级 OTel 依赖时需重新核对这些数值。详细重试、keepalive、flush 与 CORS 规则见[上报协议、批处理与采样](./wikis/reference/transport.md)。
|
|
153
172
|
|
|
154
173
|
## Session 采样与导出条件
|
|
155
174
|
|
|
@@ -164,7 +183,7 @@ session: {
|
|
|
164
183
|
- 同一 Session 的决定一致,轮换后重新计算;
|
|
165
184
|
- 未采样时 `startSpan()` 返回 non-recording Span,手动事件不导出;
|
|
166
185
|
- 普通 Span 还必须有有效 `session.id` 与 `view.id`;
|
|
167
|
-
- `
|
|
186
|
+
- `span_type=session` 是允许没有 View 的例外;
|
|
168
187
|
- SDK 自身 `/v1/rum` 请求、显式 discard 和 beforeSend 返回 false 的 Span 会被过滤。
|
|
169
188
|
|
|
170
189
|
## 手动事件
|
|
@@ -186,13 +205,26 @@ rum.reportCustomEvent({
|
|
|
186
205
|
});
|
|
187
206
|
```
|
|
188
207
|
|
|
189
|
-
- `reportAction()`
|
|
208
|
+
- `reportAction()` 立即创建并结束 `<action.name>`(上例为 `submit-order`,`action.type=custom`),不是持续关联后续请求的自动 Action;
|
|
190
209
|
- `reportCustomEvent()` 创建 `custom.<name>`;带 Error 时记录 exception 和 ERROR status;
|
|
191
210
|
- name 是检索维度,必须有限枚举,不能拼用户/订单/随机 ID;
|
|
192
211
|
- 两者都受当前 Session 采样约束。
|
|
193
212
|
|
|
194
213
|
默认 `autoStart: true` 是异步启动,构造后立即同步调用的手动事件不会排队,可能因为 View 尚未建立而丢失。首个手动事件不能丢时,使用 `autoStart: false`,先 `await rum.start()`,manual View 再调用 `startView()`,之后才开放业务上报。
|
|
195
214
|
|
|
215
|
+
## 生命周期
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
await rum.start(); // autoStart: false 时显式启动
|
|
219
|
+
await rum.flush(); // 尽力导出已结束 Span
|
|
220
|
+
await rum.shutdown(); // 卸载插件、flush、销毁 Provider
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
- `start()` 幂等;`enabled: false` 或 Consent 未授权时会标记为已启动但不安装采集;
|
|
224
|
+
- 单个插件初始化失败被隔离,不会让 `start()` reject,`debug: true` 时打印 warning;
|
|
225
|
+
- `flush()` 只等待 SDK 完成导出调用,不代表服务端已持久化;SDK 也会在 `pagehide` 和页面转入 hidden 时自动尽力 flush;
|
|
226
|
+
- `shutdown()` 后实例**不可重启**,再次 `start()` 会抛错,需要重新 `new`;临时停止采集应用 `setTrackingConsent('not-granted')`。
|
|
227
|
+
|
|
196
228
|
## 用户和 View
|
|
197
229
|
|
|
198
230
|
```ts
|
|
@@ -236,7 +268,7 @@ await rum.setTrackingConsent('not-granted');
|
|
|
236
268
|
|
|
237
269
|
未授权时不安装插件/instrumentation。撤销会关闭采集、清理 Session 上下文并 flush 已结束的队列数据,但不会删除服务端已经接收的数据,也不会删除 localStorage 中仍有效的 Session 记录;再次授权后可能复用该 Session。
|
|
238
270
|
|
|
239
|
-
`trackingConsent: 'not-granted'` 控制的是采集和发送,不会推迟构造阶段的所有浏览器读取:只要 `tracking.device !== false`,`new BkOpenTelemetry()` 仍会读取 UA
|
|
271
|
+
`trackingConsent: 'not-granted'` 控制的是采集和发送,不会推迟构造阶段的所有浏览器读取:只要 `tracking.device !== false`,`new BkOpenTelemetry()` 仍会读取 `navigator.userAgent` 与 UA-CH,生成 `user_agent.*` 和 `device.type` 四个 Device Resource 字段,但此时不会发送。SDK 不读取设备内存或逻辑处理器数。合规要求“授权前不能读取 User-Agent”时,应在授权后再构造实例。完整边界见[隐私、Consent 与字段治理](./wikis/reference/privacy.md)。
|
|
240
272
|
|
|
241
273
|
## 扩展
|
|
242
274
|
|
|
@@ -269,26 +301,28 @@ SDK 默认不附加独立页面属性;页面地址使用经过 `redactUrl` 处
|
|
|
269
301
|
|
|
270
302
|
OTLP 字段分五层:
|
|
271
303
|
|
|
272
|
-
1. Resource:`service.name
|
|
273
|
-
2. Scope
|
|
274
|
-
3. Span envelope
|
|
275
|
-
4. RUM attributes
|
|
276
|
-
5. Span events
|
|
304
|
+
1. Resource:`service.name`、`deployment.environment.name`、`service.version`、`telemetry.sdk.*`、`session.sample_rate`,以及 UA/UA-CH 派生的 `user_agent.*` 和 `device.type`;
|
|
305
|
+
2. Scope:`scope.name = "bk-rum"`(不带 version);
|
|
306
|
+
3. Span envelope:`traceId` / `spanId`、纳秒起止时间、`kind`、`status`、`links`;
|
|
307
|
+
4. RUM attributes:`session.id` / `view.id` / `action.id` / `user.id` 关联字段,加上分类字段 `span_type` 和 `outcome.type`;
|
|
308
|
+
5. Span events:`exception`、`long_task.script`、`long_task.attribution`。
|
|
309
|
+
|
|
310
|
+
分类只用 `span_type`(`session` / `view` / `resource` / `error` / `vital` / `long_task` / `action` / `websocket` / `custom`)和 `outcome.type`(`success` / `warning` / `error` / `timeout` / `abort`)两个字段。当前 SDK **不写** `outcome.reason`,也没有 `event.*` 或 `result` 字段。
|
|
277
311
|
|
|
278
|
-
|
|
312
|
+
主要 Span 及其实际产出的领域字段:
|
|
279
313
|
|
|
280
|
-
| Span |
|
|
314
|
+
| Span | 领域字段 |
|
|
281
315
|
| --- | --- |
|
|
282
|
-
| `
|
|
283
|
-
|
|
|
284
|
-
| `
|
|
285
|
-
| Error
|
|
286
|
-
| `
|
|
287
|
-
| `
|
|
288
|
-
| `
|
|
289
|
-
| `
|
|
316
|
+
| `session.<phase>` | `session.phase`、`session.id`、`session.type`、`session.has_replay` |
|
|
317
|
+
| `<view.name>` | `view.phase`、`view.version`、`view.url` / `url_template` / `previous*`、`loading_type`、`loading_time` / `loading_time_source`、初始导航 timing、`view.end_reason` |
|
|
318
|
+
| `<method> <url.template>` | `url.full` / `url.template`、`http.request.method` / `response.status_code`、`resource.type` / `size` / `protocol` / `cache.hit`、DNS/TCP/TLS/首字节/下载阶段 |
|
|
319
|
+
| Error Span | `error.message` / `source` / `handled`、`code.filepath` / `lineno` / `column`、`exception` Event |
|
|
320
|
+
| `<VITAL_METRIC>` | `vital.metric` / `value` / `id`,以及 LCP/INP/TTFB 的部分 attribution |
|
|
321
|
+
| `click <target>` | `action.id` / `name` / `type` / `target.name` / `target.tag` / `frustration.type` |
|
|
322
|
+
| `blank_screen.<reason>` | `blank_screen.reason` / `empty_ratio` / `empty_sample_count` |
|
|
323
|
+
| `<long_task.entry_type>` | `long_task.id` / `entry_type` / `name`,LoAF 的 `blocking_duration` 等,加 script/attribution Event |
|
|
290
324
|
|
|
291
|
-
|
|
325
|
+
持续时间统一用 Span 起止时间表达,没有 `action.loading_time`、`long_task.duration` 这类耗时 Attribute。完整层级见[RUM 数据模型](./wikis/concepts/data-model.md),逐字段定义和「当前不会出现的字段」清单见[遥测字段字典](./wikis/reference/telemetry.md)。
|
|
292
326
|
|
|
293
327
|
## 调试
|
|
294
328
|
|
|
@@ -324,14 +358,18 @@ await rum.flush();
|
|
|
324
358
|
| 任务 | 文档 |
|
|
325
359
|
| --- | --- |
|
|
326
360
|
| 首次安装和验证 | [快速上手](./wikis/getting-started.md) |
|
|
361
|
+
| 用 AI 安装 Skill 并生成配置 | [用 AI 接入](./wikis/ai-setup.md) |
|
|
327
362
|
| 上线检查和容量/隐私/CORS | [生产接入指南](./wikis/production.md) |
|
|
328
363
|
| 判断支持范围、默认开关和降级 | [能力矩阵](./wikis/capabilities.md) |
|
|
329
364
|
| Vue/React/Router/SSR/微前端 | [框架与路由集成](./wikis/framework-integration.md) |
|
|
330
365
|
| 理解模块、启动、过滤和导出 | [架构与数据流](./wikis/concepts/architecture.md) |
|
|
331
366
|
| 理解 OTLP 层级和字段归属 | [RUM 数据模型](./wikis/concepts/data-model.md) |
|
|
367
|
+
| 深入单项采集算法和阈值 | [Session](./wikis/features/session-context.md)、[View](./wikis/features/views-routing.md)、[网络](./wikis/features/network.md)、[Action](./wikis/features/actions.md)、[性能](./wikis/features/performance.md)、[错误与 CSP](./wikis/features/errors-security.md)、[白屏](./wikis/features/blank-screen.md) |
|
|
368
|
+
| 写自定义插件或接第三方 Instrumentation | [插件与 OpenTelemetry 扩展](./wikis/features/extensions.md) |
|
|
332
369
|
| 查全部配置和默认值 | [配置参考](./wikis/reference/configuration.md) |
|
|
333
370
|
| 查类、方法、类型和扩展 API | [API 参考](./wikis/reference/api.md) |
|
|
334
371
|
| 查 Span 名和逐字段定义 | [遥测字段字典](./wikis/reference/telemetry.md) |
|
|
372
|
+
| 对齐前后端字段语义和稳定性承诺 | [RUM 语义约定](./wikis/reference/span-protocol.md) |
|
|
335
373
|
| 查协议、batch、重试和采样 | [上报协议、批处理与采样](./wikis/reference/transport.md) |
|
|
336
374
|
| 查 Consent 和脱敏边界 | [隐私、Consent 与字段治理](./wikis/reference/privacy.md) |
|
|
337
375
|
| 解决无数据、重复、缺字段和误报 | [调试与排障](./wikis/reference/troubleshooting.md) |
|