@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
|
@@ -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
|
|
|
@@ -18,13 +18,15 @@
|
|
|
18
18
|
3. `schema`:负责 RUM 字段、span 类型、结果、耗时分桶等归一化模型。
|
|
19
19
|
4. `browser` / `index`:分别提供 CDN 全局入口(`https://unpkg.com/@blueking/open-telemetry/dist/bk-rum.global.js`)和 ESM 模块入口(`@blueking/open-telemetry`)。
|
|
20
20
|
|
|
21
|
+
完整能力、默认开关与信号产出见[能力矩阵](./capabilities.md),初始化顺序、上下文和导出过滤见[架构与数据流](./architecture.md)。
|
|
22
|
+
|
|
21
23
|
## 最小示例
|
|
22
24
|
|
|
23
25
|
```ts
|
|
24
26
|
import { BkOpenTelemetry } from '@blueking/open-telemetry';
|
|
25
27
|
|
|
26
28
|
new BkOpenTelemetry({
|
|
27
|
-
|
|
29
|
+
application: {
|
|
28
30
|
name: 'bk-rum-demo',
|
|
29
31
|
environment: 'production',
|
|
30
32
|
version: '1.0.0',
|
|
@@ -36,144 +38,98 @@ new BkOpenTelemetry({
|
|
|
36
38
|
});
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
默认情况下,SDK
|
|
41
|
+
默认情况下,SDK 会自动启动,建立 Session 和 View,并开启 request(内部组合 Fetch/XHR)、action、resource、error、webVitals、blankScreen、device 等基础采集能力。
|
|
40
42
|
|
|
41
43
|
# 快速上手
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
## 安装
|
|
45
|
+
## 安装与初始化
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
48
|
pnpm add @blueking/open-telemetry
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
## 最小接入
|
|
52
|
-
|
|
53
51
|
```ts
|
|
54
52
|
import { BkOpenTelemetry } from '@blueking/open-telemetry';
|
|
55
53
|
|
|
56
|
-
new BkOpenTelemetry({
|
|
57
|
-
|
|
58
|
-
endpoint: 'https://rum-collector.example.com',
|
|
59
|
-
token: 'report-token',
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
这段代码会使用默认应用名 `unknown_service`、默认环境 `production`,并自动启动 SDK。生产环境建议显式声明应用信息。
|
|
65
|
-
|
|
66
|
-
## 推荐生产配置
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
import { BkOpenTelemetry } from '@blueking/open-telemetry';
|
|
70
|
-
|
|
71
|
-
const bkOT = new BkOpenTelemetry({
|
|
72
|
-
app: {
|
|
54
|
+
export const bkOT = new BkOpenTelemetry({
|
|
55
|
+
application: {
|
|
73
56
|
name: 'bk-monitor-web',
|
|
74
57
|
environment: 'production',
|
|
75
58
|
version: '1.4.2',
|
|
76
59
|
},
|
|
77
|
-
user: {
|
|
78
|
-
id: window.__BK_USER__?.id,
|
|
79
|
-
},
|
|
80
60
|
transport: {
|
|
81
61
|
endpoint: 'https://rum-collector.example.com',
|
|
82
62
|
token: window.__BK_RUM_TOKEN__,
|
|
83
63
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
route: {
|
|
88
|
-
getPathGroup: url => new URL(url).pathname.replace(/\/\d+/g, '/:id'),
|
|
64
|
+
session: {
|
|
65
|
+
sampleRate: 0.2,
|
|
89
66
|
},
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const next = { ...attributes };
|
|
94
|
-
delete next['http.request.header.authorization'];
|
|
95
|
-
return next;
|
|
67
|
+
tracking: {
|
|
68
|
+
view: {
|
|
69
|
+
getPathGroup: url => new URL(url).pathname.replace(/\/\d+/g, '/:id'),
|
|
96
70
|
},
|
|
97
71
|
},
|
|
72
|
+
context: {
|
|
73
|
+
user: { id: window.__BK_USER__?.id },
|
|
74
|
+
},
|
|
98
75
|
});
|
|
99
|
-
|
|
100
|
-
export default bkOT;
|
|
101
76
|
```
|
|
102
77
|
|
|
103
|
-
|
|
78
|
+
`application.name` 与 `transport` 必填。通常提供根 `transport.endpoint`;如果所有已开启信号都有独立 endpoint,则可省略根地址。SDK 默认自动启动。
|
|
104
79
|
|
|
105
|
-
|
|
80
|
+
## 手动启动与扩展
|
|
106
81
|
|
|
107
82
|
```ts
|
|
108
|
-
import { BkOpenTelemetry, createPlugin } from '@blueking/open-telemetry';
|
|
109
|
-
|
|
110
83
|
const bkOT = new BkOpenTelemetry({
|
|
84
|
+
application: { name: 'bk-rum-demo' },
|
|
111
85
|
autoStart: false,
|
|
112
|
-
app: { name: 'bk-rum-demo' },
|
|
113
86
|
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
87
|
+
extensions: { plugins: [bizReadyPlugin] },
|
|
114
88
|
});
|
|
115
89
|
|
|
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
90
|
await bkOT.start();
|
|
129
91
|
```
|
|
130
92
|
|
|
131
|
-
`use()` 和 `
|
|
93
|
+
`use()`、`useInstrumentation()` 和 `extensions` 注册都必须发生在 `start()` 前。
|
|
94
|
+
|
|
95
|
+
手动 View 也应在 `await start()` 建立 Session 后创建:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const bkOT = new BkOpenTelemetry({
|
|
99
|
+
application: { name: 'manual-view-demo' },
|
|
100
|
+
autoStart: false,
|
|
101
|
+
transport: { endpoint: 'https://rum-collector.example.com' },
|
|
102
|
+
tracking: { view: { tracking: 'manual' } },
|
|
103
|
+
});
|
|
132
104
|
|
|
133
|
-
|
|
105
|
+
await bkOT.start();
|
|
106
|
+
bkOT.startView({ name: '订单详情', url: location.href });
|
|
107
|
+
```
|
|
134
108
|
|
|
135
|
-
|
|
109
|
+
## CDN
|
|
136
110
|
|
|
137
111
|
```html
|
|
138
|
-
<!-- 最新版本 -->
|
|
139
112
|
<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
113
|
<script>
|
|
145
|
-
new window.BkOpenTelemetry({
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
environment: 'production',
|
|
149
|
-
},
|
|
150
|
-
transport: {
|
|
151
|
-
endpoint: 'https://rum-collector.example.com',
|
|
152
|
-
token: 'report-token',
|
|
153
|
-
},
|
|
114
|
+
window.bkOT = new window.BkOpenTelemetry({
|
|
115
|
+
application: { name: 'legacy-web', environment: 'production' },
|
|
116
|
+
transport: { endpoint: 'https://rum-collector.example.com', token: 'report-token' },
|
|
154
117
|
});
|
|
155
118
|
</script>
|
|
156
119
|
```
|
|
157
120
|
|
|
158
|
-
##
|
|
121
|
+
## 手动事件
|
|
159
122
|
|
|
160
123
|
```ts
|
|
161
124
|
bkOT.reportAction({
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
targetText: '提交订单',
|
|
165
|
-
attributes: {
|
|
166
|
-
'biz.order_id': '202605270001',
|
|
167
|
-
},
|
|
125
|
+
name: '提交订单',
|
|
126
|
+
attributes: { 'biz.order_id': '202607160001' },
|
|
168
127
|
});
|
|
169
128
|
|
|
170
129
|
bkOT.reportCustomEvent({
|
|
171
130
|
name: 'checkout_success',
|
|
172
|
-
attributes: {
|
|
173
|
-
'biz.amount': 99.9,
|
|
174
|
-
'biz.currency': 'CNY',
|
|
175
|
-
},
|
|
131
|
+
attributes: { 'biz.amount': 99.9 },
|
|
176
132
|
});
|
|
177
133
|
```
|
|
178
134
|
|
|
179
|
-
|
|
135
|
+
未命中 `session.sampleRate` 时,手动事件静默丢弃。
|