@blueking/open-telemetry 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -554
- package/dist/bk-rum.global.js +9 -9
- package/dist/bk-rum.global.js.map +1 -1
- package/dist/core/action-activity.d.ts +28 -0
- package/dist/core/config.d.ts +113 -93
- package/dist/core/page-activity.d.ts +14 -0
- package/dist/core/plugin.d.ts +23 -6
- package/dist/core/processor.d.ts +25 -4
- package/dist/core/request-timing.d.ts +5 -0
- package/dist/core/runtime-context.d.ts +51 -3
- package/dist/core/sampling.d.ts +5 -1
- package/dist/core/sdk.d.ts +29 -10
- package/dist/core/url.d.ts +4 -1
- package/dist/index.d.ts +12 -14
- package/dist/index.js +2184 -1175
- package/dist/index.js.map +1 -1
- package/dist/plugins/action.d.ts +6 -2
- package/dist/plugins/activity.d.ts +6 -0
- package/dist/plugins/blank-screen.d.ts +17 -0
- package/dist/plugins/common.d.ts +11 -3
- package/dist/plugins/device.d.ts +2 -0
- package/dist/plugins/long-task.d.ts +3 -12
- package/dist/plugins/page-view.d.ts +1 -0
- package/dist/plugins/request-body.d.ts +14 -0
- package/dist/plugins/resource.d.ts +17 -1
- package/dist/plugins/session-state.d.ts +18 -0
- package/dist/plugins/session.d.ts +4 -4
- package/dist/plugins/web-vitals.d.ts +74 -0
- package/dist/schema/attributes.d.ts +31 -10
- package/dist/schema/span.d.ts +4 -12
- package/package.json +3 -7
- package/skills/bk-rum-otele/SKILL.md +34 -33
- package/skills/bk-rum-otele/evals/evals.json +1 -1
- package/skills/bk-rum-otele/references/api.md +45 -13
- package/skills/bk-rum-otele/references/concepts.md +38 -112
- package/skills/bk-rum-otele/references/configuration.md +135 -228
- package/skills/bk-rum-otele/references/custom-plugin.md +8 -5
- package/skills/bk-rum-otele/references/data-model.md +13 -8
- package/skills/bk-rum-otele/references/framework-integration.md +25 -17
- package/skills/bk-rum-otele/references/getting-started.md +27 -87
- package/skills/bk-rum-otele/references/plugins.md +165 -99
- package/skills/bk-rum-otele/references/privacy.md +42 -33
- package/skills/bk-rum-otele/references/telemetry-reference.md +73 -44
- package/skills/bk-rum-otele/references/troubleshooting.md +72 -38
- package/dist/plugins/http-body.d.ts +0 -3
- package/dist/plugins/route-timing.d.ts +0 -2
|
@@ -2,317 +2,224 @@
|
|
|
2
2
|
|
|
3
3
|
# 配置总览
|
|
4
4
|
|
|
5
|
-
SDK
|
|
6
|
-
|
|
7
|
-
## 完整配置示例
|
|
5
|
+
SDK 入口按职责分为 `application`、`transport`、`session`、`tracking`、`context`、`privacy`、`extensions`。`application.name` 与 `transport` 必填;根 `transport.endpoint` 可由所有已开启信号的独立 endpoint 取代。
|
|
8
6
|
|
|
9
7
|
```ts
|
|
10
|
-
import { BkOpenTelemetry } from '@blueking/open-telemetry';
|
|
11
|
-
|
|
12
8
|
const bkOT = new BkOpenTelemetry({
|
|
13
|
-
|
|
14
|
-
autoStart: true,
|
|
15
|
-
debug: false,
|
|
16
|
-
app: {
|
|
9
|
+
application: {
|
|
17
10
|
name: 'bk-monitor-web',
|
|
18
11
|
environment: 'production',
|
|
19
12
|
version: '1.4.2',
|
|
20
13
|
},
|
|
21
|
-
user: {
|
|
22
|
-
id: 'user-12345',
|
|
23
|
-
},
|
|
24
14
|
transport: {
|
|
25
15
|
endpoint: 'https://rum-collector.example.com',
|
|
26
16
|
token: 'report-token',
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
signals: {
|
|
18
|
+
traces: { processor: 'batch', batch: { maxQueueSize: 2048 } },
|
|
19
|
+
metrics: { intervalMillis: 60_000 },
|
|
29
20
|
},
|
|
30
21
|
},
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
session: {
|
|
23
|
+
sampleRate: 0.2,
|
|
33
24
|
},
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
tracking: {
|
|
26
|
+
view: {
|
|
27
|
+
tracking: 'auto',
|
|
28
|
+
getPathGroup: url => new URL(url, location.href).pathname.replace(/\/\d+/g, '/:id'),
|
|
29
|
+
},
|
|
30
|
+
request: {
|
|
31
|
+
allowedTracingUrls: ['https://api.example.com'],
|
|
32
|
+
excludedUrls: [/\/health$/],
|
|
33
|
+
},
|
|
34
|
+
longTask: false,
|
|
35
|
+
websocket: false,
|
|
36
|
+
},
|
|
37
|
+
context: {
|
|
38
|
+
user: { id: 'user-12345' },
|
|
39
|
+
attributes: {
|
|
40
|
+
page: () => ({ 'biz.space_id': window.__BK_SPACE_ID__ }),
|
|
41
|
+
},
|
|
36
42
|
},
|
|
37
43
|
privacy: {
|
|
38
|
-
|
|
44
|
+
trackingConsent: 'granted',
|
|
39
45
|
redactAttributes: attributes => attributes,
|
|
40
46
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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,
|
|
47
|
+
extensions: {
|
|
48
|
+
plugins: [],
|
|
49
|
+
instrumentations: [],
|
|
73
50
|
},
|
|
74
51
|
});
|
|
75
|
-
|
|
76
|
-
export default bkOT;
|
|
77
52
|
```
|
|
78
53
|
|
|
79
54
|
## 顶层配置
|
|
80
55
|
|
|
81
56
|
| 配置 | 默认值 | 说明 |
|
|
82
57
|
| --- | --- | --- |
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
transport: {
|
|
106
|
-
endpoint: 'https://rum-collector.example.com',
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Instrumentation 配置
|
|
112
|
-
|
|
113
|
-
| 配置 | 默认值 | 说明 |
|
|
58
|
+
| `application.name` | 无 | 必填,写入 `service.name` |
|
|
59
|
+
| `application.environment` | `production` | 写入 `deployment.environment.name` |
|
|
60
|
+
| `application.version` | 无 | 写入 `service.version` |
|
|
61
|
+
| `transport.endpoint` | 无 | 上报根地址;已开启信号没有独立 endpoint 时必填 |
|
|
62
|
+
| `transport.signals.traces` | `{}` | Trace 配置;设为 `false` 关闭 |
|
|
63
|
+
| `transport.signals.metrics` | `{}` | Metric 配置;设为 `false` 关闭 |
|
|
64
|
+
| `transport.signals.logs` | `{}` | Log 配置;设为 `false` 关闭 |
|
|
65
|
+
| `session.sampleRate` | `1` | Session 级确定性采样率 |
|
|
66
|
+
| `tracking.view.tracking` | `auto` | 自动或手动 View |
|
|
67
|
+
| `tracking.view.loadingTime` | `true` | 自动计算 View loading time |
|
|
68
|
+
| `privacy.trackingConsent` | `granted` | 初始化授权状态 |
|
|
69
|
+
| `enabled` | `true` | 是否启用 SDK |
|
|
70
|
+
| `autoStart` | `true` | 构造后自动启动 |
|
|
71
|
+
| `debug` | `false` | 输出 exporter 与插件调试信息 |
|
|
72
|
+
|
|
73
|
+
Session 固定为 15 分钟无活动过期、4 小时最长生命周期。View 和 Session 是 RUM 关联边界,不能作为普通插件关闭。
|
|
74
|
+
|
|
75
|
+
## 内置采集开关
|
|
76
|
+
|
|
77
|
+
内置能力全部位于 `tracking`:
|
|
78
|
+
|
|
79
|
+
| 配置 | 默认 | 说明 |
|
|
114
80
|
| --- | --- | --- |
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
|
|
121
|
-
`
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
- 上述字符串/正则组成的数组:命中任意一个即注入。
|
|
127
|
-
- `(url: string) => boolean`:完全自定义判断。
|
|
128
|
-
|
|
129
|
-
```ts
|
|
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
|
-
```
|
|
137
|
-
|
|
138
|
-
> 注意:向跨域服务注入自定义头会触发 CORS 预检,目标服务需在 `Access-Control-Allow-Headers` 中放行 `traceparent`(以及按需的 `tracestate`),否则请求会被浏览器拦截。
|
|
139
|
-
|
|
140
|
-
示例:关闭接口自动采集。
|
|
81
|
+
| `view` | 开 | 初始加载、SPA、BFCache、手动 View |
|
|
82
|
+
| `request` | 开 | Fetch/XHR 请求 span、Trace Header、body |
|
|
83
|
+
| `resource` | 开 | 静态资源 span;PerformanceObserver 始终为 View 活动和请求 timing 服务 |
|
|
84
|
+
| `error` | 开 | JS、Promise 与资源错误 |
|
|
85
|
+
| `webVitals` | 开 | FCP/LCP/TTFB 及 View 级 CLS/INP |
|
|
86
|
+
| `blankScreen` | 开 | 白屏检测 |
|
|
87
|
+
| `device` | 开 | 浏览器、OS、屏幕与网络信息 |
|
|
88
|
+
| `action` | 开 | 点击 Action 与活动聚合 |
|
|
89
|
+
| `longTask` | 关 | LoAF/Long Task |
|
|
90
|
+
| `websocket` | 关 | WebSocket 指标 |
|
|
91
|
+
| `cspViolation` | 关 | CSP 违规 |
|
|
141
92
|
|
|
142
93
|
```ts
|
|
143
94
|
new BkOpenTelemetry({
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
95
|
+
application: { name: 'demo' },
|
|
96
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
97
|
+
tracking: {
|
|
98
|
+
request: false,
|
|
99
|
+
blankScreen: false,
|
|
100
|
+
longTask: { threshold: 80 },
|
|
147
101
|
},
|
|
148
102
|
});
|
|
149
103
|
```
|
|
150
104
|
|
|
151
|
-
##
|
|
105
|
+
## 请求配置
|
|
152
106
|
|
|
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
|
-
示例:开启高成本插件。
|
|
107
|
+
`tracking.request.allowedTracingUrls` 是严格白名单,同源请求也必须命中后才注入 `traceparent`。关闭 Trace 时不会注入。`excludedUrls` 命中后完全不采集。SDK 自身已开启 signal endpoint 始终排除。
|
|
170
108
|
|
|
171
109
|
```ts
|
|
172
110
|
new BkOpenTelemetry({
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
111
|
+
application: { name: 'request-demo' },
|
|
112
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
113
|
+
tracking: {
|
|
114
|
+
request: {
|
|
115
|
+
allowedTracingUrls: [/https:\/\/api\.example\.com/],
|
|
116
|
+
excludedUrls: [/\/health(?:\?|$)/],
|
|
117
|
+
beforeSend: (event, context) => {
|
|
118
|
+
event.attributes['request.transport'] = context.type;
|
|
119
|
+
return true;
|
|
120
|
+
},
|
|
121
|
+
body: {
|
|
122
|
+
capture: 'errors',
|
|
123
|
+
redact: ({ body }) => body.replace(/token=[^&]+/g, 'token=***'),
|
|
124
|
+
},
|
|
180
125
|
},
|
|
181
|
-
websocket: true,
|
|
182
126
|
},
|
|
183
127
|
});
|
|
184
128
|
```
|
|
185
129
|
|
|
186
|
-
|
|
130
|
+
跨域注入 Trace Header 可能触发 CORS 预检,服务端需要放行 `traceparent`。
|
|
187
131
|
|
|
188
|
-
|
|
132
|
+
## 全局 beforeSend
|
|
189
133
|
|
|
190
|
-
|
|
134
|
+
`tracking.beforeSend` 在 span/log 进入 exporter 前执行,可修改属性或返回 `false` 丢弃事件。内部 `bk.rum.sampled` 标记会在此之前移除。
|
|
191
135
|
|
|
192
136
|
```ts
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
137
|
+
tracking: {
|
|
138
|
+
beforeSend(event) {
|
|
139
|
+
delete event.attributes['debug.payload'];
|
|
140
|
+
return event.name !== 'custom.ignore-me';
|
|
197
141
|
},
|
|
198
|
-
}
|
|
142
|
+
}
|
|
199
143
|
```
|
|
200
144
|
|
|
201
|
-
|
|
145
|
+
## 不再支持的旧入口
|
|
146
|
+
|
|
147
|
+
`app`、`sampling`、`route`、顶层 `view`、`plugins`、`instrumentations`、`attributes`、`spanProcessor`、`spanBatch` 已删除,不做兼容映射。
|
|
202
148
|
|
|
203
|
-
|
|
204
|
-
- metrics:`https://rum-collector.example.com/v1/metrics`
|
|
205
|
-
- logs:`https://rum-collector.example.com/v1/logs`
|
|
149
|
+
# 传输与采样
|
|
206
150
|
|
|
207
|
-
##
|
|
151
|
+
## Endpoint
|
|
208
152
|
|
|
209
|
-
|
|
153
|
+
`transport.endpoint` 是可选根地址。未配置独立地址的已开启信号会基于它生成 `/v1/rum`、`/v1/metrics`、`/v1/logs`;单信号 `endpoint` 是完整 URL,不再拼接路径。
|
|
210
154
|
|
|
211
155
|
```ts
|
|
212
156
|
new BkOpenTelemetry({
|
|
157
|
+
application: { name: 'demo' },
|
|
213
158
|
transport: {
|
|
214
|
-
endpoint: 'https://
|
|
215
|
-
|
|
216
|
-
'x-bk-app-code': 'bk-monitor',
|
|
217
|
-
},
|
|
159
|
+
endpoint: 'https://collector.example.com',
|
|
160
|
+
token: 'report-token',
|
|
218
161
|
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
162
|
traces: {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
163
|
+
endpoint: 'https://trace.example.com/v1/rum',
|
|
164
|
+
processor: 'batch',
|
|
165
|
+
batch: {
|
|
166
|
+
maxQueueSize: 2048,
|
|
167
|
+
maxExportBatchSize: 512,
|
|
168
|
+
scheduledDelayMillis: 5000,
|
|
169
|
+
exportTimeoutMillis: 30000,
|
|
231
170
|
},
|
|
232
171
|
},
|
|
172
|
+
metrics: { endpoint: 'https://metric.example.com/v1/metrics', intervalMillis: 60_000 },
|
|
173
|
+
logs: { endpoint: 'https://log.example.com/v1/logs' },
|
|
233
174
|
},
|
|
234
175
|
},
|
|
235
176
|
});
|
|
236
177
|
```
|
|
237
178
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
## 避免自循环采集
|
|
241
|
-
|
|
242
|
-
SDK 内置 `FilteringSpanProcessor`,会过滤指向自身 OTLP endpoint 的 span,避免上报请求本身再次被 fetch/xhr instrumentation 采集。
|
|
179
|
+
## 独立信号开关
|
|
243
180
|
|
|
244
|
-
|
|
181
|
+
三类信号默认全部开启。设为 `false` 时,不创建对应 exporter、processor 或 metric reader:
|
|
245
182
|
|
|
246
183
|
```ts
|
|
247
184
|
new BkOpenTelemetry({
|
|
185
|
+
application: { name: 'trace-only-demo' },
|
|
248
186
|
transport: {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
187
|
+
signals: {
|
|
188
|
+
traces: { endpoint: 'https://trace.example.com/v1/rum' },
|
|
189
|
+
metrics: false,
|
|
190
|
+
logs: false,
|
|
191
|
+
},
|
|
254
192
|
},
|
|
255
193
|
});
|
|
256
194
|
```
|
|
257
195
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
fetch/xhr instrumentation 会给符合条件的同源请求注入 W3C `traceparent`,用于打通前后端 trace。跨域请求是否能传播还取决于服务端 CORS 是否允许该 header。
|
|
261
|
-
|
|
262
|
-
示例:前端请求同源 API。
|
|
263
|
-
|
|
264
|
-
```ts
|
|
265
|
-
await fetch('/api/orders/202605270001', {
|
|
266
|
-
method: 'GET',
|
|
267
|
-
});
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
## 会话级 sticky 采样
|
|
196
|
+
校验规则:
|
|
271
197
|
|
|
272
|
-
|
|
198
|
+
- 至少开启一种信号,三类不能全部为 `false`。
|
|
199
|
+
- 每个开启信号必须有独立 endpoint,或能回退到根 `transport.endpoint`。
|
|
200
|
+
- 关闭 Trace 后不记录 Span,也不会向 `allowedTracingUrls` 注入 `traceparent`。
|
|
201
|
+
- 关闭 Metric 后不启动周期导出定时器。
|
|
202
|
+
- 关闭 Log 不影响 Session/View 上下文维护,但不会产生 Session、View Snapshot、HTTP body 等 Log。
|
|
273
203
|
|
|
274
|
-
|
|
275
|
-
new BkOpenTelemetry({
|
|
276
|
-
sampling: {
|
|
277
|
-
rate: 0.05,
|
|
278
|
-
},
|
|
279
|
-
transport: {
|
|
280
|
-
endpoint: 'https://rum-collector.example.com',
|
|
281
|
-
},
|
|
282
|
-
});
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
需要注意:
|
|
204
|
+
只开启 Metric 时没有精确 `view.id` 下钻链路;需要从指标定位具体 View 时,至少开启 Trace。
|
|
286
205
|
|
|
287
|
-
|
|
288
|
-
- `rate: 0` 表示 RUM 插件和手动事件都不上报。
|
|
289
|
-
- 未命中采样时,主动产生数据的 RUM 插件不会启动。
|
|
290
|
-
- 调试时建议临时设置 `rate: 1` 和 `debug: true`。
|
|
206
|
+
请求头优先级:`token` 生成的 Authorization < `transport.headers` < 单 signal `headers`。
|
|
291
207
|
|
|
292
|
-
|
|
208
|
+
浏览器 exporter 使用 `fetch keepalive`,SDK 在 `pagehide` 和页面进入 hidden 时触发 flush。`shutdown()` 会先结束 View 和插件,再 flush final Snapshot,最后关闭 provider。
|
|
293
209
|
|
|
294
|
-
|
|
210
|
+
## Session 级确定性采样
|
|
295
211
|
|
|
296
212
|
```ts
|
|
297
213
|
new BkOpenTelemetry({
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
endpoint: 'http://localhost:4318',
|
|
302
|
-
},
|
|
214
|
+
application: { name: 'demo' },
|
|
215
|
+
transport: { endpoint: 'https://collector.example.com' },
|
|
216
|
+
session: { sampleRate: 0.05 },
|
|
303
217
|
});
|
|
304
218
|
```
|
|
305
219
|
|
|
306
|
-
|
|
220
|
+
- `1` 表示全量,`0` 表示全部丢弃。
|
|
221
|
+
- 决定由 `application.name + session.id` 的稳定 hash 得出。
|
|
222
|
+
- 不写额外 sessionStorage;同一 Session 内 span/log/metric 决定一致。
|
|
223
|
+
- Session 续期后使用新 ID 重新计算。
|
|
307
224
|
|
|
308
|
-
|
|
309
|
-
new BkOpenTelemetry({
|
|
310
|
-
spanProcessor: 'batch',
|
|
311
|
-
spanBatch: {
|
|
312
|
-
maxQueueSize: 2048,
|
|
313
|
-
maxExportBatchSize: 256,
|
|
314
|
-
scheduledDelayMillis: 5000,
|
|
315
|
-
exportTimeoutMillis: 30000,
|
|
316
|
-
},
|
|
317
|
-
});
|
|
318
|
-
```
|
|
225
|
+
Metric exporter 只接受带内部采样标记的数据点,并在传输前移除该标记。Metric 只保留低基数 `view.url_path_group`,精确 View 关联由 span/log/View Snapshot 的 `view.id` 提供。
|
|
@@ -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',
|
|
@@ -125,18 +126,19 @@ const createResizePlugin = () => {
|
|
|
125
126
|
|
|
126
127
|
## 注册额外 instrumentation
|
|
127
128
|
|
|
128
|
-
第三方 OpenTelemetry instrumentation
|
|
129
|
+
第三方 OpenTelemetry instrumentation 放在 `extensions.instrumentations`,或通过 `useInstrumentation()` 链式注册。两者区别详见 [内置采集与扩展](./concepts.md)。
|
|
129
130
|
|
|
130
131
|
配置式:
|
|
131
132
|
|
|
132
133
|
```ts
|
|
133
134
|
const bkOT = new BkOpenTelemetry({
|
|
134
|
-
|
|
135
|
-
custom: [new SomeWebInstrumentation()],
|
|
136
|
-
},
|
|
135
|
+
application: { name: 'extension-demo' },
|
|
137
136
|
transport: {
|
|
138
137
|
endpoint: 'https://rum-collector.example.com',
|
|
139
138
|
},
|
|
139
|
+
extensions: {
|
|
140
|
+
instrumentations: [new SomeWebInstrumentation()],
|
|
141
|
+
},
|
|
140
142
|
});
|
|
141
143
|
```
|
|
142
144
|
|
|
@@ -144,6 +146,7 @@ const bkOT = new BkOpenTelemetry({
|
|
|
144
146
|
|
|
145
147
|
```ts
|
|
146
148
|
const bkOT = new BkOpenTelemetry({
|
|
149
|
+
application: { name: 'extension-demo' },
|
|
147
150
|
autoStart: false,
|
|
148
151
|
transport: {
|
|
149
152
|
endpoint: 'https://rum-collector.example.com',
|
|
@@ -155,4 +158,4 @@ bkOT.useInstrumentation(new SomeWebInstrumentation());
|
|
|
155
158
|
await bkOT.start();
|
|
156
159
|
```
|
|
157
160
|
|
|
158
|
-
>
|
|
161
|
+
> Extension instrumentation 与采集生命周期一致:未授权或 SDK 停止时不会注册;授权后注册。它产生的 RUM 数据仍受 Session sampler 和导出过滤约束。
|
|
@@ -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
21
|
| `error` | 错误 | error 插件、blankScreen 插件、cspViolation 插件、自定义事件错误 |
|
|
23
22
|
| `longtask` | 长任务 | longTask 插件 |
|
|
24
23
|
| `action` | 用户动作 | action 插件、reportAction |
|
|
25
|
-
| `route` | 路由切换 |
|
|
24
|
+
| `route` | 路由切换 | View 管理器(SPA/手动 View) |
|
|
26
25
|
| `custom` | 自定义事件 | reportCustomEvent、自定义插件、websocket 插件 |
|
|
27
26
|
|
|
28
|
-
> 每种 span 的具体 span
|
|
27
|
+
> 每种 span 的具体 span 名、metric 名、log 事件名和完整属性字典见[遥测参考](./telemetry-reference.md)。
|
|
29
28
|
|
|
30
29
|
示例:自定义业务事件归一为 `custom`。
|
|
31
30
|
|
|
@@ -55,7 +54,7 @@ span.end();
|
|
|
55
54
|
- `timeout`
|
|
56
55
|
- `abort`
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
请求 Resource Span 会根据状态码推导结果:`408`、`504` 为 timeout,`>= 400` 为 error,其余为 success。
|
|
59
58
|
|
|
60
59
|
```ts
|
|
61
60
|
bkOT.reportCustomEvent({
|
|
@@ -89,8 +88,8 @@ console.log(getDurationBucket(1200)); // 500ms~2s
|
|
|
89
88
|
|
|
90
89
|
- 应用与环境:`service.name`、`deployment.environment.name`、`service.version`
|
|
91
90
|
- 用户与会话:`user.id`、`session.id`
|
|
92
|
-
- View:`view.id`、`view.url`、`view.url_path_group`、`view.loading_type`
|
|
93
|
-
- 终端信息:`
|
|
91
|
+
- View:`view.id`、`view.name`、`view.url`、`view.url_path_group`、`view.loading_type`
|
|
92
|
+
- 终端信息:`device.type`、`browser.name`、`browser.version`、`os.name`、`network.effective_type`
|
|
94
93
|
- HTTP / Resource:`http.request.method`、`http.response.status_code`、`url.full`、`transfer_size`
|
|
95
94
|
- Web Vitals:`vital.metric`、`vital.value`、`vital.rating`
|
|
96
95
|
- Error:`exception.type`、`exception.message`、`exception.stacktrace`、`exception.fingerprint`
|
|
@@ -120,3 +119,9 @@ bkOT.reportCustomEvent({
|
|
|
120
119
|
```
|
|
121
120
|
|
|
122
121
|
上例中 `biz.order_id` 适合放在 span/log 中定位单次问题,不适合作为 metric 维度做长期聚合。
|
|
122
|
+
|
|
123
|
+
## Metric 与 View 的关联
|
|
124
|
+
|
|
125
|
+
Metric 不携带唯一的 `view.id`、`session.id` 或 `action.id`,只保留 `view.url_path_group`、`view.loading_type` 等低基数维度。这样可以按页面类型聚合,又不会因为每次访问生成新的时序而造成基数爆炸。
|
|
126
|
+
|
|
127
|
+
需要定位某一次 View 时,使用同一指标对应的 span(例如 `browser.web_vital`)或 View Snapshot Log;它们携带精确的 `session.id` 和 `view.id`。后端需要从聚合指标跳转到样本时,应通过 exemplar 或 span/log 派生聚合建立关联,而不是把 `view.id` 放进 metric labels。
|
|
@@ -12,14 +12,17 @@ import { BkOpenTelemetry } from '@blueking/open-telemetry';
|
|
|
12
12
|
|
|
13
13
|
export const bkOT = new BkOpenTelemetry({
|
|
14
14
|
autoStart: false,
|
|
15
|
-
|
|
15
|
+
application: {
|
|
16
16
|
name: 'vue-rum-demo',
|
|
17
17
|
environment: import.meta.env.MODE,
|
|
18
18
|
},
|
|
19
19
|
transport: {
|
|
20
20
|
endpoint: 'https://rum-collector.example.com',
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
tracking: {
|
|
23
|
+
view: {
|
|
24
|
+
tracking: 'manual',
|
|
25
|
+
},
|
|
23
26
|
blankScreen: {
|
|
24
27
|
rootSelector: '#app',
|
|
25
28
|
},
|
|
@@ -35,10 +38,9 @@ import App from './App.vue';
|
|
|
35
38
|
import router from './router';
|
|
36
39
|
|
|
37
40
|
router.afterEach(to => {
|
|
38
|
-
bkOT.
|
|
41
|
+
bkOT.startView({
|
|
42
|
+
name: to.matched.at(-1)?.path || to.path,
|
|
39
43
|
url: window.location.href,
|
|
40
|
-
urlPathGroup: to.matched.at(-1)?.path || to.path,
|
|
41
|
-
loadingType: 'route_change',
|
|
42
44
|
});
|
|
43
45
|
});
|
|
44
46
|
|
|
@@ -49,7 +51,7 @@ createApp(App).use(router).mount('#app');
|
|
|
49
51
|
|
|
50
52
|
## Vue Router 路由模板
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
自动模式不需要 `afterEach`,通过 `tracking.view.getPathGroup` 统一生成低基数路径。
|
|
53
55
|
|
|
54
56
|
```ts
|
|
55
57
|
const routeGroups = [
|
|
@@ -58,10 +60,14 @@ const routeGroups = [
|
|
|
58
60
|
];
|
|
59
61
|
|
|
60
62
|
new BkOpenTelemetry({
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
application: { name: 'vue-rum-demo' },
|
|
64
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
65
|
+
tracking: {
|
|
66
|
+
view: {
|
|
67
|
+
getPathGroup: url => {
|
|
68
|
+
const pathname = new URL(url, window.location.href).pathname;
|
|
69
|
+
return routeGroups.find(route => route.pattern.test(pathname))?.group || pathname.replace(/\/\d+/g, '/:id');
|
|
70
|
+
},
|
|
65
71
|
},
|
|
66
72
|
},
|
|
67
73
|
});
|
|
@@ -75,9 +81,10 @@ import { useEffect } from 'react';
|
|
|
75
81
|
import { useLocation, useMatches } from 'react-router-dom';
|
|
76
82
|
|
|
77
83
|
export const bkOT = new BkOpenTelemetry({
|
|
78
|
-
|
|
84
|
+
application: { name: 'react-rum-demo' },
|
|
79
85
|
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
80
|
-
|
|
86
|
+
tracking: {
|
|
87
|
+
view: { tracking: 'manual' },
|
|
81
88
|
blankScreen: {
|
|
82
89
|
rootSelector: '#root',
|
|
83
90
|
},
|
|
@@ -89,10 +96,9 @@ export const RumRouteSync = () => {
|
|
|
89
96
|
const matches = useMatches();
|
|
90
97
|
|
|
91
98
|
useEffect(() => {
|
|
92
|
-
bkOT.
|
|
99
|
+
bkOT.startView({
|
|
100
|
+
name: matches.at(-1)?.pathname || location.pathname,
|
|
93
101
|
url: window.location.href,
|
|
94
|
-
urlPathGroup: matches.at(-1)?.pathname || location.pathname,
|
|
95
|
-
loadingType: 'route_change',
|
|
96
102
|
});
|
|
97
103
|
}, [location.pathname, matches]);
|
|
98
104
|
|
|
@@ -127,14 +133,16 @@ export const onLogout = () => {
|
|
|
127
133
|
import { BkOpenTelemetry } from '@blueking/open-telemetry';
|
|
128
134
|
|
|
129
135
|
const bkOT = new BkOpenTelemetry({
|
|
130
|
-
|
|
136
|
+
application: { name: 'micro-frontend-host' },
|
|
131
137
|
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
132
138
|
});
|
|
133
139
|
|
|
134
140
|
window.__BK_RUM__ = {
|
|
135
141
|
reportAction: bkOT.reportAction,
|
|
136
142
|
reportCustomEvent: bkOT.reportCustomEvent,
|
|
137
|
-
|
|
143
|
+
setViewName: bkOT.setViewName,
|
|
144
|
+
setViewLoadingTime: bkOT.setViewLoadingTime,
|
|
145
|
+
startView: bkOT.startView,
|
|
138
146
|
};
|
|
139
147
|
```
|
|
140
148
|
|