@blueking/open-telemetry 0.0.14 → 0.0.16
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 +96 -641
- 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 +39 -33
- package/skills/bk-rum-otele/evals/evals.json +3 -3
- package/skills/bk-rum-otele/references/api.md +247 -114
- package/skills/bk-rum-otele/references/architecture.md +141 -0
- package/skills/bk-rum-otele/references/capabilities.md +100 -0
- package/skills/bk-rum-otele/references/concepts.md +40 -111
- package/skills/bk-rum-otele/references/configuration.md +202 -254
- package/skills/bk-rum-otele/references/custom-plugin.md +22 -7
- package/skills/bk-rum-otele/references/data-model.md +17 -10
- package/skills/bk-rum-otele/references/framework-integration.md +25 -17
- package/skills/bk-rum-otele/references/getting-started.md +42 -86
- package/skills/bk-rum-otele/references/plugins.md +232 -138
- package/skills/bk-rum-otele/references/privacy.md +47 -34
- package/skills/bk-rum-otele/references/telemetry-reference.md +74 -45
- package/skills/bk-rum-otele/references/transport-sampling.md +79 -0
- package/skills/bk-rum-otele/references/troubleshooting.md +71 -37
- package/dist/plugins/http-body.d.ts +0 -3
- package/dist/plugins/route-timing.d.ts +0 -2
|
@@ -1,320 +1,268 @@
|
|
|
1
1
|
<!-- 本文件由 packages/open-telemetry/scripts/gen-skill-references.mjs 从 wikis 自动生成,请勿手改。 -->
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# 配置参考
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## 完整配置示例
|
|
5
|
+
`BkOpenTelemetry` 只接受当前 `BkOTOptions` 结构。`application.name` 与 `transport` 必填;所有已启用信号必须能解析到有效 Endpoint。
|
|
8
6
|
|
|
9
7
|
```ts
|
|
10
|
-
import { BkOpenTelemetry } from '@blueking/open-telemetry';
|
|
8
|
+
import { BkOpenTelemetry, type BkOTOptions } from '@blueking/open-telemetry';
|
|
11
9
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
app: {
|
|
17
|
-
name: 'bk-monitor-web',
|
|
18
|
-
environment: 'production',
|
|
19
|
-
version: '1.4.2',
|
|
20
|
-
},
|
|
21
|
-
user: {
|
|
22
|
-
id: 'user-12345',
|
|
23
|
-
},
|
|
24
|
-
transport: {
|
|
25
|
-
endpoint: 'https://rum-collector.example.com',
|
|
26
|
-
token: 'report-token',
|
|
27
|
-
headers: {
|
|
28
|
-
'x-bk-tenant-id': 'system',
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
sampling: {
|
|
32
|
-
rate: 0.2,
|
|
33
|
-
},
|
|
34
|
-
route: {
|
|
35
|
-
getPathGroup: url => new URL(url).pathname.replace(/\/\d+/g, '/:id'),
|
|
36
|
-
},
|
|
37
|
-
privacy: {
|
|
38
|
-
redactUrl: url => url.replace(/([?&](token|bk_ticket)=)[^&]+/g, '$1***'),
|
|
39
|
-
redactAttributes: attributes => attributes,
|
|
40
|
-
},
|
|
41
|
-
attributes: {
|
|
42
|
-
page: () => ({
|
|
43
|
-
'biz.space_id': window.__BK_SPACE_ID__,
|
|
44
|
-
}),
|
|
45
|
-
custom: () => ({
|
|
46
|
-
'biz.app_code': 'bk-monitor',
|
|
47
|
-
}),
|
|
48
|
-
},
|
|
49
|
-
instrumentations: {
|
|
50
|
-
documentLoad: true,
|
|
51
|
-
fetch: true,
|
|
52
|
-
xhr: true,
|
|
53
|
-
userInteraction: true,
|
|
54
|
-
},
|
|
55
|
-
plugins: {
|
|
56
|
-
pageView: true,
|
|
57
|
-
resource: true,
|
|
58
|
-
error: true,
|
|
59
|
-
webVitals: true,
|
|
60
|
-
blankScreen: {
|
|
61
|
-
rootSelector: '#app',
|
|
62
|
-
checkDelay: 3000,
|
|
63
|
-
threshold: 0.8,
|
|
64
|
-
},
|
|
65
|
-
session: true,
|
|
66
|
-
device: true,
|
|
67
|
-
action: false,
|
|
68
|
-
httpBody: false,
|
|
69
|
-
longTask: false,
|
|
70
|
-
routeTiming: false,
|
|
71
|
-
cspViolation: false,
|
|
72
|
-
websocket: false,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
10
|
+
const options: BkOTOptions = {
|
|
11
|
+
application: { name: 'bk-monitor-web' },
|
|
12
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
13
|
+
};
|
|
75
14
|
|
|
76
|
-
|
|
15
|
+
const bkOT = new BkOpenTelemetry(options);
|
|
77
16
|
```
|
|
78
17
|
|
|
79
18
|
## 顶层配置
|
|
80
19
|
|
|
81
|
-
|
|
|
82
|
-
| --- | --- | --- |
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
20
|
+
| 字段 | 类型 | 默认 | 说明 |
|
|
21
|
+
| --- | --- | --- | --- |
|
|
22
|
+
| `application` | `BkOTApplicationConfig` | 必填 | 应用 Resource 标识 |
|
|
23
|
+
| `transport` | `BkOTTransportConfig` | 必填 | 三类 OTLP HTTP 导出链路 |
|
|
24
|
+
| `session` | `BkOTSessionConfig` | `{ sampleRate: 1 }` | Session 存储和确定性采样 |
|
|
25
|
+
| `tracking` | `BkOTTrackingConfig` | `{}` | 内置采集、View 与事件 Hook |
|
|
26
|
+
| `context` | `BkOTContextConfig` | 无 | 初始用户与公共属性 Hook |
|
|
27
|
+
| `privacy` | `BkOTPrivacyConfig` | Consent 已授权、默认 URL 脱敏 | 授权、URL 和属性脱敏 |
|
|
28
|
+
| `extensions` | `BkOTExtensionsConfig` | 空数组 | 自定义 RUM 插件与 OTel instrumentation |
|
|
29
|
+
| `enabled` | `boolean` | `true` | `false` 时 `start()` 不安装采集能力 |
|
|
30
|
+
| `autoStart` | `boolean` | `true` | 构造后异步启动 |
|
|
31
|
+
| `debug` | `boolean` | `false` | 输出 exporter 数据和可诊断 warning |
|
|
90
32
|
|
|
91
|
-
|
|
33
|
+
## application
|
|
92
34
|
|
|
93
|
-
|
|
94
|
-
|
|
35
|
+
| 字段 | 类型 | 默认 | Resource Attribute |
|
|
36
|
+
| --- | --- | --- | --- |
|
|
37
|
+
| `name` | `string` | 必填且非空 | `service.name` |
|
|
38
|
+
| `environment` | `string` | `production` | `deployment.environment.name` |
|
|
39
|
+
| `version` | `string` | 无 | `service.version` |
|
|
95
40
|
|
|
96
|
-
|
|
41
|
+
SDK 还会固定写入 `rum.provider=blueking`、`rum.schema.version=1`、`telemetry.sdk.name=@blueking/open-telemetry` 和 `telemetry.sdk.language=webjs`。
|
|
42
|
+
|
|
43
|
+
## transport
|
|
97
44
|
|
|
98
45
|
```ts
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
46
|
+
transport: {
|
|
47
|
+
endpoint: 'https://collector.example.com',
|
|
48
|
+
token: 'report-token',
|
|
49
|
+
headers: { 'X-Tenant': 'blueking' },
|
|
50
|
+
signals: {
|
|
51
|
+
traces: {
|
|
52
|
+
endpoint: 'https://trace.example.com/v1/rum',
|
|
53
|
+
processor: 'batch',
|
|
54
|
+
batch: {
|
|
55
|
+
maxQueueSize: 2048,
|
|
56
|
+
maxExportBatchSize: 512,
|
|
57
|
+
scheduledDelayMillis: 5000,
|
|
58
|
+
exportTimeoutMillis: 30000,
|
|
59
|
+
},
|
|
60
|
+
timeoutMillis: 10_000,
|
|
61
|
+
concurrencyLimit: 10,
|
|
62
|
+
},
|
|
63
|
+
metrics: {
|
|
64
|
+
intervalMillis: 60_000,
|
|
65
|
+
},
|
|
66
|
+
logs: {},
|
|
107
67
|
},
|
|
108
|
-
}
|
|
68
|
+
}
|
|
109
69
|
```
|
|
110
70
|
|
|
111
|
-
|
|
71
|
+
### 根字段
|
|
112
72
|
|
|
113
|
-
|
|
|
114
|
-
| --- | --- | --- |
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `propagateTraceHeaderUrls` | `undefined`(仅同源) | 把跨域后台 API 纳入 `traceparent`(含 OpenTelemetry traceId)注入范围。 |
|
|
73
|
+
| 字段 | 类型 | 默认 | 说明 |
|
|
74
|
+
| --- | --- | --- | --- |
|
|
75
|
+
| `endpoint` | `string` | 无 | 根地址,去掉末尾 `/` 后拼默认信号路径 |
|
|
76
|
+
| `token` | `string` | 无 | 生成 `Authorization: Bearer <token>` |
|
|
77
|
+
| `headers` | `Record<string,string>` | 无 | 所有信号的公共 Header |
|
|
78
|
+
| `signals` | `SignalExportersInputConfig` | 三类开启 | 单信号开关和覆盖项 |
|
|
120
79
|
|
|
121
|
-
|
|
80
|
+
默认路径:Trace `/v1/rum`、Metric `/v1/metrics`、Log `/v1/logs`。单信号 `endpoint` 是完整 URL,不再拼路径。
|
|
122
81
|
|
|
123
|
-
|
|
124
|
-
- `string`:URL 包含该子串即注入,例如 `'api.example.com'`。
|
|
125
|
-
- `RegExp`:URL 匹配该正则即注入。
|
|
126
|
-
- 上述字符串/正则组成的数组:命中任意一个即注入。
|
|
127
|
-
- `(url: string) => boolean`:完全自定义判断。
|
|
82
|
+
Header 覆盖顺序为 `token` < 根 `headers` < 单信号 `headers`。同名字段由右侧配置覆盖。
|
|
128
83
|
|
|
129
|
-
|
|
130
|
-
new BkOpenTelemetry({
|
|
131
|
-
instrumentations: {
|
|
132
|
-
// 给所有调用 api.example.com / api.internal.com 的后台请求注入 traceparent
|
|
133
|
-
propagateTraceHeaderUrls: [/https:\/\/api\.example\.com/, 'api.internal.com'],
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
```
|
|
84
|
+
### 单信号字段
|
|
137
85
|
|
|
138
|
-
|
|
86
|
+
| 字段 | Trace | Metric | Log | SDK 默认 |
|
|
87
|
+
| --- | --- | --- | --- | --- |
|
|
88
|
+
| `endpoint` | 支持 | 支持 | 支持 | 回退根 Endpoint |
|
|
89
|
+
| `headers` | 支持 | 支持 | 支持 | 回退根 Header |
|
|
90
|
+
| `timeoutMillis` | 支持 | 支持 | 支持 | 交给 OTel exporter |
|
|
91
|
+
| `concurrencyLimit` | 支持 | 支持 | 支持 | 交给 OTel exporter |
|
|
92
|
+
| `processor` | `'batch' \| 'simple'` | — | — | `batch` |
|
|
93
|
+
| `batch` | `BkOTBatchConfig` | — | — | 交给 `BatchSpanProcessor` |
|
|
94
|
+
| `intervalMillis` | — | number | — | `60_000` |
|
|
139
95
|
|
|
140
|
-
|
|
96
|
+
`batch` 支持 `maxQueueSize`、`maxExportBatchSize`、`scheduledDelayMillis`、`exportTimeoutMillis`。未提供时使用 OpenTelemetry `BatchSpanProcessor` 默认值。
|
|
141
97
|
|
|
142
|
-
|
|
143
|
-
new BkOpenTelemetry({
|
|
144
|
-
instrumentations: {
|
|
145
|
-
fetch: false,
|
|
146
|
-
xhr: false,
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
```
|
|
98
|
+
校验规则:
|
|
150
99
|
|
|
151
|
-
|
|
100
|
+
- 三类信号不能全部为 `false`。
|
|
101
|
+
- 每个已开启信号必须配置单独 Endpoint,或能回退到根 `transport.endpoint`。
|
|
102
|
+
- 关闭 Trace 后不创建 Trace exporter/processor,不记录可导出的 Span,也不注入 `traceparent`。
|
|
103
|
+
- 关闭 Metric 后不创建 reader;关闭 Log 后不创建 log processor,Request Body 配置也不会产生 Log。
|
|
152
104
|
|
|
153
|
-
|
|
154
|
-
| --- | --- | --- |
|
|
155
|
-
| `pageView` | 开 | 初始页面和 SPA 路由 view。 |
|
|
156
|
-
| `resource` | 开 | 静态资源 PerformanceObserver。 |
|
|
157
|
-
| `error` | 开 | JS error、unhandledrejection、资源错误。 |
|
|
158
|
-
| `webVitals` | 开 | CLS、FCP、INP、LCP、TTFB。 |
|
|
159
|
-
| `blankScreen` | 开 | 延迟检测页面空白比例。 |
|
|
160
|
-
| `device` | 开 | 设备、浏览器、OS、viewport、网络属性。 |
|
|
161
|
-
| `session` | 开 | session.id 生成、轮换和跨 tab 同步。 |
|
|
162
|
-
| `action` | 关 | 自动采集 click、submit、keydown 等动作。 |
|
|
163
|
-
| `httpBody` | 关 | 错误路径采集请求/响应 body。 |
|
|
164
|
-
| `longTask` | 关 | Long Task API。 |
|
|
165
|
-
| `routeTiming` | 关 | SPA 路由切换渲染耗时估算。 |
|
|
166
|
-
| `cspViolation` | 关 | CSP 违规 error span。 |
|
|
167
|
-
| `websocket` | 关 | WebSocket 连接、消息、错误、关闭。 |
|
|
168
|
-
|
|
169
|
-
示例:开启高成本插件。
|
|
105
|
+
更多行为见[传输与采样](./transport-sampling.md)。
|
|
170
106
|
|
|
171
|
-
|
|
172
|
-
new BkOpenTelemetry({
|
|
173
|
-
plugins: {
|
|
174
|
-
longTask: {
|
|
175
|
-
threshold: 80,
|
|
176
|
-
},
|
|
177
|
-
httpBody: {
|
|
178
|
-
maxBodySize: 4096,
|
|
179
|
-
redact: ({ body, type }) => (type === 'request' ? '[redacted request body]' : body),
|
|
180
|
-
},
|
|
181
|
-
websocket: true,
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
```
|
|
107
|
+
## session
|
|
185
108
|
|
|
186
|
-
|
|
109
|
+
| 字段 | 类型 | 默认 | 说明 |
|
|
110
|
+
| --- | --- | --- | --- |
|
|
111
|
+
| `sampleRate` | `number` | `1` | Session 确定性采样;有限数值限制到 `0..1`,非有限值回退 `1` |
|
|
112
|
+
| `storageKey` | `string` | 按应用名和 Endpoint host hash | Session localStorage key |
|
|
187
113
|
|
|
188
|
-
|
|
114
|
+
Session 固定为 15 分钟无活动过期、4 小时最长生命周期,不开放超时配置。localStorage 不可用时退回进程内存。
|
|
189
115
|
|
|
190
|
-
##
|
|
116
|
+
## tracking.view
|
|
191
117
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
});
|
|
199
|
-
```
|
|
118
|
+
| 字段 | 类型 | 默认 | 说明 |
|
|
119
|
+
| --- | --- | --- | --- |
|
|
120
|
+
| `tracking` | `'auto' \| 'manual'` | `auto` | 自动观察 History/hash,或由业务调用 `startView()` |
|
|
121
|
+
| `loadingTime` | `boolean` | `true` | 计算 View 页面活动稳定耗时 |
|
|
122
|
+
| `getPathGroup` | `(url) => string \| undefined` | URL pathname | 返回低基数 `view.url_path_group` |
|
|
123
|
+
| `excludedActivityUrls` | matcher 或 matcher[] | 无 | 命中请求/资源不延长 View/Action 活动窗口 |
|
|
200
124
|
|
|
201
|
-
|
|
125
|
+
URL matcher 支持字符串包含、`RegExp` 或 `(url) => boolean`。字符串使用 `url.includes(matcher)`,不等于 origin 精确匹配;安全白名单应使用 URL-aware 函数或带边界的正则。自动 View 只对 pathname 和非页内锚点 hash path 的变化切换,query-only 变化不切换。
|
|
202
126
|
|
|
203
|
-
|
|
204
|
-
- metrics:`https://rum-collector.example.com/v1/metrics`
|
|
205
|
-
- logs:`https://rum-collector.example.com/v1/logs`
|
|
127
|
+
## tracking.request
|
|
206
128
|
|
|
207
|
-
|
|
129
|
+
`request` 可设为 `false` 完全关闭 Fetch/XHR patch;`true` 或 `{}` 使用默认配置。
|
|
208
130
|
|
|
209
|
-
|
|
131
|
+
| 字段 | 类型 | 默认 | 说明 |
|
|
132
|
+
| --- | --- | --- | --- |
|
|
133
|
+
| `excludedUrls` | matcher 或 matcher[] | 无 | 命中后不采集、不注入、不计入页面活动 |
|
|
134
|
+
| `allowedTracingUrls` | matcher 或 matcher[] | 无 | W3C Trace Context 显式白名单;同源请求也必须命中,推荐 URL-aware 函数 |
|
|
135
|
+
| `beforeSend` | `(event, context) => boolean \| void` | 无 | 修改请求属性;返回 `false` 丢弃 Span,并跳过该请求的 Body Log |
|
|
136
|
+
| `body` | `BkOTRequestBodyConfig` | 关闭 | 请求/响应 Body Log |
|
|
210
137
|
|
|
211
|
-
|
|
212
|
-
new BkOpenTelemetry({
|
|
213
|
-
transport: {
|
|
214
|
-
endpoint: 'https://rum-collector.example.com',
|
|
215
|
-
headers: {
|
|
216
|
-
'x-bk-app-code': 'bk-monitor',
|
|
217
|
-
},
|
|
218
|
-
signals: {
|
|
219
|
-
endpoints: {
|
|
220
|
-
traces: 'https://trace-gateway.example.com/v1/rum',
|
|
221
|
-
metrics: 'https://metric-gateway.example.com/v1/metrics',
|
|
222
|
-
logs: 'https://log-gateway.example.com/v1/logs',
|
|
223
|
-
},
|
|
224
|
-
traces: {
|
|
225
|
-
timeoutMillis: 5000,
|
|
226
|
-
concurrencyLimit: 4,
|
|
227
|
-
},
|
|
228
|
-
logs: {
|
|
229
|
-
headers: {
|
|
230
|
-
'x-bk-log-source': 'browser',
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
```
|
|
138
|
+
Request Body:
|
|
237
139
|
|
|
238
|
-
|
|
140
|
+
| 字段 | 类型 | 默认 | 说明 |
|
|
141
|
+
| --- | --- | --- | --- |
|
|
142
|
+
| `capture` | `'errors' \| 'all'` | `errors` | 错误包括状态未知、0 或 `>=400` |
|
|
143
|
+
| `maxSize` | `number` | `10 * 1024` | 每个最终 Body 的最大字符数;无效值回退默认 |
|
|
144
|
+
| `allowedContentTypes` | `(string \| RegExp)[]` | text、json、urlencoded、graphql | Response 必须命中;无 Content-Type 的 Request 允许读取 |
|
|
145
|
+
| `redact` | `(payload) => string \| undefined` | 必填 | 返回脱敏文本;`undefined` 跳过当前 Body |
|
|
239
146
|
|
|
240
|
-
|
|
147
|
+
默认不采集 Body。Body 只在 Log 信号开启时生效,不支持 FormData、ArrayBuffer 等不可安全文本化的内容。
|
|
241
148
|
|
|
242
|
-
##
|
|
149
|
+
## tracking 内置能力
|
|
243
150
|
|
|
244
|
-
|
|
151
|
+
| 字段 | 类型 | 默认 | 参数 |
|
|
152
|
+
| --- | --- | --- | --- |
|
|
153
|
+
| `resource` | `boolean` | `true` | 无;`false` 只关闭静态资源 Span,Resource Observer 仍服务请求 timing/活动 |
|
|
154
|
+
| `error` | `boolean \| BkOTErrorPluginOptions` | `true` | `windowMs=60_000`、`maxPerWindow=5` |
|
|
155
|
+
| `webVitals` | `boolean` | `true` | 无 |
|
|
156
|
+
| `blankScreen` | `boolean \| BkOTBlankScreenPluginOptions` | `true` | 见下表 |
|
|
157
|
+
| `device` | `boolean \| BkOTDevicePluginOptions` | `true` | 见下表 |
|
|
158
|
+
| `action` | `boolean \| BkOTActionPluginOptions` | `true` | 见下表 |
|
|
159
|
+
| `longTask` | `boolean \| BkOTLongTaskPluginOptions` | `false` | `threshold=50`、`warningThreshold=100` ms |
|
|
160
|
+
| `websocket` | `boolean` | `false` | 无 |
|
|
161
|
+
| `cspViolation` | `boolean` | `false` | 无,内置同指纹 60 秒最多 5 条 |
|
|
245
162
|
|
|
246
|
-
|
|
163
|
+
Blank Screen:
|
|
164
|
+
|
|
165
|
+
| 字段 | 默认 | 说明 |
|
|
166
|
+
| --- | --- | --- |
|
|
167
|
+
| `rootSelector` | `body` | 应用挂载根节点 |
|
|
168
|
+
| `threshold` | `0.8` | 九点采样的空白比例,限制到 `0..1` |
|
|
169
|
+
| `checkDelay` | `1000` ms | 页面活动稳定后的首次检查延迟 |
|
|
170
|
+
| `confirmationDelay` | `200` ms | 两次候选白屏的确认间隔 |
|
|
171
|
+
| `ignoreSelectors` | 内置 loading/skeleton 选择器 | 自定义数组会替换内置数组 |
|
|
172
|
+
|
|
173
|
+
Action:
|
|
174
|
+
|
|
175
|
+
| 字段 | 默认 | 说明 |
|
|
176
|
+
| --- | --- | --- |
|
|
177
|
+
| `actionNameAttribute` | `data-bk-action-name` | 向上查找的显式动作名属性 |
|
|
178
|
+
| `maxDuration` | `10_000` ms | 单次 Action 最大活动窗口 |
|
|
179
|
+
| `nameCollection` | `explicit` | 默认只取显式属性,否则退回标签名;`text` 才读取可访问名称/DOM 文本 |
|
|
180
|
+
|
|
181
|
+
Device:
|
|
182
|
+
|
|
183
|
+
| 字段 | 默认 | 说明 |
|
|
184
|
+
| --- | --- | --- |
|
|
185
|
+
| `persistentId` | `false` | `false` 时 ID 只在当前实例稳定;`true` 写 localStorage |
|
|
186
|
+
| `storageKey` | 按应用名 hash | 仅持久 ID 使用 |
|
|
187
|
+
|
|
188
|
+
## tracking.beforeSend
|
|
247
189
|
|
|
248
190
|
```ts
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
191
|
+
tracking: {
|
|
192
|
+
beforeSend(event) {
|
|
193
|
+
delete event.attributes['debug.payload'];
|
|
194
|
+
return event.name !== 'custom.ignore-me';
|
|
252
195
|
},
|
|
253
|
-
|
|
254
|
-
fetch: true,
|
|
255
|
-
xhr: true,
|
|
256
|
-
},
|
|
257
|
-
});
|
|
196
|
+
}
|
|
258
197
|
```
|
|
259
198
|
|
|
260
|
-
|
|
199
|
+
该 Hook 在 Span/Log 进入底层 processor 前执行,可原地修改属性或返回 `false` 丢弃。异常会被吞掉,`debug: true` 时输出 warning。它不处理 Metric;请求专属逻辑优先使用 `tracking.request.beforeSend`。
|
|
261
200
|
|
|
262
|
-
|
|
201
|
+
## context
|
|
263
202
|
|
|
264
|
-
|
|
203
|
+
| 字段 | 类型 | 默认 | 作用 |
|
|
204
|
+
| --- | --- | --- | --- |
|
|
205
|
+
| `user.id` | `string` | 无 | SDK 原样写入 `user.id` |
|
|
206
|
+
| `attributes.page` | `() => Attributes` | host/path | 页面、请求、错误、Action 等事件属性 |
|
|
207
|
+
| `attributes.metric` | `() => Attributes` | `{}` | 内置 Metric 的低基数自定义维度 |
|
|
208
|
+
| `attributes.error` | `() => Attributes` | `{}` | Error Span 附加属性 |
|
|
209
|
+
| `attributes.custom` | `() => Attributes` | `{}` | `reportCustomEvent()` 附加属性 |
|
|
265
210
|
|
|
266
|
-
|
|
267
|
-
await fetch('/api/orders/202605270001', {
|
|
268
|
-
method: 'GET',
|
|
269
|
-
});
|
|
270
|
-
```
|
|
211
|
+
自定义 `page` Hook 会替换默认 host/path Hook,不是合并默认实现。Metric Hook 禁止放用户 ID、订单 ID、完整 URL 等高基数字段。
|
|
271
212
|
|
|
272
|
-
##
|
|
213
|
+
## privacy
|
|
273
214
|
|
|
274
|
-
|
|
215
|
+
| 字段 | 类型 | 默认 | 说明 |
|
|
216
|
+
| --- | --- | --- | --- |
|
|
217
|
+
| `trackingConsent` | `'granted' \| 'not-granted'` | `granted` | 初始化授权状态 |
|
|
218
|
+
| `redactUrl` | `(url) => string` | 删除 username/password/query/hash | SDK URL 属性脱敏 |
|
|
219
|
+
| `redactAttributes` | `(attributes) => Attributes` | 原样返回 | SDK 创建 Span/Log 和内置插件属性脱敏 |
|
|
275
220
|
|
|
276
|
-
|
|
277
|
-
new BkOpenTelemetry({
|
|
278
|
-
sampling: {
|
|
279
|
-
rate: 0.05,
|
|
280
|
-
},
|
|
281
|
-
transport: {
|
|
282
|
-
endpoint: 'https://rum-collector.example.com',
|
|
283
|
-
},
|
|
284
|
-
});
|
|
285
|
-
```
|
|
221
|
+
第三方 instrumentation 的自有 Span 属性不保证经过 `redactAttributes`;需要在 `tracking.beforeSend` 做最终兜底。详见[隐私与公共属性](./privacy.md)。
|
|
286
222
|
|
|
287
|
-
|
|
223
|
+
## extensions
|
|
288
224
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
225
|
+
| 字段 | 类型 | 默认 | 说明 |
|
|
226
|
+
| --- | --- | --- | --- |
|
|
227
|
+
| `plugins` | `BkOTPlugin[]` | `[]` | 在内置插件后初始化 |
|
|
228
|
+
| `instrumentations` | `Instrumentation[]` | `[]` | 插件完成后注册到 SDK provider |
|
|
293
229
|
|
|
294
|
-
|
|
230
|
+
也可以在 `start()` 前调用 `use()` / `useInstrumentation()`。需要动态注册时设置 `autoStart: false`;启动后调用会抛错。
|
|
295
231
|
|
|
296
|
-
|
|
232
|
+
## 完整配置骨架
|
|
297
233
|
|
|
298
234
|
```ts
|
|
299
235
|
new BkOpenTelemetry({
|
|
300
|
-
|
|
301
|
-
spanProcessor: 'simple',
|
|
236
|
+
application: { name: 'demo', environment: 'production', version: '1.0.0' },
|
|
302
237
|
transport: {
|
|
303
|
-
endpoint: '
|
|
238
|
+
endpoint: 'https://collector.example.com',
|
|
239
|
+
token: 'token',
|
|
240
|
+
headers: {},
|
|
241
|
+
signals: {
|
|
242
|
+
traces: { processor: 'batch', batch: {} },
|
|
243
|
+
metrics: { intervalMillis: 60_000 },
|
|
244
|
+
logs: {},
|
|
245
|
+
},
|
|
304
246
|
},
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
247
|
+
session: { sampleRate: 1 },
|
|
248
|
+
tracking: {
|
|
249
|
+
view: { tracking: 'auto', loadingTime: true },
|
|
250
|
+
request: true,
|
|
251
|
+
resource: true,
|
|
252
|
+
error: true,
|
|
253
|
+
webVitals: true,
|
|
254
|
+
blankScreen: true,
|
|
255
|
+
device: true,
|
|
256
|
+
action: true,
|
|
257
|
+
longTask: false,
|
|
258
|
+
websocket: false,
|
|
259
|
+
cspViolation: false,
|
|
318
260
|
},
|
|
261
|
+
context: { attributes: {} },
|
|
262
|
+
privacy: { trackingConsent: 'granted' },
|
|
263
|
+
extensions: { plugins: [], instrumentations: [] },
|
|
264
|
+
enabled: true,
|
|
265
|
+
autoStart: true,
|
|
266
|
+
debug: false,
|
|
319
267
|
});
|
|
320
268
|
```
|
|
@@ -38,6 +38,7 @@ import { BkOpenTelemetry } from '@blueking/open-telemetry';
|
|
|
38
38
|
import { bizPlugin } from './biz-plugin';
|
|
39
39
|
|
|
40
40
|
const bkOT = new BkOpenTelemetry({
|
|
41
|
+
application: { name: 'plugin-demo' },
|
|
41
42
|
autoStart: false,
|
|
42
43
|
transport: {
|
|
43
44
|
endpoint: 'https://rum-collector.example.com',
|
|
@@ -53,7 +54,11 @@ await bkOT.start();
|
|
|
53
54
|
|
|
54
55
|
`init(context)` 中可以访问 `tracer`、`meter`、`logger`、`startSpan()`、`emitLog()`、`getRuntimeAttributes()` 等能力。
|
|
55
56
|
|
|
57
|
+
优先使用 `context.startSpan()` 和 `context.emitLog()`:它们会合并事件发生时的运行时上下文并应用 SDK 脱敏。直接调用 `context.logger.emit()` 的 Log 不会自动获得这些能力,可能因缺少有效 Session/View 被导出过滤器丢弃。
|
|
58
|
+
|
|
56
59
|
```ts
|
|
60
|
+
let teardownVisibility = () => {};
|
|
61
|
+
|
|
57
62
|
const visibilityPlugin = createPlugin({
|
|
58
63
|
name: 'visibility-change',
|
|
59
64
|
init(context) {
|
|
@@ -68,8 +73,10 @@ const visibilityPlugin = createPlugin({
|
|
|
68
73
|
};
|
|
69
74
|
|
|
70
75
|
document.addEventListener('visibilitychange', onVisibilityChange);
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
teardownVisibility = () => document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
77
|
+
},
|
|
78
|
+
shutdown() {
|
|
79
|
+
teardownVisibility();
|
|
73
80
|
},
|
|
74
81
|
});
|
|
75
82
|
```
|
|
@@ -125,18 +132,19 @@ const createResizePlugin = () => {
|
|
|
125
132
|
|
|
126
133
|
## 注册额外 instrumentation
|
|
127
134
|
|
|
128
|
-
第三方 OpenTelemetry instrumentation
|
|
135
|
+
第三方 OpenTelemetry instrumentation 放在 `extensions.instrumentations`,或通过 `useInstrumentation()` 链式注册。两者区别详见 [内置采集与扩展](./concepts.md)。
|
|
129
136
|
|
|
130
137
|
配置式:
|
|
131
138
|
|
|
132
139
|
```ts
|
|
133
140
|
const bkOT = new BkOpenTelemetry({
|
|
134
|
-
|
|
135
|
-
custom: [new SomeWebInstrumentation()],
|
|
136
|
-
},
|
|
141
|
+
application: { name: 'extension-demo' },
|
|
137
142
|
transport: {
|
|
138
143
|
endpoint: 'https://rum-collector.example.com',
|
|
139
144
|
},
|
|
145
|
+
extensions: {
|
|
146
|
+
instrumentations: [new SomeWebInstrumentation()],
|
|
147
|
+
},
|
|
140
148
|
});
|
|
141
149
|
```
|
|
142
150
|
|
|
@@ -144,6 +152,7 @@ const bkOT = new BkOpenTelemetry({
|
|
|
144
152
|
|
|
145
153
|
```ts
|
|
146
154
|
const bkOT = new BkOpenTelemetry({
|
|
155
|
+
application: { name: 'extension-demo' },
|
|
147
156
|
autoStart: false,
|
|
148
157
|
transport: {
|
|
149
158
|
endpoint: 'https://rum-collector.example.com',
|
|
@@ -155,4 +164,10 @@ bkOT.useInstrumentation(new SomeWebInstrumentation());
|
|
|
155
164
|
await bkOT.start();
|
|
156
165
|
```
|
|
157
166
|
|
|
158
|
-
>
|
|
167
|
+
> Extension instrumentation 与采集生命周期一致:未授权或 SDK 停止时不会注册;授权后注册。它产生的 Span 受 Session sampler 和导出过滤约束;第三方 instrumentation Metric 因没有公开采样 helper,默认会被过滤。
|
|
168
|
+
|
|
169
|
+
## 自定义 Metric 注意事项
|
|
170
|
+
|
|
171
|
+
内置 Metric 会主动带上内部采样标记与低基数 `view.url_path_group`。当前包没有导出稳定的自定义 Metric helper 或采样属性;自定义插件直接调用 `context.meter` 创建的数据点默认无法通过 `FilteringMetricExporter`。不要依赖内部 `bk.rum.sampled` 字段,也不要把 `context.getRuntimeAttributes()` 整体复制到 Metric attributes,否则还会把唯一的 `session.id`、`view.id`、`action.id` 变成高基数 labels。
|
|
172
|
+
|
|
173
|
+
如果需求是记录一次具体业务行为,使用 Span 或 Log。确实需要自定义 Metric 时,应先为 SDK 设计并公开低基数、采样安全的 Metric API,而不是绕过当前过滤约束。
|
|
@@ -15,17 +15,16 @@ SDK 的数据模型遵循“浏览器 SDK 负责低成本原始数据和单事
|
|
|
15
15
|
|
|
16
16
|
| 类型 | 说明 | 常见来源 |
|
|
17
17
|
| --- | --- | --- |
|
|
18
|
-
| `document` | 文档加载 |
|
|
19
|
-
| `
|
|
20
|
-
| `resource` | 静态资源 | resource 插件、documentLoad instrumentation |
|
|
18
|
+
| `document` | 文档加载 | View 管理器(初始加载) |
|
|
19
|
+
| `resource` | Fetch/XHR 请求与静态资源 | request、resource 采集 |
|
|
21
20
|
| `vital` | Web Vitals | webVitals 插件 |
|
|
22
|
-
| `error` |
|
|
21
|
+
| `error` | 浏览器与体验错误 | error 插件、blankScreen 插件、cspViolation 插件 |
|
|
23
22
|
| `longtask` | 长任务 | longTask 插件 |
|
|
24
23
|
| `action` | 用户动作 | action 插件、reportAction |
|
|
25
|
-
| `route` | 路由切换 |
|
|
26
|
-
| `custom` | 自定义事件 | reportCustomEvent、自定义插件、websocket
|
|
24
|
+
| `route` | 路由切换 | View 管理器(SPA/手动 View) |
|
|
25
|
+
| `custom` | 自定义事件 | reportCustomEvent、自定义插件、websocket 插件;`reportCustomEvent({ error })` 仍属于此类型 |
|
|
27
26
|
|
|
28
|
-
> 每种 span 的具体 span
|
|
27
|
+
> 每种 span 的具体 span 名、metric 名、log 事件名和完整属性字典见[遥测参考](./telemetry-reference.md)。
|
|
29
28
|
|
|
30
29
|
示例:自定义业务事件归一为 `custom`。
|
|
31
30
|
|
|
@@ -55,7 +54,9 @@ span.end();
|
|
|
55
54
|
- `timeout`
|
|
56
55
|
- `abort`
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
请求 Resource Span 会根据状态码推导结果:`408`、`504` 为 timeout,`>= 400` 为 error,其余为 success。
|
|
58
|
+
|
|
59
|
+
`reportCustomEvent({ error })` 会设置 `result=error` 和 OpenTelemetry Span Status ERROR,但不会把 `span_type` 从 `custom` 改为 `error`。`span_type` 描述事件类别,`result` 描述结果,两者不要混用。
|
|
59
60
|
|
|
60
61
|
```ts
|
|
61
62
|
bkOT.reportCustomEvent({
|
|
@@ -89,8 +90,8 @@ console.log(getDurationBucket(1200)); // 500ms~2s
|
|
|
89
90
|
|
|
90
91
|
- 应用与环境:`service.name`、`deployment.environment.name`、`service.version`
|
|
91
92
|
- 用户与会话:`user.id`、`session.id`
|
|
92
|
-
- View:`view.id`、`view.url`、`view.url_path_group`、`view.loading_type`
|
|
93
|
-
- 终端信息:`
|
|
93
|
+
- View:`view.id`、`view.name`、`view.url`、`view.url_path_group`、`view.loading_type`
|
|
94
|
+
- 终端信息:`device.type`、`browser.name`、`browser.version`、`os.name`、`network.effective_type`
|
|
94
95
|
- HTTP / Resource:`http.request.method`、`http.response.status_code`、`url.full`、`transfer_size`
|
|
95
96
|
- Web Vitals:`vital.metric`、`vital.value`、`vital.rating`
|
|
96
97
|
- Error:`exception.type`、`exception.message`、`exception.stacktrace`、`exception.fingerprint`
|
|
@@ -120,3 +121,9 @@ bkOT.reportCustomEvent({
|
|
|
120
121
|
```
|
|
121
122
|
|
|
122
123
|
上例中 `biz.order_id` 适合放在 span/log 中定位单次问题,不适合作为 metric 维度做长期聚合。
|
|
124
|
+
|
|
125
|
+
## Metric 与 View 的关联
|
|
126
|
+
|
|
127
|
+
Metric 不携带唯一的 `view.id`、`session.id` 或 `action.id`,只保留 `view.url_path_group`、`view.loading_type` 等低基数维度。这样可以按页面类型聚合,又不会因为每次访问生成新的时序而造成基数爆炸。
|
|
128
|
+
|
|
129
|
+
需要定位某一次 View 时,使用同一指标对应的 span(例如 `browser.web_vital`)或 View Snapshot Log;它们携带精确的 `session.id` 和 `view.id`。后端需要从聚合指标跳转到样本时,应通过 exemplar 或 span/log 派生聚合建立关联,而不是把 `view.id` 放进 metric labels。
|