@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.
Files changed (49) hide show
  1. package/README.md +96 -641
  2. package/dist/bk-rum.global.js +9 -9
  3. package/dist/bk-rum.global.js.map +1 -1
  4. package/dist/core/action-activity.d.ts +28 -0
  5. package/dist/core/config.d.ts +113 -93
  6. package/dist/core/page-activity.d.ts +14 -0
  7. package/dist/core/plugin.d.ts +23 -6
  8. package/dist/core/processor.d.ts +25 -4
  9. package/dist/core/request-timing.d.ts +5 -0
  10. package/dist/core/runtime-context.d.ts +51 -3
  11. package/dist/core/sampling.d.ts +5 -1
  12. package/dist/core/sdk.d.ts +29 -10
  13. package/dist/core/url.d.ts +4 -1
  14. package/dist/index.d.ts +12 -14
  15. package/dist/index.js +2184 -1175
  16. package/dist/index.js.map +1 -1
  17. package/dist/plugins/action.d.ts +6 -2
  18. package/dist/plugins/activity.d.ts +6 -0
  19. package/dist/plugins/blank-screen.d.ts +17 -0
  20. package/dist/plugins/common.d.ts +11 -3
  21. package/dist/plugins/device.d.ts +2 -0
  22. package/dist/plugins/long-task.d.ts +3 -12
  23. package/dist/plugins/page-view.d.ts +1 -0
  24. package/dist/plugins/request-body.d.ts +14 -0
  25. package/dist/plugins/resource.d.ts +17 -1
  26. package/dist/plugins/session-state.d.ts +18 -0
  27. package/dist/plugins/session.d.ts +4 -4
  28. package/dist/plugins/web-vitals.d.ts +74 -0
  29. package/dist/schema/attributes.d.ts +31 -10
  30. package/dist/schema/span.d.ts +4 -12
  31. package/package.json +3 -7
  32. package/skills/bk-rum-otele/SKILL.md +39 -33
  33. package/skills/bk-rum-otele/evals/evals.json +3 -3
  34. package/skills/bk-rum-otele/references/api.md +247 -114
  35. package/skills/bk-rum-otele/references/architecture.md +141 -0
  36. package/skills/bk-rum-otele/references/capabilities.md +100 -0
  37. package/skills/bk-rum-otele/references/concepts.md +40 -111
  38. package/skills/bk-rum-otele/references/configuration.md +202 -254
  39. package/skills/bk-rum-otele/references/custom-plugin.md +22 -7
  40. package/skills/bk-rum-otele/references/data-model.md +17 -10
  41. package/skills/bk-rum-otele/references/framework-integration.md +25 -17
  42. package/skills/bk-rum-otele/references/getting-started.md +42 -86
  43. package/skills/bk-rum-otele/references/plugins.md +232 -138
  44. package/skills/bk-rum-otele/references/privacy.md +47 -34
  45. package/skills/bk-rum-otele/references/telemetry-reference.md +74 -45
  46. package/skills/bk-rum-otele/references/transport-sampling.md +79 -0
  47. package/skills/bk-rum-otele/references/troubleshooting.md +71 -37
  48. package/dist/plugins/http-body.d.ts +0 -3
  49. package/dist/plugins/route-timing.d.ts +0 -2
@@ -10,13 +10,16 @@
10
10
 
11
11
  ```ts
12
12
  new BkOpenTelemetry({
13
+ application: { name: 'rum-debug' },
13
14
  debug: true,
14
- spanProcessor: 'simple',
15
- sampling: {
16
- rate: 1,
15
+ session: {
16
+ sampleRate: 1,
17
17
  },
18
18
  transport: {
19
19
  endpoint: 'http://localhost:4318',
20
+ signals: {
21
+ traces: { processor: 'simple' },
22
+ },
20
23
  },
21
24
  });
22
25
  ```
@@ -34,10 +37,12 @@ new BkOpenTelemetry({
34
37
 
35
38
  ```ts
36
39
  new BkOpenTelemetry({
40
+ application: { name: 'rum-debug' },
37
41
  debug: true,
38
- sampling: {
39
- rate: 1,
42
+ session: {
43
+ sampleRate: 1,
40
44
  },
45
+ transport: { endpoint: 'https://rum-collector.example.com' },
41
46
  });
42
47
  ```
43
48
 
@@ -47,7 +52,9 @@ new BkOpenTelemetry({
47
52
 
48
53
  ```ts
49
54
  const bkOT = new BkOpenTelemetry({
55
+ application: { name: 'rum-debug' },
50
56
  autoStart: false,
57
+ transport: { endpoint: 'https://rum-collector.example.com' },
51
58
  });
52
59
 
53
60
  bkOT.use(myPlugin);
@@ -61,7 +68,9 @@ SPA 应用应配置 `rootSelector` 和 loading/skeleton 忽略选择器。
61
68
 
62
69
  ```ts
63
70
  new BkOpenTelemetry({
64
- plugins: {
71
+ application: { name: 'rum-debug' },
72
+ transport: { endpoint: 'https://rum-collector.example.com' },
73
+ tracking: {
65
74
  blankScreen: {
66
75
  rootSelector: '#app',
67
76
  ignoreSelectors: ['.bk-loading', '.skeleton'],
@@ -73,13 +82,16 @@ new BkOpenTelemetry({
73
82
 
74
83
  ## 接口 span 太多
75
84
 
76
- 先确认是否有多个 SDK 实例重复初始化,尤其是微前端场景。其次可以关闭不需要的 instrumentation。
85
+ 先确认是否有多个 SDK 实例重复初始化,尤其是微前端场景。其次用 `excludedUrls` 排除探活或高频无价值请求。
77
86
 
78
87
  ```ts
79
88
  new BkOpenTelemetry({
80
- instrumentations: {
81
- fetch: true,
82
- xhr: false,
89
+ application: { name: 'rum-debug' },
90
+ transport: { endpoint: 'https://rum-collector.example.com' },
91
+ tracking: {
92
+ request: {
93
+ excludedUrls: [/\/health(?:\?|$)/, /\/polling\//],
94
+ },
83
95
  },
84
96
  });
85
97
  ```
@@ -90,6 +102,8 @@ new BkOpenTelemetry({
90
102
 
91
103
  ```ts
92
104
  new BkOpenTelemetry({
105
+ application: { name: 'rum-debug' },
106
+ transport: { endpoint: 'https://rum-collector.example.com' },
93
107
  privacy: {
94
108
  redactUrl: url => url.replace(/([?&]token=)[^&]+/g, '$1***'),
95
109
  redactAttributes: attributes => {
@@ -107,7 +121,9 @@ Long Task API 并非所有浏览器都支持。Firefox 不支持时插件会跳
107
121
 
108
122
  ```ts
109
123
  new BkOpenTelemetry({
110
- plugins: {
124
+ application: { name: 'rum-debug' },
125
+ transport: { endpoint: 'https://rum-collector.example.com' },
126
+ tracking: {
111
127
  longTask: {
112
128
  threshold: 50,
113
129
  },
@@ -117,26 +133,36 @@ new BkOpenTelemetry({
117
133
 
118
134
  ## HTTP body 没有数据
119
135
 
120
- `httpBody` 只在错误路径采集,且默认关闭。
136
+ 请求/响应 body 默认关闭。需要采集时配置 `tracking.request.body`,并提供必填的 `redact`:
121
137
 
122
138
  ```ts
123
139
  new BkOpenTelemetry({
124
- plugins: {
125
- httpBody: {
126
- maxBodySize: 4096,
127
- redact: ({ body }) => body,
140
+ application: { name: 'rum-debug' },
141
+ transport: { endpoint: 'https://rum-collector.example.com' },
142
+ tracking: {
143
+ request: {
144
+ body: {
145
+ capture: 'errors',
146
+ allowedContentTypes: ['application/json'],
147
+ maxSize: 10 * 1024,
148
+ redact: ({ body }) => body.replace(/"password"\s*:\s*"[^"]+"/g, '"password":"***"'),
149
+ },
128
150
  },
129
151
  },
130
152
  });
131
153
  ```
132
154
 
155
+ `capture` 默认就是 `errors`,成功请求不会产生 body Log;要采集成功请求需显式设为 `all`。如果仍然没有数据,依次检查 Content-Type 是否命中 `allowedContentTypes`、body 是否为支持的文本类型,以及 `redact` 是否返回了 `undefined`。FormData、ArrayBuffer 和二进制响应会跳过。
156
+
133
157
  ## WebSocket 采集异常
134
158
 
135
159
  WebSocket 插件会 Proxy 全局 `WebSocket`。如果应用或第三方库也 patch 了 WebSocket,应避免重复 patch。
136
160
 
137
161
  ```ts
138
162
  new BkOpenTelemetry({
139
- plugins: {
163
+ application: { name: 'rum-debug' },
164
+ transport: { endpoint: 'https://rum-collector.example.com' },
165
+ tracking: {
140
166
  websocket: true,
141
167
  },
142
168
  });
@@ -146,14 +172,15 @@ new BkOpenTelemetry({
146
172
 
147
173
  ## SDK 会采集哪些数据?
148
174
 
149
- 默认采集页面访问、资源加载、fetch/xhr、JavaScript 错误、Web Vitals、空白屏、设备信息和会话信息。动作、HTTP body、Long Task、路由耗时、CSP、WebSocket 默认关闭。
175
+ 默认采集页面访问与稳定耗时、用户动作、资源加载、fetch/xhr、JavaScript 错误、Web Vitals、空白屏、设备信息和会话信息。HTTP body、Long Task、CSP、WebSocket 默认关闭。
150
176
 
151
177
  ```ts
152
178
  new BkOpenTelemetry({
153
- plugins: {
179
+ application: { name: 'demo' },
180
+ transport: { endpoint: 'https://rum-collector.example.com' },
181
+ tracking: {
154
182
  action: true,
155
183
  longTask: true,
156
- routeTiming: true,
157
184
  websocket: true,
158
185
  },
159
186
  });
@@ -165,32 +192,37 @@ new BkOpenTelemetry({
165
192
 
166
193
  ```ts
167
194
  new BkOpenTelemetry({
168
- user: {
169
- id: hashUserId(rawUserId),
195
+ application: { name: 'demo' },
196
+ transport: { endpoint: 'https://rum-collector.example.com' },
197
+ context: {
198
+ user: {
199
+ id: hashUserId(rawUserId),
200
+ },
170
201
  },
171
202
  });
172
203
  ```
173
204
 
174
- ## `sampling.rate` 是 trace 级采样吗?
205
+ ## `session.sampleRate` 是 trace 级采样吗?
175
206
 
176
- 不是。它是会话级 sticky 采样,同一会话内保持一致。
207
+ 不是。它是会话级确定性采样,同一会话内保持一致。
177
208
 
178
209
  ```ts
179
210
  new BkOpenTelemetry({
180
- sampling: {
181
- rate: 0.2,
211
+ application: { name: 'demo' },
212
+ transport: { endpoint: 'https://rum-collector.example.com' },
213
+ session: {
214
+ sampleRate: 0.2,
182
215
  },
183
216
  });
184
217
  ```
185
218
 
186
- ## 为什么开启了 userInteraction 还需要 action 插件?
219
+ ## 为什么不使用 OpenTelemetry userInteraction instrumentation?
187
220
 
188
- `userInteraction` 是 OpenTelemetry 官方 instrumentation,产生的是官方用户交互 span;`action` 插件和 `reportAction()` 会写入 SDK 的 RUM action 归一字段。需要稳定的业务动作模型时,推荐使用 `action` 或 `reportAction()`。
221
+ 官方 userInteraction instrumentation 主要用于把交互回调中的异步任务组织成 trace,但没有稳定的 RUM action 语义、动作命名、页面活动窗口和关联计数。本 SDK 统一使用 `action` 插件,避免同一次点击重复上报;内置 request 采集统一负责 Fetch/XHR 网络 trace。
189
222
 
190
223
  ```ts
191
224
  bkOT.reportAction({
192
- type: 'click',
193
- targetText: '确认提交',
225
+ name: '确认提交',
194
226
  attributes: {
195
227
  'biz.scene': 'strategy-create',
196
228
  },
@@ -199,29 +231,31 @@ bkOT.reportAction({
199
231
 
200
232
  ## 可以只上报 traces,不上报 metrics/logs 吗?
201
233
 
202
- 当前 SDK 会初始化三类 provider。可以在 Collector 或网关层按信号丢弃,也可以为不同信号配置不同 endpoint。
234
+ 可以。将不需要的信号设为 `false`;根 endpoint 在所有已开启信号都配置独立地址时可以省略。
203
235
 
204
236
  ```ts
205
237
  new BkOpenTelemetry({
238
+ application: { name: 'demo' },
206
239
  transport: {
207
240
  signals: {
208
- endpoints: {
209
- traces: 'https://trace-gateway.example.com/v1/rum',
210
- metrics: 'https://metric-gateway.example.com/v1/metrics',
211
- logs: 'https://log-gateway.example.com/v1/logs',
212
- },
241
+ traces: { endpoint: 'https://trace-gateway.example.com/v1/rum' },
242
+ metrics: false,
243
+ logs: false,
213
244
  },
214
245
  },
215
246
  });
216
247
  ```
217
248
 
249
+ 三类信号不能全部关闭。关闭 Trace 后也不会注入 `traceparent`。
250
+
218
251
  ## 为什么不建议多个实例同时运行?
219
252
 
220
- fetch、xhr、userInteraction、websocket 等能力会 patch 全局 API。多个实例可能重复 patch、重复上报或互相影响。
253
+ fetch、xhr、action、websocket 等能力会监听或 patch 全局 API。多个实例可能重复采集、重复上报或互相影响。
221
254
 
222
255
  ```ts
223
256
  if (!window.__BK_RUM_INSTANCE__) {
224
257
  window.__BK_RUM_INSTANCE__ = new BkOpenTelemetry({
258
+ application: { name: 'demo' },
225
259
  transport: {
226
260
  endpoint: 'https://rum-collector.example.com',
227
261
  },
@@ -1,3 +0,0 @@
1
- import type { BkOTHttpBodyConfig } from '../core/config';
2
- import type { BkOTPlugin } from '../core/plugin';
3
- export declare const createHttpBodyPlugin: (options?: BkOTHttpBodyConfig) => BkOTPlugin;
@@ -1,2 +0,0 @@
1
- import type { BkOTPlugin } from '../core/plugin';
2
- export declare const createRouteTimingPlugin: () => BkOTPlugin;