@blueking/open-telemetry 0.0.22 → 0.0.24
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 +256 -70
- package/dist/bk-rum.global.js +2 -2
- package/dist/bk-rum.global.js.map +1 -1
- package/dist/core/config.d.ts +4 -2
- package/dist/core/processor.d.ts +2 -2
- package/dist/core/runtime-context.d.ts +4 -0
- package/dist/core/sampling.d.ts +0 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +395 -477
- package/dist/index.js.map +1 -1
- package/dist/plugins/blank-screen.d.ts +1 -1
- package/dist/plugins/common.d.ts +3 -4
- package/dist/plugins/web-vitals.d.ts +0 -5
- package/dist/schema/attributes.d.ts +6 -8
- package/dist/schema/span.d.ts +24 -15
- package/package.json +1 -1
- package/skills/bk-rum-otele/SKILL.md +26 -23
- package/skills/bk-rum-otele/references/actions.md +166 -0
- package/skills/bk-rum-otele/references/api.md +248 -215
- package/skills/bk-rum-otele/references/architecture.md +139 -37
- package/skills/bk-rum-otele/references/blank-screen.md +190 -0
- package/skills/bk-rum-otele/references/capabilities.md +175 -83
- package/skills/bk-rum-otele/references/configuration.md +226 -151
- package/skills/bk-rum-otele/references/data-model.md +156 -24
- package/skills/bk-rum-otele/references/errors-security.md +168 -0
- package/skills/bk-rum-otele/references/extensions.md +236 -0
- package/skills/bk-rum-otele/references/framework-integration.md +318 -75
- package/skills/bk-rum-otele/references/getting-started.md +186 -70
- package/skills/bk-rum-otele/references/network.md +258 -0
- package/skills/bk-rum-otele/references/performance.md +197 -0
- package/skills/bk-rum-otele/references/privacy.md +236 -67
- package/skills/bk-rum-otele/references/production.md +264 -0
- package/skills/bk-rum-otele/references/session-context.md +185 -0
- package/skills/bk-rum-otele/references/telemetry-reference.md +479 -51
- package/skills/bk-rum-otele/references/transport-sampling.md +318 -32
- package/skills/bk-rum-otele/references/troubleshooting.md +341 -151
- package/skills/bk-rum-otele/references/views-routing.md +211 -0
- package/skills/bk-rum-otele/references/concepts.md +0 -60
- package/skills/bk-rum-otele/references/custom-plugin.md +0 -170
- package/skills/bk-rum-otele/references/plugins-basic.md +0 -135
- package/skills/bk-rum-otele/references/plugins-error-security.md +0 -83
- package/skills/bk-rum-otele/references/plugins-experience.md +0 -124
- package/skills/bk-rum-otele/references/plugins-network.md +0 -32
- package/skills/bk-rum-otele/references/plugins.md +0 -62
|
@@ -2,226 +2,301 @@
|
|
|
2
2
|
|
|
3
3
|
# 配置参考
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
本文按 `BkOTOptions` 的当前 TypeScript 定义列出全部公开配置、默认值和约束。源码只校验真正必填的字段;浏览器兼容、隐私与基数治理仍需要接入方负责。
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import { BkOpenTelemetry, type BkOTOptions } from '@blueking/open-telemetry';
|
|
9
|
-
|
|
10
|
-
const options: BkOTOptions = {
|
|
11
|
-
application: { name: 'bk-monitor-web' },
|
|
12
|
-
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
13
|
-
};
|
|
7
|
+
## 完整结构
|
|
14
8
|
|
|
15
|
-
|
|
9
|
+
```ts
|
|
10
|
+
new BkOpenTelemetry({
|
|
11
|
+
application: { name, environment?, version? },
|
|
12
|
+
transport: {
|
|
13
|
+
endpoint,
|
|
14
|
+
token?, headers?, processor?, batch?, timeoutMillis?, concurrencyLimit?,
|
|
15
|
+
},
|
|
16
|
+
autoStart?,
|
|
17
|
+
enabled?,
|
|
18
|
+
debug?,
|
|
19
|
+
session: { sampleRate?, storageKey? },
|
|
20
|
+
context: { user?, attributes? },
|
|
21
|
+
privacy: { trackingConsent?, redactUrl?, redactAttributes? },
|
|
22
|
+
tracking: {
|
|
23
|
+
request?, resource?, error?, webVitals?, action?, blankScreen?, device?,
|
|
24
|
+
longTask?, websocket?, cspViolation?, view?, beforeSend?,
|
|
25
|
+
},
|
|
26
|
+
extensions: { plugins?, instrumentations? },
|
|
27
|
+
});
|
|
16
28
|
```
|
|
17
29
|
|
|
18
30
|
## 顶层配置
|
|
19
31
|
|
|
20
|
-
|
|
|
32
|
+
| 配置 | 类型 | 默认 | 说明 |
|
|
21
33
|
| --- | --- | --- | --- |
|
|
22
|
-
| `application` | `BkOTApplicationConfig` | 必填 | 应用 Resource
|
|
23
|
-
| `transport` | `BkOTTransportConfig` | 必填 |
|
|
24
|
-
| `
|
|
25
|
-
| `
|
|
26
|
-
| `
|
|
27
|
-
| `
|
|
28
|
-
| `
|
|
29
|
-
| `
|
|
30
|
-
| `
|
|
31
|
-
| `
|
|
34
|
+
| `application` | `BkOTApplicationConfig` | 必填 | 应用 Resource 信息 |
|
|
35
|
+
| `transport` | `BkOTTransportConfig` | 必填 | 唯一 Trace 上报通道 |
|
|
36
|
+
| `autoStart` | `boolean` | `true` | 构造后异步调用 `start()` |
|
|
37
|
+
| `enabled` | `boolean` | `true` | `false` 时不启动采集;Provider 仍会构造,便于公开 API 形态稳定 |
|
|
38
|
+
| `debug` | `boolean` | `false` | 打印待导出 Span,并显示部分插件初始化/丢弃警告 |
|
|
39
|
+
| `session` | `BkOTSessionConfig` | `{ sampleRate: 1 }` | 会话采样和存储 key |
|
|
40
|
+
| `context` | `BkOTContextConfig` | 无 | 初始用户及按事件读取的自定义属性 |
|
|
41
|
+
| `privacy` | `BkOTPrivacyConfig` | 已授权、默认 URL 清洗 | Consent 与脱敏 Hook |
|
|
42
|
+
| `tracking` | `BkOTTrackingConfig` | 见能力矩阵 | 内置采集开关和参数 |
|
|
43
|
+
| `extensions` | `BkOTExtensionsConfig` | 空数组 | 自定义 RUM 插件和 OTel instrumentation |
|
|
44
|
+
|
|
45
|
+
如果要调用 `use()` 或 `useInstrumentation()`,必须设置 `autoStart: false`,先注册再 `await start()`。
|
|
46
|
+
|
|
47
|
+
`enabled: false` 和初始 `trackingConsent: 'not-granted'` 都不阻止构造阶段创建 Provider/Resource。默认 Device 开启时,稳定 Device Resource 快照也会在构造时读取;它们只阻止后续插件采集和 Span 发送。对“授权前不能读取浏览器设备信息”有严格要求时,应延后整个构造调用。
|
|
32
48
|
|
|
33
49
|
## application
|
|
34
50
|
|
|
35
|
-
|
|
|
51
|
+
| 配置 | 类型 | 默认 | 上报位置 |
|
|
36
52
|
| --- | --- | --- | --- |
|
|
37
|
-
| `name` | `string` |
|
|
38
|
-
| `environment` | `string` | `production` | `deployment.environment.name` |
|
|
39
|
-
| `version` | `string` |
|
|
53
|
+
| `name` | `string` | 必填、非空 | Resource `service.name`,也参与 Session 稳定采样 |
|
|
54
|
+
| `environment` | `string` | `'production'` | Resource `deployment.environment.name` |
|
|
55
|
+
| `version` | `string` | 不发送 | Resource `service.version` |
|
|
40
56
|
|
|
41
|
-
|
|
57
|
+
`name` 应稳定且低基数,不要包含用户、构建时间或路由。`version` 推荐使用可以定位前端构建产物的版本号或 commit 标识。
|
|
42
58
|
|
|
43
59
|
## transport
|
|
44
60
|
|
|
61
|
+
| 配置 | 类型 | 默认 | 说明 |
|
|
62
|
+
| --- | --- | ---: | --- |
|
|
63
|
+
| `endpoint` | `string` | 必填、非空 | 上报根地址;去除末尾 `/` 后追加 `/v1/rum` |
|
|
64
|
+
| `token` | `string` | 无 | 生成默认 `Authorization: Bearer <token>` |
|
|
65
|
+
| `headers` | `Record<string, string>` | 无 | 自定义头;同名时覆盖 token 生成的头 |
|
|
66
|
+
| `processor` | `'batch' \| 'simple'` | `'batch'` | 批量或逐 Span 导出 |
|
|
67
|
+
| `batch` | `BkOTBatchConfig` | OTel 默认值 | 仅 batch 模式生效 |
|
|
68
|
+
| `timeoutMillis` | `number` | `10000` | exporter 请求及重试的总期限,必须大于 0 |
|
|
69
|
+
| `concurrencyLimit` | `number` | `30` | exporter 并发 Promise 上限 |
|
|
70
|
+
|
|
71
|
+
`batch` 子项:
|
|
72
|
+
|
|
73
|
+
| 配置 | 默认 | 说明 |
|
|
74
|
+
| --- | ---: | --- |
|
|
75
|
+
| `maxQueueSize` | `2048` | 队列满后丢弃新的已结束 Span |
|
|
76
|
+
| `maxExportBatchSize` | `512` | 单批 Span 上限,不能有效超过 queue size |
|
|
77
|
+
| `scheduledDelayMillis` | `5000` | 批量调度等待 |
|
|
78
|
+
| `exportTimeoutMillis` | `30000` | processor 等待 export 的上限 |
|
|
79
|
+
|
|
80
|
+
完整协议与重试语义见[上报协议、批处理与采样](./transport-sampling.md)。
|
|
81
|
+
|
|
82
|
+
## session
|
|
83
|
+
|
|
84
|
+
| 配置 | 类型 | 默认 | 说明 |
|
|
85
|
+
| --- | --- | --- | --- |
|
|
86
|
+
| `sampleRate` | `number` | `1` | 0–1 的 Session 级确定性采样率;越界会截断 |
|
|
87
|
+
| `storageKey` | `string` | 按应用和 endpoint host 生成 | 跨 Tab 共享 Session 状态的 localStorage key |
|
|
88
|
+
|
|
89
|
+
15 分钟无活动和 4 小时最大生命周期是当前固定行为,不是公开配置项。localStorage 不可用时退化为页面进程内存,无法跨页面/Tab 共享。详见[Session、用户与设备上下文](./session-context.md)。
|
|
90
|
+
|
|
91
|
+
## context
|
|
92
|
+
|
|
45
93
|
```ts
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
maxQueueSize: 2048,
|
|
53
|
-
maxExportBatchSize: 512,
|
|
54
|
-
scheduledDelayMillis: 5000,
|
|
55
|
-
exportTimeoutMillis: 30000,
|
|
94
|
+
context: {
|
|
95
|
+
user: { id: 'user-001' },
|
|
96
|
+
attributes: {
|
|
97
|
+
page: () => ({ 'biz.module': 'order' }),
|
|
98
|
+
error: () => ({ 'biz.release_channel': 'gray' }),
|
|
99
|
+
custom: () => ({ 'biz.tenant': 'tenant-a' }),
|
|
56
100
|
},
|
|
57
|
-
timeoutMillis: 10_000,
|
|
58
|
-
concurrencyLimit: 10,
|
|
59
101
|
}
|
|
60
102
|
```
|
|
61
103
|
|
|
62
|
-
|
|
104
|
+
| 配置 | 调用时机 | 合并到 |
|
|
105
|
+
| --- | --- | --- |
|
|
106
|
+
| `user.id` | 构造时,之后可用 `setUser()` 更新 | 运行时 `user.id` |
|
|
107
|
+
| `attributes.page()` | 插件创建相关 Span、过滤层补属性时 | 页面/请求/事件 Span,具体取决于调用插件 |
|
|
108
|
+
| `attributes.error()` | 创建错误 Span 时 | Error Span |
|
|
109
|
+
| `attributes.custom()` | `reportCustomEvent()` 时 | Custom Span |
|
|
63
110
|
|
|
64
|
-
|
|
65
|
-
| --- | --- | --- | --- |
|
|
66
|
-
| `endpoint` | `string` | 无 | 根地址,去掉末尾 `/` 后拼 `/v1/rum` |
|
|
67
|
-
| `token` | `string` | 无 | 生成 `Authorization: Bearer <token>` |
|
|
68
|
-
| `headers` | `Record<string,string>` | 无 | RUM 请求 Header |
|
|
69
|
-
| `timeoutMillis` | `number` | OTel 默认 | Exporter 超时 |
|
|
70
|
-
| `concurrencyLimit` | `number` | OTel 默认 | Exporter 并发数 |
|
|
71
|
-
| `processor` | `'batch' \| 'simple'` | `batch` | Span Processor 模式 |
|
|
72
|
-
| `batch` | `BkOTBatchConfig` | OTel 默认 | BatchSpanProcessor 参数 |
|
|
111
|
+
Hook 每次调用都应返回新的普通对象,且不能抛异常。SDK 不 hash、不改写 `user.id`。如果 ID 敏感,接入方必须在传入前完成不可逆处理。
|
|
73
112
|
|
|
74
|
-
`
|
|
113
|
+
未配置 `attributes.page` 时默认返回空对象。页面地址由 `view.url` 表达,低基数路由由 `view.url_path_group` 表达;该 Hook 只用于补充业务自定义的页面维度。
|
|
75
114
|
|
|
76
|
-
|
|
115
|
+
属性合并优先级不是全局统一的:各插件会先组合公共字段、Hook 字段和事件字段,`startSpan()` 再用运行时上下文作为底层。精确字段请以对应能力页和[RUM 数据模型](./data-model.md)为准。
|
|
77
116
|
|
|
78
|
-
|
|
117
|
+
## privacy
|
|
79
118
|
|
|
80
|
-
|
|
119
|
+
| 配置 | 类型 | 默认 | 说明 |
|
|
120
|
+
| --- | --- | --- | --- |
|
|
121
|
+
| `trackingConsent` | `'granted' \| 'not-granted'` | `'granted'` | 初始化时是否安装采集插件 |
|
|
122
|
+
| `redactUrl` | `(url: string) => string` | 去除认证信息、query、fragment | 所有按规范写入的 URL 在入 Span 前清洗 |
|
|
123
|
+
| `redactAttributes` | `(attributes) => attributes` | 原样返回 | 插件 emit 和 Resource 构造时的统一属性过滤 |
|
|
81
124
|
|
|
82
|
-
|
|
125
|
+
`redactAttributes` 必须返回合法 OpenTelemetry `Attributes`。删除字段时返回新对象最安全。Consent 与各 Hook 的覆盖边界见[隐私、Consent 与字段治理](./privacy.md)。
|
|
126
|
+
|
|
127
|
+
## tracking 默认开关
|
|
128
|
+
|
|
129
|
+
| 配置 | 默认 | 类型/参数 | 作用 |
|
|
83
130
|
| --- | --- | --- | --- |
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
131
|
+
| `request` | 开 | `boolean \| BkOTRequestConfig` | Fetch/XHR、可选 traceparent |
|
|
132
|
+
| `resource` | 开 | `boolean` | 静态资源 PerformanceResourceTiming |
|
|
133
|
+
| `error` | 开 | `boolean` | runtime、Promise、资源加载错误 |
|
|
134
|
+
| `webVitals` | 开 | `boolean` | CLS/FCP/INP/LCP/TTFB |
|
|
135
|
+
| `action` | 开 | `boolean \| BkOTActionPluginOptions` | 点击 Action 与挫败信号 |
|
|
136
|
+
| `blankScreen` | 开 | `boolean \| BkOTBlankScreenPluginOptions` | 白屏检测 |
|
|
137
|
+
| `device` | 开 | `boolean \| BkOTDevicePluginOptions` | Resource 与运行时设备属性 |
|
|
138
|
+
| `longTask` | 关 | `boolean \| BkOTLongTaskPluginOptions` | LoAF/Long Task |
|
|
139
|
+
| `websocket` | 关 | `boolean` | WebSocket 连接生命周期 |
|
|
140
|
+
| `cspViolation` | 关 | `boolean` | CSP violation |
|
|
141
|
+
| `view` | 自动、loading 开 | `BkOTViewConfig` | View 边界、命名和 loading time |
|
|
142
|
+
| `beforeSend` | 无 | `(event) => boolean \| void` | 所有结束 Span 的最终业务过滤 |
|
|
143
|
+
|
|
144
|
+
Session、Activity 和 Page View 上下文是关联模型的基础,不提供统一的 `tracking.session: false` 或 `tracking.activity: false` 开关。
|
|
145
|
+
|
|
146
|
+
## request
|
|
86
147
|
|
|
87
|
-
|
|
148
|
+
```ts
|
|
149
|
+
tracking: {
|
|
150
|
+
request: {
|
|
151
|
+
excludedUrls: [/\/health(?:\?|$)/],
|
|
152
|
+
allowedTracingUrls: [url => new URL(url, location.href).origin === 'https://api.example.com'],
|
|
153
|
+
beforeSend(event, context) {
|
|
154
|
+
if (event.resource.outcome.type === 'response' && event.resource.outcome.statusCode === 404) return false;
|
|
155
|
+
event.attributes['biz.api_group'] = 'order';
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
| 配置 | 默认 | 说明 |
|
|
162
|
+
| --- | --- | --- |
|
|
163
|
+
| `excludedUrls` | 无 | 匹配后不建请求 Span、不注入 trace header,也不计入 View/Action 活动 |
|
|
164
|
+
| `allowedTracingUrls` | 无 | 只有明确匹配的 URL 才注入 W3C `traceparent`,同源也不例外 |
|
|
165
|
+
| `beforeSend` | 无 | 只作用于 Fetch/XHR 请求事件;`event.resource.outcome` 区分 response/abort/timeout/network_error,返回 `false` 丢弃请求 Span |
|
|
166
|
+
|
|
167
|
+
URL matcher 支持 string、RegExp 或函数:
|
|
168
|
+
|
|
169
|
+
- string:URL 包含该字符串即匹配;
|
|
170
|
+
- RegExp:对完整 URL 执行 `test`,SDK 会重置 `lastIndex`;
|
|
171
|
+
- function:返回 true 即匹配;
|
|
172
|
+
- 单个 matcher 或数组均可。
|
|
88
173
|
|
|
89
|
-
|
|
174
|
+
请求插件不采集请求体、响应体和常规业务 header。详见[网络请求、资源与链路传播](./network.md)。
|
|
90
175
|
|
|
91
|
-
|
|
176
|
+
## view
|
|
177
|
+
|
|
178
|
+
| 配置 | 类型 | 默认 | 说明 |
|
|
92
179
|
| --- | --- | --- | --- |
|
|
93
|
-
| `tracking` | `'auto' \| 'manual'` | `auto` |
|
|
94
|
-
| `loadingTime` | `boolean` | `true` |
|
|
95
|
-
| `getPathGroup` | `(url) => string \| undefined` | URL pathname |
|
|
96
|
-
| `excludedActivityUrls` |
|
|
180
|
+
| `tracking` | `'auto' \| 'manual'` | `'auto'` | 自动监听 History/hash,或只接受 `startView()` |
|
|
181
|
+
| `loadingTime` | `boolean` | `true` | 自动计算初始加载和路由稳定耗时 |
|
|
182
|
+
| `getPathGroup` | `(url) => string \| undefined` | URL pathname | 生成低基数 `view.url_path_group` |
|
|
183
|
+
| `excludedActivityUrls` | URL matcher | 无 | 不让长轮询/流式/埋点请求延长 View loading time |
|
|
184
|
+
|
|
185
|
+
`getPathGroup` 返回 `undefined` 时回退到 pathname。自动路由不会因 query-only 变化创建新 View;hash 变化会创建,但纯锚点语义由业务自行决定是否改用 manual。详见[View、路由与页面加载](./views-routing.md)。
|
|
97
186
|
|
|
98
|
-
|
|
187
|
+
## action
|
|
188
|
+
|
|
189
|
+
| 配置 | 类型 | 默认 | 说明 |
|
|
190
|
+
| --- | --- | --- | --- |
|
|
191
|
+
| `actionNameAttribute` | `string` | `'data-bk-action-name'` | 从目标或祖先读取显式名称 |
|
|
192
|
+
| `maxDuration` | `number` | `10000` | Action 最长持续时间,非法或非正数回退默认 |
|
|
193
|
+
| `nameCollection` | `'explicit' \| 'text'` | `'explicit'` | 是否允许从可访问名称/DOM 文本推导名称 |
|
|
99
194
|
|
|
100
|
-
|
|
195
|
+
`text` 可能采集用户界面文本,开启前必须做隐私评审。详见[用户操作与挫败信号](./actions.md)。
|
|
101
196
|
|
|
102
|
-
|
|
197
|
+
## blankScreen
|
|
103
198
|
|
|
104
|
-
|
|
|
199
|
+
| 配置 | 类型 | 默认 | 说明 |
|
|
105
200
|
| --- | --- | --- | --- |
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
| `
|
|
201
|
+
| `rootSelector` | `string` | `'body'` | 应用根节点;不存在会成为白屏候选 |
|
|
202
|
+
| `threshold` | `number` | `0.8` | 九点采样中的空白比例阈值,截断至 0–1 |
|
|
203
|
+
| `checkDelay` | `number` | `1000` | 页面活动稳定后的首检延迟 |
|
|
204
|
+
| `confirmationDelay` | `number` | `200` | 两次白屏结果的确认间隔 |
|
|
205
|
+
| `ignoreSelectors` | `string[]` | 内置 loading/skeleton 列表 | 追加忽略元素,不替换内置列表 |
|
|
109
206
|
|
|
110
|
-
|
|
207
|
+
SPA 应将 `rootSelector` 指向真实挂载节点。详见[白屏检测](./blank-screen.md)。
|
|
111
208
|
|
|
112
|
-
##
|
|
209
|
+
## device
|
|
113
210
|
|
|
114
|
-
|
|
|
211
|
+
| 配置 | 类型 | 默认 | 说明 |
|
|
115
212
|
| --- | --- | --- | --- |
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `webVitals` | `boolean` | `true` | 无 |
|
|
119
|
-
| `blankScreen` | `boolean \| BkOTBlankScreenPluginOptions` | `true` | 见下表 |
|
|
120
|
-
| `device` | `boolean \| BkOTDevicePluginOptions` | `true` | 见下表 |
|
|
121
|
-
| `action` | `boolean \| BkOTActionPluginOptions` | `true` | 见下表 |
|
|
122
|
-
| `longTask` | `boolean \| BkOTLongTaskPluginOptions` | `false` | `threshold=50` ms |
|
|
123
|
-
| `websocket` | `boolean` | `false` | 无 |
|
|
124
|
-
| `cspViolation` | `boolean` | `false` | 无;每条 CSP 违规都生成 Span |
|
|
125
|
-
|
|
126
|
-
Blank Screen:
|
|
127
|
-
|
|
128
|
-
| 字段 | 默认 | 说明 |
|
|
129
|
-
| --- | --- | --- |
|
|
130
|
-
| `rootSelector` | `body` | 应用挂载根节点 |
|
|
131
|
-
| `threshold` | `0.8` | 九点采样的空白比例,限制到 `0..1` |
|
|
132
|
-
| `checkDelay` | `1000` ms | 页面活动稳定后的首次检查延迟 |
|
|
133
|
-
| `confirmationDelay` | `200` ms | 两次候选白屏的确认间隔 |
|
|
134
|
-
| `ignoreSelectors` | 内置 loading/skeleton 选择器 | 自定义数组会追加到内置数组 |
|
|
213
|
+
| `persistentId` | `boolean` | `false` | 是否把匿名设备 ID 持久化到 localStorage |
|
|
214
|
+
| `storageKey` | `string` | `BK_RUM_DEVICE_ID_<应用 hash>` | 持久设备 ID 的 key |
|
|
135
215
|
|
|
136
|
-
|
|
216
|
+
`persistentId: false` 时,每次 Device 插件初始化都会创建新的设备 ID,只在当前采集周期内稳定;撤销再授予 Consent 会重新初始化插件并换 ID。`tracking.device: false` 还会阻止浏览器/OS/硬件 Resource 属性生成。详见[Session、用户与设备上下文](./session-context.md)。
|
|
137
217
|
|
|
138
|
-
|
|
139
|
-
| --- | --- | --- |
|
|
140
|
-
| `actionNameAttribute` | `data-bk-action-name` | 向上查找的显式动作名属性 |
|
|
141
|
-
| `maxDuration` | `10_000` ms | 单次 Action 最大活动窗口 |
|
|
142
|
-
| `nameCollection` | `explicit` | 默认只取显式属性,否则退回标签名;`text` 才读取可访问名称/DOM 文本 |
|
|
218
|
+
## longTask
|
|
143
219
|
|
|
144
|
-
|
|
220
|
+
| 配置 | 类型 | 默认 | 说明 |
|
|
221
|
+
| --- | --- | --- | --- |
|
|
222
|
+
| `threshold` | `number` | `50` | 最低 duration,非法或负数回退默认 |
|
|
145
223
|
|
|
146
|
-
|
|
147
|
-
| --- | --- | --- |
|
|
148
|
-
| `persistentId` | `false` | `false` 时 ID 只在当前实例稳定;`true` 写 localStorage |
|
|
149
|
-
| `storageKey` | 按应用名 hash | 仅持久 ID 使用 |
|
|
224
|
+
优先使用 Long Animation Frame API,不支持时回退 Long Tasks API;两者的可用字段不同。详见[性能体验与长任务](./performance.md)。
|
|
150
225
|
|
|
151
226
|
## tracking.beforeSend
|
|
152
227
|
|
|
153
228
|
```ts
|
|
154
229
|
tracking: {
|
|
155
230
|
beforeSend(event) {
|
|
156
|
-
|
|
157
|
-
|
|
231
|
+
if (event.name === 'browser.resource' && event.attributes['url.full']?.includes('/noise')) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
event.attributes['biz.reviewed'] = true;
|
|
158
235
|
},
|
|
159
236
|
}
|
|
160
237
|
```
|
|
161
238
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
## context
|
|
239
|
+
事件结构:
|
|
165
240
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
自定义 `page` Hook 会替换默认 host/path Hook,不是合并默认实现。
|
|
174
|
-
|
|
175
|
-
## privacy
|
|
241
|
+
```ts
|
|
242
|
+
interface BkOTBeforeSendEvent {
|
|
243
|
+
signal: 'span';
|
|
244
|
+
name: string;
|
|
245
|
+
attributes: Record<string, unknown>;
|
|
246
|
+
}
|
|
247
|
+
```
|
|
176
248
|
|
|
177
|
-
|
|
178
|
-
| --- | --- | --- | --- |
|
|
179
|
-
| `trackingConsent` | `'granted' \| 'not-granted'` | `granted` | 初始化授权状态 |
|
|
180
|
-
| `redactUrl` | `(url) => string` | 删除 username/password/query/hash | SDK URL 属性脱敏 |
|
|
181
|
-
| `redactAttributes` | `(attributes) => Attributes` | 原样返回 | Resource、SDK 创建的 Span 和内置插件属性脱敏 |
|
|
249
|
+
该 Hook 在 Span 结束、导出过滤阶段执行:
|
|
182
250
|
|
|
183
|
-
|
|
251
|
+
- 返回 `false` 丢弃;返回 `void` 保留;
|
|
252
|
+
- 可原地修改 `event.attributes`;
|
|
253
|
+
- 只暴露名字和属性,不暴露 Span event、时间、status、trace ID;
|
|
254
|
+
- 在 Span 已完成常规脱敏之后执行;该 Hook 新增或改写的字段不会再自动经过 `redactAttributes`;
|
|
255
|
+
- Hook 抛异常时 SDK 保留 Span 并继续发送,`debug: true` 时打印 warning;业务仍应在 Hook 内避免可能失败或高开销的逻辑。
|
|
184
256
|
|
|
185
257
|
## extensions
|
|
186
258
|
|
|
187
|
-
|
|
|
259
|
+
| 配置 | 类型 | 默认 | 说明 |
|
|
188
260
|
| --- | --- | --- | --- |
|
|
189
|
-
| `plugins` | `BkOTPlugin[]` | `[]` |
|
|
190
|
-
| `instrumentations` | `Instrumentation[]` | `[]` |
|
|
261
|
+
| `plugins` | `BkOTPlugin[]` | `[]` | 使用 SDK RUM runtime context 的插件 |
|
|
262
|
+
| `instrumentations` | `Instrumentation[]` | `[]` | 绑定 SDK 私有 WebTracerProvider 的 OTel instrumentation |
|
|
191
263
|
|
|
192
|
-
|
|
264
|
+
两类扩展都在 SDK 获得 Consent 后启动,并在撤销 Consent/shutdown 时关闭。使用方法见[插件与 OpenTelemetry 扩展](./extensions.md)。
|
|
193
265
|
|
|
194
|
-
##
|
|
266
|
+
## 可复制的生产模板
|
|
195
267
|
|
|
196
268
|
```ts
|
|
197
|
-
new BkOpenTelemetry({
|
|
198
|
-
application: {
|
|
269
|
+
const rum = new BkOpenTelemetry({
|
|
270
|
+
application: {
|
|
271
|
+
name: 'order-center',
|
|
272
|
+
environment: 'production',
|
|
273
|
+
version: '2026.07.21',
|
|
274
|
+
},
|
|
199
275
|
transport: {
|
|
200
|
-
endpoint: 'https://
|
|
201
|
-
token: 'token',
|
|
202
|
-
headers: {},
|
|
276
|
+
endpoint: 'https://rum.example.com',
|
|
277
|
+
token: 'limited-browser-write-token',
|
|
203
278
|
processor: 'batch',
|
|
204
|
-
batch: {},
|
|
205
279
|
},
|
|
206
|
-
session: { sampleRate:
|
|
280
|
+
session: { sampleRate: 0.2 },
|
|
207
281
|
tracking: {
|
|
208
|
-
view: {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
282
|
+
view: {
|
|
283
|
+
getPathGroup(url) {
|
|
284
|
+
return new URL(url, location.href).pathname.replace(/\/orders\/[^/]+/, '/orders/:id');
|
|
285
|
+
},
|
|
286
|
+
excludedActivityUrls: [/\/events\/stream(?:\?|$)/],
|
|
287
|
+
},
|
|
288
|
+
request: {
|
|
289
|
+
excludedUrls: [/\/health(?:\?|$)/],
|
|
290
|
+
allowedTracingUrls: [url => new URL(url, location.href).origin === 'https://api.example.com'],
|
|
291
|
+
},
|
|
292
|
+
blankScreen: { rootSelector: '#app' },
|
|
293
|
+
},
|
|
294
|
+
privacy: {
|
|
295
|
+
redactAttributes(attributes) {
|
|
296
|
+
const next = { ...attributes };
|
|
297
|
+
delete next['biz.secret'];
|
|
298
|
+
return next;
|
|
299
|
+
},
|
|
219
300
|
},
|
|
220
|
-
context: { attributes: {} },
|
|
221
|
-
privacy: { trackingConsent: 'granted' },
|
|
222
|
-
extensions: { plugins: [], instrumentations: [] },
|
|
223
|
-
enabled: true,
|
|
224
|
-
autoStart: true,
|
|
225
|
-
debug: false,
|
|
226
301
|
});
|
|
227
302
|
```
|