@blueking/open-telemetry 0.0.21 → 0.0.22-beta.1

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 (43) hide show
  1. package/README.md +11 -25
  2. package/dist/bk-rum.global.js +2 -12
  3. package/dist/bk-rum.global.js.map +1 -1
  4. package/dist/core/config.d.ts +8 -44
  5. package/dist/core/hash.d.ts +2 -0
  6. package/dist/core/plugin.d.ts +2 -7
  7. package/dist/core/processor.d.ts +0 -20
  8. package/dist/core/sdk.d.ts +1 -7
  9. package/dist/core/telemetry-attributes.d.ts +1 -2
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +1045 -1471
  12. package/dist/index.js.map +1 -1
  13. package/dist/plugins/common.d.ts +1 -1
  14. package/dist/plugins/csp-violation.d.ts +0 -8
  15. package/dist/plugins/error.d.ts +1 -5
  16. package/dist/plugins/long-task.d.ts +1 -3
  17. package/dist/plugins/web-vitals.d.ts +1 -4
  18. package/dist/schema/attributes.d.ts +8 -10
  19. package/dist/schema/span.d.ts +2 -0
  20. package/package.json +1 -6
  21. package/skills/bk-rum-otele/SKILL.md +3 -3
  22. package/skills/bk-rum-otele/evals/evals.json +2 -2
  23. package/skills/bk-rum-otele/references/api.md +10 -22
  24. package/skills/bk-rum-otele/references/architecture.md +38 -118
  25. package/skills/bk-rum-otele/references/capabilities.md +26 -28
  26. package/skills/bk-rum-otele/references/concepts.md +14 -106
  27. package/skills/bk-rum-otele/references/configuration.md +25 -66
  28. package/skills/bk-rum-otele/references/custom-plugin.md +10 -13
  29. package/skills/bk-rum-otele/references/data-model.md +23 -95
  30. package/skills/bk-rum-otele/references/getting-started.md +1 -1
  31. package/skills/bk-rum-otele/references/plugins-basic.md +7 -7
  32. package/skills/bk-rum-otele/references/plugins-error-security.md +1 -1
  33. package/skills/bk-rum-otele/references/plugins-experience.md +4 -5
  34. package/skills/bk-rum-otele/references/plugins-network.md +19 -128
  35. package/skills/bk-rum-otele/references/plugins.md +3 -3
  36. package/skills/bk-rum-otele/references/privacy.md +4 -25
  37. package/skills/bk-rum-otele/references/telemetry-reference.md +49 -279
  38. package/skills/bk-rum-otele/references/transport-sampling.md +15 -50
  39. package/skills/bk-rum-otele/references/troubleshooting.md +7 -34
  40. package/dist/core/metric.d.ts +0 -2
  41. package/dist/core/signal.d.ts +0 -3
  42. package/dist/core/throttle.d.ts +0 -20
  43. package/dist/plugins/request-body.d.ts +0 -15
@@ -2,9 +2,9 @@
2
2
 
3
3
  # 传输与采样
4
4
 
5
- ## Endpoint
5
+ ## 单一 Endpoint
6
6
 
7
- `transport.endpoint` 是可选根地址。未配置独立地址的已开启信号会基于它生成 `/v1/rum`、`/v1/metrics`、`/v1/logs`;单信号 `endpoint` 是完整 URL,不再拼接路径。
7
+ `transport.endpoint` 是必填根地址,SDK 去掉末尾斜杠后拼接 `/v1/rum`。没有 `/v1/metrics`、`/v1/logs` 或独立信号开关。
8
8
 
9
9
  ```ts
10
10
  new BkOpenTelemetry({
@@ -12,54 +12,20 @@ new BkOpenTelemetry({
12
12
  transport: {
13
13
  endpoint: 'https://collector.example.com',
14
14
  token: 'report-token',
15
- signals: {
16
- traces: {
17
- endpoint: 'https://trace.example.com/v1/rum',
18
- processor: 'batch',
19
- batch: {
20
- maxQueueSize: 2048,
21
- maxExportBatchSize: 512,
22
- scheduledDelayMillis: 5000,
23
- exportTimeoutMillis: 30000,
24
- },
25
- },
26
- metrics: { endpoint: 'https://metric.example.com/v1/metrics', intervalMillis: 60_000 },
27
- logs: { endpoint: 'https://log.example.com/v1/logs' },
15
+ processor: 'batch',
16
+ batch: {
17
+ maxQueueSize: 2048,
18
+ maxExportBatchSize: 512,
19
+ scheduledDelayMillis: 5000,
20
+ exportTimeoutMillis: 30000,
28
21
  },
22
+ timeoutMillis: 10_000,
23
+ concurrencyLimit: 10,
29
24
  },
30
25
  });
31
26
  ```
32
27
 
33
- ## 独立信号开关
34
-
35
- 三类信号默认全部开启。设为 `false` 时,不创建对应 exporter、processor 或 metric reader:
36
-
37
- ```ts
38
- new BkOpenTelemetry({
39
- application: { name: 'trace-only-demo' },
40
- transport: {
41
- signals: {
42
- traces: { endpoint: 'https://trace.example.com/v1/rum' },
43
- metrics: false,
44
- logs: false,
45
- },
46
- },
47
- });
48
- ```
49
-
50
- 校验规则:
51
-
52
- - 至少开启一种信号,三类不能全部为 `false`。
53
- - 每个开启信号必须有独立 endpoint,或能回退到根 `transport.endpoint`。
54
- - 关闭 Trace 后不记录 Span,也不会向 `allowedTracingUrls` 注入 `traceparent`。
55
- - 关闭 Metric 后不启动周期导出定时器。
56
- - 关闭 Log 不影响 Session/View 上下文维护,但不会产生 Session、View Snapshot、HTTP body 等 Log。
57
-
58
- 只开启 Metric 时没有精确 `view.id` 下钻链路;需要从指标定位具体 View 时,至少开启 Trace。
59
-
60
- 请求头优先级:`token` 生成的 Authorization < `transport.headers` < 单 signal `headers`。
61
-
62
- 浏览器 OTLP HTTP exporter 负责实际传输,SDK 在 `pagehide` 和页面进入 hidden 时触发 flush。`shutdown()` 会先结束 View 和插件,再 flush final Snapshot,最后关闭 provider。
28
+ `token` 生成默认 `Authorization: Bearer <token>`,显式 `headers` 可覆盖它。SDK 在 `pagehide` 和页面进入 hidden 时触发 flush。
63
29
 
64
30
  ## Session 级确定性采样
65
31
 
@@ -72,8 +38,7 @@ new BkOpenTelemetry({
72
38
  ```
73
39
 
74
40
  - `1` 表示全量,`0` 表示全部丢弃。
75
- - 决定由 `application.name + session.id` 的稳定 hash 得出。
76
- - 采样决定不写额外 storage;同一 Session 内 span/log/metric 决定一致。
77
- - Session 续期后使用新 ID 重新计算。
78
-
79
- Metric exporter 只接受带内部采样标记的数据点,并在传输前移除该标记。Metric 只保留低基数 `view.url_path_group`,精确 View 关联由 span/log/View Snapshot 的 `view.id` 提供。
41
+ - 采样由 `application.name + session.id` 的稳定 hash 决定。
42
+ - Session 轮换后使用新 ID 重新计算。
43
+ - `session.sample_rate` 写入 Resource,供后端做采样率修正。
44
+ - 未采样 Session 不创建可导出的 RUM Span。
@@ -17,9 +17,7 @@ new BkOpenTelemetry({
17
17
  },
18
18
  transport: {
19
19
  endpoint: 'http://localhost:4318',
20
- signals: {
21
- traces: { processor: 'simple' },
22
- },
20
+ processor: 'simple',
23
21
  },
24
22
  });
25
23
  ```
@@ -27,7 +25,7 @@ new BkOpenTelemetry({
27
25
  检查点:
28
26
 
29
27
  - Collector 是否监听 `4318`。
30
- - 浏览器 Network 中是否有 `/v1/rum`、`/v1/metrics`、`/v1/logs` 请求。
28
+ - 浏览器 Network 中是否有 `/v1/rum` 请求。
31
29
  - 是否被采样丢弃。
32
30
  - `enabled` 是否为 `false`。
33
31
 
@@ -131,28 +129,9 @@ new BkOpenTelemetry({
131
129
  });
132
130
  ```
133
131
 
134
- ## HTTP body 没有数据
135
-
136
- 请求/响应 body 默认关闭。需要采集时配置 `tracking.request.body`,并提供必填的 `redact`:
137
-
138
- ```ts
139
- new BkOpenTelemetry({
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
- },
150
- },
151
- },
152
- });
153
- ```
132
+ ## HTTP Body 没有数据
154
133
 
155
- `capture` 默认就是 `errors`,成功请求不会产生 body Log;要采集成功请求需显式设为 `all`。如果仍然没有数据,依次检查 Content-Type 是否命中 `allowedContentTypes`、body 是否为支持的文本类型,以及 `redact` 是否返回了 `undefined`。FormData、ArrayBuffer 和二进制响应会跳过。
134
+ 这是预期行为:SDK 不读取或上报请求/响应 Body。
156
135
 
157
136
  ## WebSocket 采集异常
158
137
 
@@ -231,22 +210,16 @@ bkOT.reportAction({
231
210
 
232
211
  ## 可以只上报 traces,不上报 metrics/logs 吗?
233
212
 
234
- 可以。将不需要的信号设为 `false`;根 endpoint 在所有已开启信号都配置独立地址时可以省略。
213
+ SDK 固定只上报 RUM Trace,不创建 Metrics/Logs Provider,无需配置开关。
235
214
 
236
215
  ```ts
237
216
  new BkOpenTelemetry({
238
217
  application: { name: 'demo' },
239
- transport: {
240
- signals: {
241
- traces: { endpoint: 'https://trace-gateway.example.com/v1/rum' },
242
- metrics: false,
243
- logs: false,
244
- },
245
- },
218
+ transport: { endpoint: 'https://trace-gateway.example.com' },
246
219
  });
247
220
  ```
248
221
 
249
- 三类信号不能全部关闭。关闭 Trace 后也不会注入 `traceparent`。
222
+ Endpoint 会解析为 `https://trace-gateway.example.com/v1/rum`。
250
223
 
251
224
  ## 为什么不建议多个实例同时运行?
252
225
 
@@ -1,2 +0,0 @@
1
- export declare const CLS_HISTOGRAM_BOUNDARIES: number[];
2
- export declare const DURATION_HISTOGRAM_BOUNDARIES: number[];
@@ -1,3 +0,0 @@
1
- import type { BkOTRuntimeContext } from './plugin';
2
- export type BkOTSignal = 'logs' | 'metrics' | 'traces';
3
- export declare const shouldRecordSignal: (context: BkOTRuntimeContext, signal: BkOTSignal) => boolean;
@@ -1,20 +0,0 @@
1
- /**
2
- * 简易 djb2 字符串 hash。结果稳定、短(base36),足以区分常见 fingerprint 字符串组合。
3
- * 不是密码学安全 hash,仅用于事件聚合分组场景。
4
- */
5
- export declare const hashString: (input: string) => string;
6
- export interface ThrottleResult {
7
- /** 是否允许本次上报 */
8
- allowed: boolean;
9
- /** 当前窗口内同 fingerprint 的触发序号(含本次) */
10
- count: number;
11
- }
12
- /**
13
- * 时间窗节流:同一 key 在 windowMs 窗口内最多允许 maxPerWindow 次通过;
14
- * 超出则被拦截,但 `count` 仍累加,供调用方维护内部统计。
15
- *
16
- * 长会话场景下避免 records 无限累积——按窗口长度节奏轻量清理一次过期 entry。
17
- */
18
- export declare const createThrottle: (windowMs: number, maxPerWindow: number) => {
19
- allow(key: string): ThrottleResult;
20
- };
@@ -1,15 +0,0 @@
1
- import type { BkOTRequestBodyConfig, BkOTRequestContext, BkOTRequestEvent } from '../core/config';
2
- import type { BkOTRuntimeContext } from '../core/plugin';
3
- import type { Span } from '@opentelemetry/api';
4
- interface CaptureRequestBodyLogOptions {
5
- bodyConfig: BkOTRequestBodyConfig;
6
- domainContext: BkOTRequestContext;
7
- event: BkOTRequestEvent;
8
- fetchRequest?: Request | RequestInit;
9
- occurredAt?: number;
10
- runtimeContext: Pick<BkOTRuntimeContext, 'emitLog'>;
11
- span: Span;
12
- }
13
- export declare const prepareFetchRequestBodySource: (request: Request | RequestInit) => Request | RequestInit | undefined;
14
- export declare const captureRequestBodyLog: ({ bodyConfig, domainContext, event, fetchRequest, occurredAt, runtimeContext, span, }: CaptureRequestBodyLogOptions) => Promise<void>;
15
- export {};