tdem-web-sdk 1.0.10 → 1.0.12
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 +141 -148
- package/lib/packages/core/src/index.d.ts +5 -1
- package/lib/packages/core/src/interface/config.d.ts +2 -0
- package/lib/packages/core/src/interface/event.d.ts +102 -2
- package/lib/packages/core/src/interface/index.d.ts +1 -1
- package/lib/packages/core/src/pipes/event-pipes.d.ts +6 -5
- package/lib/packages/core/src/pipes/index.d.ts +1 -1
- package/lib/packages/core/src/pipes/tdem-sample-gate.d.ts +6 -21
- package/lib/packages/core/src/sample/evaluate.d.ts +2 -0
- package/lib/packages/core/src/sample/eventTypes.d.ts +9 -0
- package/lib/packages/core/src/sample/resolve.d.ts +2 -0
- package/lib/packages/core/src/sample/types.d.ts +51 -0
- package/lib/packages/web-sdk/src/interface/index.d.ts +7 -6
- package/lib/packages/web-sdk/src/plugins/cgi-speed/hack-event-source.d.ts +5 -0
- package/lib/packages/web-sdk/src/plugins/cgi-speed/hack-http.d.ts +3 -0
- package/lib/packages/web-sdk/src/plugins/cgi-speed/sse-config.d.ts +4 -0
- package/lib/packages/web-sdk/src/plugins/cgi-speed/sse-observer.d.ts +56 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/constants.d.ts +13 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/event-buffer.d.ts +10 -2
- package/lib/packages/web-sdk/src/plugins/session-replay/replay-handoff.d.ts +20 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/replay-policy.d.ts +2 -2
- package/lib/packages/web-sdk/src/plugins/session-replay/uploader.d.ts +13 -5
- package/lib/packages/web-sdk/src/plugins/tdem-config.d.ts +1 -8
- package/lib/packages/web-sdk/src/tdem.d.ts +6 -1
- package/lib/packages/web-sdk/src/transport/browser-transport.d.ts +1 -1
- package/lib/tdem.f.min.js +3 -3
- package/lib/tdem.global.min.js +3 -3
- package/lib/tdem.ie.min.js +3 -3
- package/lib/tdem.min.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# tdem-web-sdk
|
|
2
2
|
|
|
3
|
-
TDEM
|
|
3
|
+
TDEM Web SDK 用于浏览器页面的体验采集,包括脚本错误、页面性能、Web Vitals,以及按需打开的接口、静态资源、点击、控制台、会话回放。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
当前只支持 npm 接入。
|
|
6
6
|
|
|
7
7
|
## 安装
|
|
8
8
|
|
|
@@ -10,199 +10,183 @@ TDEM 是腾讯云数字体验监控平台提供的前端监控 SDK,涵盖错
|
|
|
10
10
|
npm install tdem-web-sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
或通过 CDN 引入:
|
|
14
|
-
|
|
15
|
-
```html
|
|
16
|
-
<script src="https://tam.cdn-go.cn/tdem-sdk/latest/tdem.min.js"></script>
|
|
17
|
-
```
|
|
18
|
-
|
|
19
13
|
## 快速开始
|
|
20
14
|
|
|
15
|
+
在页面脚本里尽早创建实例。`id` 使用控制台里的项目 ID,`version` 使用业务版本号。
|
|
16
|
+
|
|
21
17
|
```javascript
|
|
22
18
|
import TDEM from 'tdem-web-sdk';
|
|
23
19
|
|
|
24
20
|
const tdem = new TDEM({
|
|
25
|
-
id: 'your-project-id',
|
|
26
|
-
url: 'https://dem.rumt-zh.com',
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
app_version: '2.0.0',
|
|
30
|
-
channel: 'web',
|
|
31
|
-
},
|
|
21
|
+
id: 'your-project-id',
|
|
22
|
+
url: 'https://dem.rumt-zh.com',
|
|
23
|
+
version: '1.2.3',
|
|
24
|
+
userId: 'user-123',
|
|
32
25
|
});
|
|
33
26
|
```
|
|
34
27
|
|
|
28
|
+
`url` 是采集域名,不要带 `/api/v1/...`。省略时使用 `https://dem.rumt-zh.com`。
|
|
29
|
+
|
|
30
|
+
省略 `version` 时,上报里的应用版本是字符串 `1.0.0`。
|
|
31
|
+
|
|
32
|
+
## 什么时候会有数据
|
|
33
|
+
|
|
34
|
+
创建实例后,SDK 会先请求 `POST {url}/api/v1/config`。控制台未打开采集、采样未命中,或这次请求失败且本地没有可用缓存时,后续插件不会启动,事件也不会发出。控制台会出现:
|
|
35
|
+
|
|
36
|
+
```text
|
|
37
|
+
[TDEM] SDK disabled by remote config, skip initialization
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
采集打开后,事件发送到 `POST {url}/api/v1/collect/events`。
|
|
41
|
+
|
|
42
|
+
打开页面后在 Network 里确认两件事:`config` 返回的 `enabled` 为真,以及随后有 `collect/events` 请求。
|
|
43
|
+
|
|
44
|
+
## 默认会采集什么
|
|
45
|
+
|
|
46
|
+
下面这些能力在创建实例后就会打开。某一项传 `false` 可以关掉。
|
|
47
|
+
|
|
48
|
+
| 配置 | 默认 | 采集内容 |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `onError` | 开 | JS 错误、未处理的 Promise rejection |
|
|
51
|
+
| `pagePerformance` | 开 | 页面加载性能 |
|
|
52
|
+
| `webVitals` | 开 | Web Vitals |
|
|
53
|
+
| `lagMonitor` | 开 | 主线程卡顿。依赖 Chromium 的 `long-animation-frame`,不支持时跳过 |
|
|
54
|
+
| `blankScreen` | 开 | 白屏。一次连续白屏只上报一次 |
|
|
55
|
+
| `memoryMonitor` | 开 | JS 堆。仅在浏览器提供 `performance.memory` 时运行 |
|
|
56
|
+
|
|
57
|
+
默认关闭,需要时再打开:
|
|
58
|
+
|
|
59
|
+
| 配置 | 打开方式 |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `spa` | `true` 后监听路由变化并上报 PV |
|
|
62
|
+
| `api` | `true` 或对象。同时采集普通 HTTP 和 SSE |
|
|
63
|
+
| `assets` | 静态资源 |
|
|
64
|
+
| `click` | 点击 |
|
|
65
|
+
| `console` | 控制台日志 |
|
|
66
|
+
| `bridge` | JSBridge |
|
|
67
|
+
| `websocket` | WebSocket |
|
|
68
|
+
| `sessionReplay` | 会话回放 |
|
|
69
|
+
| `struggleMonitor` | 挣扎行为,例如愤怒点击、无效点击 |
|
|
70
|
+
| `reportRetry` | 上报失败后的重试 |
|
|
71
|
+
|
|
35
72
|
## 初始化配置
|
|
36
73
|
|
|
37
|
-
| 参数 | 类型 |
|
|
38
|
-
|
|
39
|
-
| `id` | `string` |
|
|
40
|
-
| `url` | `string` |
|
|
41
|
-
| `
|
|
42
|
-
| `
|
|
43
|
-
| `env` | `string` |
|
|
44
|
-
| `
|
|
45
|
-
| `debug` | `boolean` |
|
|
46
|
-
| `
|
|
47
|
-
| `
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// ... 其他配置见 types.ts
|
|
72
|
-
}
|
|
74
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
75
|
+
| --- | --- | --- | --- |
|
|
76
|
+
| `id` | `string` | - | 项目 ID,对应请求里的 `project_key` |
|
|
77
|
+
| `url` | `string` | `https://dem.rumt-zh.com` | 采集域名 |
|
|
78
|
+
| `version` | `string \| number` | 上报为 `1.0.0` | 应用版本 |
|
|
79
|
+
| `userId` | `string` | - | 业务用户 |
|
|
80
|
+
| `env` | `string` | `production` | 见下方环境枚举。无法识别的值按 `others` 上报 |
|
|
81
|
+
| `defaultTags` | `Record<string, string>` | `{}` | 合并进每条事件的标签 |
|
|
82
|
+
| `debug` | `boolean` | `false` | 输出 SDK 诊断日志 |
|
|
83
|
+
| `delay` | `number` | `1000` | 事件合并上报的等待时间,单位毫秒 |
|
|
84
|
+
| `repeat` | `number` | `60` | 相同事件的重复上限 |
|
|
85
|
+
| `reportImmediately` | `boolean` | `true` | 是否立即上报 |
|
|
86
|
+
| `beforeReport` | `Function` | - | 返回 `false` 时丢弃这条事件 |
|
|
87
|
+
| `beforeRequest` | `Function` | - | 请求发出前 |
|
|
88
|
+
| `afterRequest` | `Function` | - | 请求完成后 |
|
|
89
|
+
|
|
90
|
+
`lagMonitor`、`blankScreen`、`memoryMonitor` 传对象时只覆盖写明的字段。卡顿默认超过 2000ms 上报,达到 5000ms 再记为无响应。白屏默认采样后按约 70% 空点判断,并在 2 秒后复检。
|
|
91
|
+
|
|
92
|
+
### 接口与 SSE
|
|
93
|
+
|
|
94
|
+
`api: false` 时,普通 HTTP 和 SSE 都不采集。`api: true` 或传入对象时,两者一起采集。SSE 覆盖 `EventSource`,以及响应 `Content-Type` 为 `text/event-stream` 的 fetch / XHR。同一次 SSE 连接只上报 `sse_call`,不会再报 `api_call`。SSE 不采集消息正文。
|
|
95
|
+
|
|
96
|
+
卡流阈值默认 60000ms:
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
new TDEM({
|
|
100
|
+
id: 'your-project-id',
|
|
101
|
+
url: 'https://dem.rumt-zh.com',
|
|
102
|
+
version: '1.2.3',
|
|
103
|
+
api: {
|
|
104
|
+
sseStallThresholdMs: 60000,
|
|
105
|
+
apiDetail: false,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
73
108
|
```
|
|
74
109
|
|
|
75
|
-
|
|
110
|
+
`apiDetail: true` 时会上报请求体,内容会被截断。需要按业务码判断失败时,提供 `retCodeHandler`,返回 `{ isErr, code }`。
|
|
111
|
+
|
|
112
|
+
### 会话回放
|
|
76
113
|
|
|
77
|
-
|
|
114
|
+
`sessionReplay` 省略或为 `false` 时不录制。设为 `true` 或对象后,还要同时满足控制台的采集开关和回放采样。
|
|
115
|
+
|
|
116
|
+
| 字段 | 默认 | 说明 |
|
|
78
117
|
| --- | --- | --- |
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
|
|
|
118
|
+
| `sessionSampleRate` | `0.1` | 体验流采样,范围 0 到 1。控制台的 `replay_sample_rate`(0 到 100)会覆盖它 |
|
|
119
|
+
| `errorTraceback` | `true` | 未抽中体验流时,是否允许在发生错误后补报这段回放 |
|
|
120
|
+
| `errorSampleRate` | `1` | 错误回溯的命中率,仅 `errorTraceback: true` 时有效 |
|
|
82
121
|
|
|
83
|
-
|
|
122
|
+
| 用法 | 配置 |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| 只在出错时回放 | `sessionSampleRate: 0`,保持 `errorTraceback: true` |
|
|
125
|
+
| 体验流和错误回放都要 | `sessionSampleRate` 大于 0,保持 `errorTraceback: true` |
|
|
126
|
+
| 只看抽中的体验流 | `errorTraceback: false` |
|
|
84
127
|
|
|
85
|
-
|
|
128
|
+
未抽中体验流且开了错误回溯时,SDK 先把录制放在内存里。这段访问没有错误,就不会因为页面关闭把回放发出去。
|
|
86
129
|
|
|
87
|
-
|
|
130
|
+
隐私默认遮罩页面文本和输入内容,密码框不录入。可以用这些标记补充:
|
|
131
|
+
|
|
132
|
+
- `.tdem-mask` 或 `data-tdem-mask`:遮罩
|
|
133
|
+
- `.tdem-block` 或 `data-tdem-block`:整块不录
|
|
134
|
+
|
|
135
|
+
也可以在 `sessionReplay.privacy` 里改 `maskAllText`、`maskAllInputs`,或追加 `mask` / `block` 选择器。
|
|
136
|
+
|
|
137
|
+
## 实例方法
|
|
88
138
|
|
|
89
139
|
```javascript
|
|
90
|
-
// 上报自定义事件
|
|
91
140
|
tdem.track('button_click', {
|
|
92
141
|
tags: { button_id: 'submit' },
|
|
93
142
|
properties: { page: '/checkout' },
|
|
94
143
|
});
|
|
95
|
-
```
|
|
96
144
|
|
|
97
|
-
|
|
145
|
+
tdem.trackStruggle('repeat_submit', {
|
|
146
|
+
severity: 'high',
|
|
147
|
+
tags: { step: 'pay' },
|
|
148
|
+
});
|
|
98
149
|
|
|
99
|
-
```javascript
|
|
100
|
-
// 直接上报耗时
|
|
101
150
|
tdem.measure('api_latency', 320, {
|
|
102
151
|
tags: { api: '/user/info' },
|
|
103
152
|
});
|
|
104
|
-
|
|
105
|
-
// 或使用计时器
|
|
106
153
|
tdem.startMeasure('render');
|
|
107
|
-
// ... 执行操作 ...
|
|
108
154
|
tdem.endMeasure('render');
|
|
109
|
-
```
|
|
110
155
|
|
|
111
|
-
### 日志上报
|
|
112
|
-
|
|
113
|
-
```javascript
|
|
114
|
-
// 上报消息
|
|
115
156
|
tdem.captureMessage('用户完成注册', {
|
|
116
157
|
level: 'info',
|
|
117
158
|
tags: { step: 'register' },
|
|
118
159
|
});
|
|
119
|
-
```
|
|
120
160
|
|
|
121
|
-
### 异常上报
|
|
122
|
-
|
|
123
|
-
```javascript
|
|
124
|
-
// 手动上报错误
|
|
125
161
|
try {
|
|
126
162
|
riskyOperation();
|
|
127
|
-
} catch (
|
|
128
|
-
tdem.captureException(
|
|
163
|
+
} catch (error) {
|
|
164
|
+
tdem.captureException(error, {
|
|
129
165
|
tags: { module: 'payment' },
|
|
130
166
|
});
|
|
131
167
|
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### 全局标签管理
|
|
135
|
-
|
|
136
|
-
```javascript
|
|
137
|
-
// 设置/追加标签
|
|
138
|
-
tdem.setTags({ role: 'admin', team: 'dev' });
|
|
139
|
-
|
|
140
|
-
// 移除指定标签
|
|
141
|
-
tdem.removeTags(['team']);
|
|
142
168
|
|
|
143
|
-
// 清空所有标签
|
|
144
|
-
tdem.clearTags();
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### 用户标识管理
|
|
148
|
-
|
|
149
|
-
```javascript
|
|
150
|
-
// 设置用户
|
|
151
169
|
tdem.setUser('user-456');
|
|
152
|
-
|
|
153
|
-
// 清除用户
|
|
154
170
|
tdem.clearUser();
|
|
155
|
-
```
|
|
156
171
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// 手动上报 PV
|
|
161
|
-
tdem.reportPageView('/checkout', {
|
|
162
|
-
pageTitle: '结算页',
|
|
163
|
-
});
|
|
172
|
+
tdem.setTags({ role: 'admin' });
|
|
173
|
+
tdem.removeTags(['role']);
|
|
174
|
+
tdem.clearTags();
|
|
164
175
|
|
|
165
|
-
|
|
176
|
+
tdem.reportPageView('/checkout', { pageTitle: '结算页' });
|
|
166
177
|
tdem.setPage('/modal/confirm', { pageTitle: '确认弹窗' });
|
|
167
|
-
// 弹窗关闭后恢复
|
|
168
178
|
tdem.leavePage();
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### 高级:原始事件上报
|
|
172
|
-
|
|
173
|
-
```javascript
|
|
174
|
-
// 直接上报 TDEMEvent 格式的事件
|
|
175
|
-
tdem.reportTDEMEvent({
|
|
176
|
-
event_id: 'evt_xxx',
|
|
177
|
-
event_type: 'custom',
|
|
178
|
-
event_category: 'custom',
|
|
179
|
-
timestamp: Date.now(),
|
|
180
|
-
page_url: location.href,
|
|
181
|
-
data: {
|
|
182
|
-
event_name: 'my_event',
|
|
183
|
-
tags: { key: 'value' },
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
```
|
|
187
179
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
```javascript
|
|
191
|
-
tdem.setConfig({
|
|
192
|
-
userId: 'new-user',
|
|
193
|
-
env: 'gray',
|
|
194
|
-
});
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### 销毁实例
|
|
198
|
-
|
|
199
|
-
```javascript
|
|
180
|
+
tdem.setConfig({ env: 'gray', version: '1.2.4' });
|
|
200
181
|
tdem.destroy();
|
|
201
182
|
```
|
|
202
183
|
|
|
184
|
+
`trackStruggle` 的 `severity` 为 `low`、`medium` 或 `high`,默认 `medium`。`captureMessage` 的 `level` 为 `info`、`warn` 或 `error`。`endMeasure` 找不到对应的 `startMeasure` 时会忽略。
|
|
185
|
+
|
|
203
186
|
## 协议说明
|
|
204
187
|
|
|
205
|
-
-
|
|
188
|
+
- 远程配置(Web 规则化采样权威):`POST {url}/api/v1/sample-config`(snake_case `event` / `replay.experience_sample_rate`)
|
|
189
|
+
- 旧配置(非 Web / 兼容):`POST {url}/api/v1/config`
|
|
206
190
|
- 事件上报:`POST {url}/api/v1/collect/events`
|
|
207
191
|
|
|
208
192
|
所有事件统一走 TDEM Event 协议,请求体结构:
|
|
@@ -237,14 +221,23 @@ tdem.destroy();
|
|
|
237
221
|
## 环境枚举
|
|
238
222
|
|
|
239
223
|
```javascript
|
|
240
|
-
TDEM.environment.production
|
|
241
|
-
TDEM.environment.
|
|
242
|
-
TDEM.environment.
|
|
243
|
-
TDEM.environment.
|
|
244
|
-
TDEM.environment.
|
|
245
|
-
TDEM.environment.
|
|
246
|
-
TDEM.environment.
|
|
247
|
-
|
|
224
|
+
TDEM.environment.production
|
|
225
|
+
TDEM.environment.development
|
|
226
|
+
TDEM.environment.gray
|
|
227
|
+
TDEM.environment.pre
|
|
228
|
+
TDEM.environment.daily
|
|
229
|
+
TDEM.environment.local
|
|
230
|
+
TDEM.environment.test
|
|
231
|
+
TDEM.environment.others
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## 看不到数据时
|
|
235
|
+
|
|
236
|
+
1. 确认 `id` 是控制台项目 ID,`url` 是采集域名。
|
|
237
|
+
2. 确认控制台已打开采集,并且采样率不是 0。
|
|
238
|
+
3. 看 Network 里的 `/api/v1/config`。失败且没有本地缓存时,这次访问不会上报。
|
|
239
|
+
4. 把 `debug` 设为 `true`,查看初始化日志。
|
|
240
|
+
5. 非 `production` 环境可能被控制台的默认筛选挡住,换环境条件再查。
|
|
248
241
|
|
|
249
242
|
## License
|
|
250
243
|
|
|
@@ -3,7 +3,11 @@ import Core from './core';
|
|
|
3
3
|
import Plugin from './plugin';
|
|
4
4
|
export { Plugin };
|
|
5
5
|
export default Core;
|
|
6
|
-
export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, Config, InternalConfig, CoreApiConfig, SendOption, SendSuccess, SendFail, SendType, Transport, TransportRequest, TransportResult, TransportCallbacks, TransportMethod, TransportBody, RetryDelayResolver, RetrySchedule, DEFAULT_TRANSPORT_RETRY_SCHEDULE, InternalSdkOptions, PlatTypeNum, NetworkTypeNum, PagePerformanceStruct, EventType, EventCategory, BaseEvent, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, WebVitalsEvent, LagEventMeasurements, LagEventProperties, LagEventData, LagDetectedEvent, NoResponseEvent, BlankScreenTriggerReason, BlankScreenTriggerType, BlankScreenDetectionMethod, BlankScreenMeasurements, BlankScreenEventProperties, BlankScreenEvent, MemoryEventMeasurements, WebMemoryEventMeasurements, AppMemoryEventMeasurements, WebMemoryEventData, AppMemoryEventData, MemoryEventData, MemoryUsageEvent, FileIoOperation, FileIoEventMeasurements, FileIoEventProperties, FileIoEventData, FileIoEvent, MemoryOOMEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, ScrollEvent, LongPressEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, StruggleSeverity, EventPropertyValue, EventProperties, ReportFormSubmitResultParams, EventOptions, TrackOptions, TrackStruggleOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './interface';
|
|
6
|
+
export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, Config, InternalConfig, CoreApiConfig, SendOption, SendSuccess, SendFail, SendType, Transport, TransportRequest, TransportResult, TransportCallbacks, TransportMethod, TransportBody, RetryDelayResolver, RetrySchedule, DEFAULT_TRANSPORT_RETRY_SCHEDULE, InternalSdkOptions, PlatTypeNum, NetworkTypeNum, PagePerformanceStruct, EventType, EventCategory, BaseEvent, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, SSECallOutcome, SSECallEvent, WebVitalsEvent, LagEventMeasurements, LagEventProperties, LagEventData, LagDetectedEvent, NoResponseEvent, BlankScreenTriggerReason, BlankScreenTriggerType, BlankScreenDetectionMethod, BlankScreenMeasurements, BlankScreenEventProperties, BlankScreenEvent, MemoryEventMeasurements, WebMemoryEventMeasurements, AppMemoryEventMeasurements, WebMemoryEventData, AppMemoryEventData, MemoryEventData, MemoryUsageEvent, ProcessSignalEventName, ProcessSignalEventProperties, ProcessSignalEventData, ProcessSignalEvent, AppMetricsEvent, FileIoOperation, FileIoEventMeasurements, FileIoEventProperties, FileIoEventData, FileIoEvent, MemoryOOMEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, ScrollEvent, LongPressEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, StruggleSeverity, EventPropertyValue, EventProperties, ReportFormSubmitResultParams, EventOptions, TrackOptions, TrackStruggleOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './interface';
|
|
7
7
|
export { getDefaultConfig, setConfigUrl, globalAny, REPORT_TIMEOUT, MAX_FROM_LENGTH, ERROR_MSG_IGNORE, URL_SPEED_IGNORE, RESOURCE_TYPE_FETCH, RESOURCE_TYPE_STATIC, UNKNOWN, RESOURCE_TYPE, MAX_PROMISE_ERROR_MSG_LENGTH, } from './constant';
|
|
8
8
|
export * from './pipes';
|
|
9
9
|
export * from './util';
|
|
10
|
+
export * from './sample/types';
|
|
11
|
+
export { evaluateEventSample } from './sample/evaluate';
|
|
12
|
+
export { resolveSampleConfig } from './sample/resolve';
|
|
13
|
+
export { WEB_SAMPLE_EVENT_TYPES, isWebSampleEventType } from './sample/eventTypes';
|
|
@@ -11,6 +11,8 @@ export declare type CoreApiConfig = {
|
|
|
11
11
|
resBodyHandler?: Function | undefined;
|
|
12
12
|
resHeaders?: Array<string>;
|
|
13
13
|
reqHeaders?: Array<string>;
|
|
14
|
+
/** SSE 卡流阈值(ms)。省略或非法值按 60000 解析;不是独立 SSE 开关。 */
|
|
15
|
+
sseStallThresholdMs?: number;
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
16
18
|
* TDEM SDK 对外公开的基础配置。
|
|
@@ -15,10 +15,13 @@ export declare enum EventType {
|
|
|
15
15
|
PAGE_LOAD = "page_load",
|
|
16
16
|
RESOURCE_LOAD = "resource_load",
|
|
17
17
|
API_CALL = "api_call",
|
|
18
|
+
SSE_CALL = "sse_call",
|
|
18
19
|
WEB_VITALS = "web_vitals",
|
|
19
20
|
LAG_DETECTED = "lag_detected",
|
|
20
21
|
NO_RESPONSE = "no_response",
|
|
21
22
|
MEMORY_USAGE = "memory_usage",
|
|
23
|
+
APP_METRICS = "app_metrics",
|
|
24
|
+
PROCESS_SIGNAL = "process_signal",
|
|
22
25
|
MEMORY_OOM = "memory_oom",
|
|
23
26
|
FILE_IO = "file_io",
|
|
24
27
|
CLICK = "click",
|
|
@@ -68,6 +71,7 @@ export interface BaseEvent {
|
|
|
68
71
|
event_category: EventCategory;
|
|
69
72
|
timestamp: number;
|
|
70
73
|
page_url: string;
|
|
74
|
+
view_id?: string;
|
|
71
75
|
data: Record<string, any>;
|
|
72
76
|
}
|
|
73
77
|
/**
|
|
@@ -78,6 +82,7 @@ export interface EventContext {
|
|
|
78
82
|
session_id: string;
|
|
79
83
|
user_id?: string;
|
|
80
84
|
platform: string;
|
|
85
|
+
view_id?: string;
|
|
81
86
|
runtime?: string;
|
|
82
87
|
process_type?: string;
|
|
83
88
|
window_id?: string;
|
|
@@ -86,6 +91,7 @@ export interface EventContext {
|
|
|
86
91
|
user_agent?: string;
|
|
87
92
|
screen_resolution?: string;
|
|
88
93
|
language?: string;
|
|
94
|
+
device_id?: string;
|
|
89
95
|
}
|
|
90
96
|
/**
|
|
91
97
|
* SDK 和应用信息
|
|
@@ -281,6 +287,56 @@ export interface APICallEvent extends BaseEvent {
|
|
|
281
287
|
};
|
|
282
288
|
};
|
|
283
289
|
}
|
|
290
|
+
export declare type SSECallOutcome = 'success' | 'http_error' | 'transport_error' | 'cancelled' | 'stalled';
|
|
291
|
+
/**
|
|
292
|
+
* SSE 连接事件(Web / Electron renderer / Electron main)
|
|
293
|
+
* 对齐 Android/iOS sse_call:每条必带 measurements.stall_threshold_ms;禁止 stream_duration。
|
|
294
|
+
*/
|
|
295
|
+
export interface SSECallEvent extends BaseEvent {
|
|
296
|
+
event_type: EventType.SSE_CALL;
|
|
297
|
+
event_category: EventCategory.NETWORK;
|
|
298
|
+
data: {
|
|
299
|
+
url: string;
|
|
300
|
+
resource_type: 'sse';
|
|
301
|
+
measurements: {
|
|
302
|
+
duration: number;
|
|
303
|
+
redirect_count: number;
|
|
304
|
+
message_count: number;
|
|
305
|
+
stall_threshold_ms: number;
|
|
306
|
+
gap_lt_500_count: number;
|
|
307
|
+
gap_500_999_count: number;
|
|
308
|
+
gap_1000_2999_count: number;
|
|
309
|
+
gap_3000_9999_count: number;
|
|
310
|
+
gap_10000_59999_count: number;
|
|
311
|
+
gap_ge_60000_count: number;
|
|
312
|
+
time_to_first_message?: number;
|
|
313
|
+
last_message_offset?: number;
|
|
314
|
+
max_message_gap?: number;
|
|
315
|
+
dns_time?: number;
|
|
316
|
+
tcp_time?: number;
|
|
317
|
+
ssl_time?: number;
|
|
318
|
+
request_time?: number;
|
|
319
|
+
ttfb?: number;
|
|
320
|
+
response_time?: number;
|
|
321
|
+
bytes_sent?: number;
|
|
322
|
+
bytes_received?: number;
|
|
323
|
+
};
|
|
324
|
+
replay_id?: string;
|
|
325
|
+
tags?: Record<string, string>;
|
|
326
|
+
event_properties: {
|
|
327
|
+
http_method: string;
|
|
328
|
+
outcome: SSECallOutcome;
|
|
329
|
+
http_status?: string;
|
|
330
|
+
error_domain?: string;
|
|
331
|
+
error_code?: string;
|
|
332
|
+
error_category?: string;
|
|
333
|
+
original_url?: string;
|
|
334
|
+
request_headers?: string;
|
|
335
|
+
response_headers?: string;
|
|
336
|
+
replay_offset_ms?: string;
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
}
|
|
284
340
|
/**
|
|
285
341
|
* Web Vitals 性能事件
|
|
286
342
|
*/
|
|
@@ -374,6 +430,15 @@ export interface AppMemoryEventMeasurements {
|
|
|
374
430
|
app_memory: number;
|
|
375
431
|
memory_size: number;
|
|
376
432
|
free_memory: number;
|
|
433
|
+
main_memory?: number;
|
|
434
|
+
renderer_memory?: number;
|
|
435
|
+
gpu_memory?: number;
|
|
436
|
+
utility_memory?: number;
|
|
437
|
+
app_cpu?: number;
|
|
438
|
+
main_cpu?: number;
|
|
439
|
+
renderer_cpu?: number;
|
|
440
|
+
gpu_cpu?: number;
|
|
441
|
+
utility_cpu?: number;
|
|
377
442
|
}
|
|
378
443
|
export interface WebMemoryEventData {
|
|
379
444
|
measurements: WebMemoryEventMeasurements;
|
|
@@ -387,6 +452,7 @@ export interface AppMemoryEventData {
|
|
|
387
452
|
measurements: AppMemoryEventMeasurements;
|
|
388
453
|
event_properties: {
|
|
389
454
|
detection_source: 'app_metrics';
|
|
455
|
+
renderer_count?: string;
|
|
390
456
|
};
|
|
391
457
|
replay_id?: string;
|
|
392
458
|
tags?: Record<string, string>;
|
|
@@ -397,6 +463,40 @@ export interface MemoryUsageEvent extends BaseEvent {
|
|
|
397
463
|
event_category: EventCategory.PERFORMANCE;
|
|
398
464
|
data: MemoryEventData;
|
|
399
465
|
}
|
|
466
|
+
export declare type ProcessSignalEventName = 'render_process_gone' | 'child_process_gone' | 'unresponsive' | 'responsive';
|
|
467
|
+
export interface ProcessSignalEventProperties {
|
|
468
|
+
process_type: string;
|
|
469
|
+
process_role?: string;
|
|
470
|
+
window_id?: string;
|
|
471
|
+
web_contents_id?: string;
|
|
472
|
+
exit_reason?: string;
|
|
473
|
+
exit_code?: string;
|
|
474
|
+
service_name?: string;
|
|
475
|
+
repeat_count?: string;
|
|
476
|
+
}
|
|
477
|
+
export interface ProcessSignalEventData {
|
|
478
|
+
event_name: ProcessSignalEventName;
|
|
479
|
+
event_properties: ProcessSignalEventProperties;
|
|
480
|
+
measurements?: {
|
|
481
|
+
duration?: number;
|
|
482
|
+
app_memory?: number;
|
|
483
|
+
memory_size?: number;
|
|
484
|
+
free_memory?: number;
|
|
485
|
+
};
|
|
486
|
+
replay_id?: string;
|
|
487
|
+
tags?: Record<string, string>;
|
|
488
|
+
}
|
|
489
|
+
export interface ProcessSignalEvent extends BaseEvent {
|
|
490
|
+
event_type: EventType.PROCESS_SIGNAL;
|
|
491
|
+
event_category: EventCategory.PERFORMANCE;
|
|
492
|
+
event_name: ProcessSignalEventName;
|
|
493
|
+
data: ProcessSignalEventData;
|
|
494
|
+
}
|
|
495
|
+
export interface AppMetricsEvent extends BaseEvent {
|
|
496
|
+
event_type: EventType.APP_METRICS;
|
|
497
|
+
event_category: EventCategory.PERFORMANCE;
|
|
498
|
+
data: AppMemoryEventData;
|
|
499
|
+
}
|
|
400
500
|
export declare type FileIoOperation = 'read' | 'write' | 'open';
|
|
401
501
|
export interface FileIoEventMeasurements {
|
|
402
502
|
duration: number;
|
|
@@ -405,7 +505,7 @@ export interface FileIoEventMeasurements {
|
|
|
405
505
|
export interface FileIoEventProperties {
|
|
406
506
|
operation: FileIoOperation;
|
|
407
507
|
success: string;
|
|
408
|
-
process_type
|
|
508
|
+
process_type?: 'main' | 'renderer';
|
|
409
509
|
path?: string;
|
|
410
510
|
path_missing?: string;
|
|
411
511
|
}
|
|
@@ -629,7 +729,7 @@ export interface LogEvent extends BaseEvent {
|
|
|
629
729
|
/**
|
|
630
730
|
* 所有事件的联合类型
|
|
631
731
|
*/
|
|
632
|
-
export declare type TDEMEvent = JSErrorEvent | PromiseErrorEvent | ResourceErrorEvent | APIErrorEvent | PageLoadEvent | ResourceLoadEvent | APICallEvent | WebVitalsEvent | LagDetectedEvent | NoResponseEvent | BlankScreenEvent | MemoryUsageEvent | MemoryOOMEvent | FileIoEvent | ClickEvent | ScrollEvent | LongPressEvent | PageViewEvent | LifecycleEvent | FormFocusEvent | FormBlurEvent | FormChangeEvent | FormSubmitEvent | FormSubmitResultEvent | StruggleEvent | CustomEvent | CustomTimeEvent | LogEvent;
|
|
732
|
+
export declare type TDEMEvent = JSErrorEvent | PromiseErrorEvent | ResourceErrorEvent | APIErrorEvent | PageLoadEvent | ResourceLoadEvent | APICallEvent | SSECallEvent | WebVitalsEvent | LagDetectedEvent | NoResponseEvent | BlankScreenEvent | MemoryUsageEvent | AppMetricsEvent | ProcessSignalEvent | MemoryOOMEvent | FileIoEvent | ClickEvent | ScrollEvent | LongPressEvent | PageViewEvent | LifecycleEvent | FormFocusEvent | FormBlurEvent | FormChangeEvent | FormSubmitEvent | FormSubmitResultEvent | StruggleEvent | CustomEvent | CustomTimeEvent | LogEvent;
|
|
633
733
|
/** @internal Protocol-level input used by automatic struggle detectors. */
|
|
634
734
|
export interface ReportStruggleParams {
|
|
635
735
|
type: StruggleEventName;
|
|
@@ -3,4 +3,4 @@ export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerforman
|
|
|
3
3
|
export { SendOption, SendSuccess, SendFail, SendType, } from './send';
|
|
4
4
|
export { Transport, TransportRequest, TransportResult, TransportCallbacks, TransportMethod, TransportBody, RetryDelayResolver, RetrySchedule, DEFAULT_TRANSPORT_RETRY_SCHEDULE, InternalSdkOptions, } from './transport';
|
|
5
5
|
export { Environment, } from './env';
|
|
6
|
-
export { EventType, EventCategory, BaseEvent, EventContext, SDKInfo, AppInfo, CollectEventsRequest, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, WebVitalsEvent, LagEventMeasurements, LagEventProperties, LagEventData, LagDetectedEvent, NoResponseEvent, BlankScreenTriggerReason, BlankScreenTriggerType, BlankScreenDetectionMethod, BlankScreenMeasurements, BlankScreenEventProperties, BlankScreenEvent, MemoryEventMeasurements, WebMemoryEventMeasurements, AppMemoryEventMeasurements, WebMemoryEventData, AppMemoryEventData, MemoryEventData, MemoryUsageEvent, FileIoOperation, FileIoEventMeasurements, FileIoEventProperties, FileIoEventData, FileIoEvent, MemoryOOMEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, ScrollEvent, LongPressEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, StruggleSeverity, EventPropertyValue, EventProperties, ReportFormSubmitResultParams, EventOptions, TrackOptions, TrackStruggleOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './event';
|
|
6
|
+
export { EventType, EventCategory, BaseEvent, EventContext, SDKInfo, AppInfo, CollectEventsRequest, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, SSECallOutcome, SSECallEvent, WebVitalsEvent, LagEventMeasurements, LagEventProperties, LagEventData, LagDetectedEvent, NoResponseEvent, BlankScreenTriggerReason, BlankScreenTriggerType, BlankScreenDetectionMethod, BlankScreenMeasurements, BlankScreenEventProperties, BlankScreenEvent, MemoryEventMeasurements, WebMemoryEventMeasurements, AppMemoryEventMeasurements, WebMemoryEventData, AppMemoryEventData, MemoryEventData, MemoryUsageEvent, ProcessSignalEventName, ProcessSignalEventProperties, ProcessSignalEventData, ProcessSignalEvent, AppMetricsEvent, FileIoOperation, FileIoEventMeasurements, FileIoEventProperties, FileIoEventData, FileIoEvent, MemoryOOMEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, ScrollEvent, LongPressEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, StruggleSeverity, EventPropertyValue, EventProperties, ReportFormSubmitResultParams, EventOptions, TrackOptions, TrackStruggleOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './event';
|
|
@@ -4,17 +4,18 @@
|
|
|
4
4
|
import { TDEMEvent } from '../interface/event';
|
|
5
5
|
import { Pipe } from './index';
|
|
6
6
|
import Core from '../core';
|
|
7
|
-
/**
|
|
8
|
-
* 事件节流管道
|
|
9
|
-
* @param tdem - Core 实例
|
|
10
|
-
* @param maxCount - 最大批量数量
|
|
11
|
-
*/
|
|
12
7
|
export declare function createEventThrottlePipe(tdem: Core, maxCount: number): Pipe<TDEMEvent | TDEMEvent[], TDEMEvent[]>;
|
|
13
8
|
/**
|
|
14
9
|
* 事件过滤管道 - 调用用户的 beforeReport 钩子
|
|
15
10
|
* @param tdem - Core 实例
|
|
16
11
|
*/
|
|
17
12
|
export declare function createEventFilterPipe(tdem: Core): Pipe<TDEMEvent[], TDEMEvent[]>;
|
|
13
|
+
/**
|
|
14
|
+
* 构建公共上下文信息
|
|
15
|
+
* @param tdem - Core 实例
|
|
16
|
+
*/
|
|
17
|
+
export declare function normalizePlatform(rawPlatform: string): string;
|
|
18
|
+
export declare function readInstanceViewId(tdem: Core): string;
|
|
18
19
|
/**
|
|
19
20
|
* 上报管道 - 构建新版协议请求体并上报
|
|
20
21
|
* @param tdem - Core 实例
|
|
@@ -8,7 +8,7 @@ export { modifyRequestHooks } from '../hooks/modifyRequestHooks';
|
|
|
8
8
|
export { afterRequestHooks } from '../hooks/afterRequestHooks';
|
|
9
9
|
export * from './trace';
|
|
10
10
|
export { createEventThrottlePipe, createEventFilterPipe, createEventReportPipe, } from './event-pipes';
|
|
11
|
-
export { createTDEMSampleGatePipe } from './tdem-sample-gate';
|
|
11
|
+
export { createTDEMSampleGatePipe, isTDEMCollectionActive } from './tdem-sample-gate';
|
|
12
12
|
export type { TDEMSampleGate } from './tdem-sample-gate';
|
|
13
13
|
export declare type Pipe<M = any, N = any> = (msg: M, resolve: Resolve<N>) => void;
|
|
14
14
|
export declare type Resolve<M> = (msg: M) => void;
|
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TDEM
|
|
2
|
+
* TDEM 采样闸门管道
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* - 保证一个 Session 要么全部上报,要么全部不上报
|
|
7
|
-
* - 支持 Session 续期时重新决策(reDecide)
|
|
4
|
+
* Web:若实例上挂了 `_tdemSampleConfig`(规则化文档),按事件独立抽签。
|
|
5
|
+
* 其它端:保持 Session 全有/全无闸门。
|
|
8
6
|
*/
|
|
9
7
|
import { Pipe } from './index';
|
|
10
8
|
import { TDEMEvent } from '../interface/event';
|
|
11
9
|
import Core from '../core';
|
|
12
|
-
/** 采样闸门控制接口 */
|
|
13
10
|
export interface TDEMSampleGate {
|
|
14
|
-
/** 标记采样决策结果,释放闸门 */
|
|
15
11
|
decide(isSampled: boolean): void;
|
|
16
|
-
/**
|
|
17
|
-
* Session 续期时重新决策
|
|
18
|
-
* 使用缓存的采样率重新摇骰子,决定新 Session 是否继续上报
|
|
19
|
-
* @param sampleRate 采样率 (0~100)
|
|
20
|
-
* @returns 新的采样结果
|
|
21
|
-
*/
|
|
22
12
|
reDecide(sampleRate: number): boolean;
|
|
23
|
-
/** 是否已完成采样决策 */
|
|
24
13
|
readonly isDecided: boolean;
|
|
25
|
-
/** 是否被采样命中 */
|
|
26
14
|
readonly isSampled: boolean;
|
|
27
15
|
}
|
|
28
16
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* 该管道放在 tdemEventPipeline 的入口:
|
|
32
|
-
* - 采样决策未完成 → 暂存事件到队列
|
|
33
|
-
* - 采样命中 → 释放所有暂存事件,后续事件正常放行
|
|
34
|
-
* - 采样未命中 → 丢弃所有暂存事件,后续事件静默丢弃
|
|
17
|
+
* 远程配置已放行且本 Session 采样命中。
|
|
18
|
+
* 决策前、远程关闭或未命中时都为 false,此时不得改写业务请求的追踪头。
|
|
35
19
|
*/
|
|
20
|
+
export declare function isTDEMCollectionActive(tdem: unknown): boolean;
|
|
36
21
|
export declare function createTDEMSampleGatePipe(tdem: Core): Pipe<TDEMEvent | TDEMEvent[], TDEMEvent | TDEMEvent[]>;
|