@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.
Files changed (46) hide show
  1. package/README.md +170 -554
  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 +34 -33
  33. package/skills/bk-rum-otele/evals/evals.json +1 -1
  34. package/skills/bk-rum-otele/references/api.md +45 -13
  35. package/skills/bk-rum-otele/references/concepts.md +38 -112
  36. package/skills/bk-rum-otele/references/configuration.md +135 -228
  37. package/skills/bk-rum-otele/references/custom-plugin.md +8 -5
  38. package/skills/bk-rum-otele/references/data-model.md +13 -8
  39. package/skills/bk-rum-otele/references/framework-integration.md +25 -17
  40. package/skills/bk-rum-otele/references/getting-started.md +27 -87
  41. package/skills/bk-rum-otele/references/plugins.md +165 -99
  42. package/skills/bk-rum-otele/references/privacy.md +42 -33
  43. package/skills/bk-rum-otele/references/telemetry-reference.md +73 -44
  44. package/skills/bk-rum-otele/references/troubleshooting.md +72 -38
  45. package/dist/plugins/http-body.d.ts +0 -3
  46. package/dist/plugins/route-timing.d.ts +0 -2
@@ -24,7 +24,7 @@
24
24
  import { BkOpenTelemetry } from '@blueking/open-telemetry';
25
25
 
26
26
  new BkOpenTelemetry({
27
- app: {
27
+ application: {
28
28
  name: 'bk-rum-demo',
29
29
  environment: 'production',
30
30
  version: '1.0.0',
@@ -36,144 +36,84 @@ new BkOpenTelemetry({
36
36
  });
37
37
  ```
38
38
 
39
- 默认情况下,SDK 会自动启动,并开启 documentLoad、fetch、xhr、userInteraction 以及 pageView、resource、error、webVitals、blankScreen、device、session 等基础 RUM 插件。
39
+ 默认情况下,SDK 会自动启动,建立 Session 和 View,并开启 request(内部组合 Fetch/XHR)、action、resource、error、webVitals、blankScreen、device 等基础采集能力。
40
40
 
41
41
  # 快速上手
42
42
 
43
- 本页从最小接入开始,逐步打开常用配置。所有示例都可以直接放在前端应用入口文件中,例如 `main.ts`、`bootstrap.ts` 或独立的 `bk-ot.ts`。
44
-
45
- ## 安装
43
+ ## 安装与初始化
46
44
 
47
45
  ```bash
48
46
  pnpm add @blueking/open-telemetry
49
47
  ```
50
48
 
51
- ## 最小接入
52
-
53
- ```ts
54
- import { BkOpenTelemetry } from '@blueking/open-telemetry';
55
-
56
- new BkOpenTelemetry({
57
- transport: {
58
- endpoint: 'https://rum-collector.example.com',
59
- token: 'report-token',
60
- },
61
- });
62
- ```
63
-
64
- 这段代码会使用默认应用名 `unknown_service`、默认环境 `production`,并自动启动 SDK。生产环境建议显式声明应用信息。
65
-
66
- ## 推荐生产配置
67
-
68
49
  ```ts
69
50
  import { BkOpenTelemetry } from '@blueking/open-telemetry';
70
51
 
71
- const bkOT = new BkOpenTelemetry({
72
- app: {
52
+ export const bkOT = new BkOpenTelemetry({
53
+ application: {
73
54
  name: 'bk-monitor-web',
74
55
  environment: 'production',
75
56
  version: '1.4.2',
76
57
  },
77
- user: {
78
- id: window.__BK_USER__?.id,
79
- },
80
58
  transport: {
81
59
  endpoint: 'https://rum-collector.example.com',
82
60
  token: window.__BK_RUM_TOKEN__,
83
61
  },
84
- sampling: {
85
- rate: 0.2,
86
- },
87
- route: {
88
- getPathGroup: url => new URL(url).pathname.replace(/\/\d+/g, '/:id'),
62
+ session: {
63
+ sampleRate: 0.2,
89
64
  },
90
- privacy: {
91
- redactUrl: url => url.replace(/([?&]token=)[^&]+/g, '$1***'),
92
- redactAttributes: attributes => {
93
- const next = { ...attributes };
94
- delete next['http.request.header.authorization'];
95
- return next;
65
+ tracking: {
66
+ view: {
67
+ getPathGroup: url => new URL(url).pathname.replace(/\/\d+/g, '/:id'),
96
68
  },
97
69
  },
70
+ context: {
71
+ user: { id: window.__BK_USER__?.id },
72
+ },
98
73
  });
99
-
100
- export default bkOT;
101
74
  ```
102
75
 
103
- ## 手动启动
76
+ `application.name` 与 `transport` 必填。通常提供根 `transport.endpoint`;如果所有已开启信号都有独立 endpoint,则可省略根地址。SDK 默认自动启动。
104
77
 
105
- 如果需要先注册自定义插件或 instrumentation,再启动 SDK,可以关闭 `autoStart`。
78
+ ## 手动启动与扩展
106
79
 
107
80
  ```ts
108
- import { BkOpenTelemetry, createPlugin } from '@blueking/open-telemetry';
109
-
110
81
  const bkOT = new BkOpenTelemetry({
82
+ application: { name: 'bk-rum-demo' },
111
83
  autoStart: false,
112
- app: { name: 'bk-rum-demo' },
113
84
  transport: { endpoint: 'https://rum-collector.example.com' },
85
+ extensions: { plugins: [bizReadyPlugin] },
114
86
  });
115
87
 
116
- bkOT.use(
117
- createPlugin({
118
- name: 'biz-ready',
119
- init(context) {
120
- const span = context.startSpan('custom.biz_ready', {
121
- 'biz.stage': 'bootstrap',
122
- });
123
- span.end();
124
- },
125
- }),
126
- );
127
-
128
88
  await bkOT.start();
129
89
  ```
130
90
 
131
- `use()` 和 `useInstrumentation()` 必须在 `start()` 之前调用。如果使用默认 `autoStart: true`,构造实例后会立即启动,不再允许追加插件。
91
+ `use()`、`useInstrumentation()` 和 `extensions` 注册都必须发生在 `start()` 前。
132
92
 
133
- ## CDN 接入
134
-
135
- 构建产物提供 `dist/bk-rum.global.js`,会在浏览器上暴露全局变量 `BkOpenTelemetry`。可通过 [unpkg](https://unpkg.com/@blueking/open-telemetry/) 或 [jsDelivr](https://cdn.jsdelivr.net/npm/@blueking/open-telemetry/) 直接引用,无需本地构建。
93
+ ## CDN
136
94
 
137
95
  ```html
138
- <!-- 最新版本 -->
139
96
  <script src="https://unpkg.com/@blueking/open-telemetry/dist/bk-rum.global.js"></script>
140
- <!-- 或锁定版本(推荐生产环境,将 <version> 替换为实际版本号,如 0.0.10) -->
141
- <!-- <script src="https://unpkg.com/@blueking/open-telemetry@<version>/dist/bk-rum.global.js"></script> -->
142
- <!-- jsDelivr 备选: -->
143
- <!-- <script src="https://cdn.jsdelivr.net/npm/@blueking/open-telemetry/dist/bk-rum.global.js"></script> -->
144
97
  <script>
145
- new window.BkOpenTelemetry({
146
- app: {
147
- name: 'legacy-web',
148
- environment: 'production',
149
- },
150
- transport: {
151
- endpoint: 'https://rum-collector.example.com',
152
- token: 'report-token',
153
- },
98
+ window.bkOT = new window.BkOpenTelemetry({
99
+ application: { name: 'legacy-web', environment: 'production' },
100
+ transport: { endpoint: 'https://rum-collector.example.com', token: 'report-token' },
154
101
  });
155
102
  </script>
156
103
  ```
157
104
 
158
- ## 手动上报业务事件
105
+ ## 手动事件
159
106
 
160
107
  ```ts
161
108
  bkOT.reportAction({
162
- type: 'click',
163
- targetTag: 'button',
164
- targetText: '提交订单',
165
- attributes: {
166
- 'biz.order_id': '202605270001',
167
- },
109
+ name: '提交订单',
110
+ attributes: { 'biz.order_id': '202607160001' },
168
111
  });
169
112
 
170
113
  bkOT.reportCustomEvent({
171
114
  name: 'checkout_success',
172
- attributes: {
173
- 'biz.amount': 99.9,
174
- 'biz.currency': 'CNY',
175
- },
115
+ attributes: { 'biz.amount': 99.9 },
176
116
  });
177
117
  ```
178
118
 
179
- 未命中采样时,`reportAction()` 和 `reportCustomEvent()` 会静默丢弃。调试阶段可以设置 `sampling.rate: 1` 和 `debug: true`。
119
+ 未命中 `session.sampleRate` 时,手动事件静默丢弃。