tdem-web-sdk 1.0.10 → 1.0.11
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 +138 -180
- package/lib/packages/core/src/index.d.ts +1 -1
- package/lib/packages/core/src/interface/config.d.ts +2 -0
- package/lib/packages/core/src/interface/event.d.ts +100 -2
- package/lib/packages/core/src/interface/index.d.ts +1 -1
- package/lib/packages/core/src/pipes/index.d.ts +1 -1
- package/lib/packages/core/src/pipes/tdem-sample-gate.d.ts +5 -0
- package/lib/packages/web-sdk/src/interface/index.d.ts +2 -0
- 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/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,241 +10,199 @@ 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
|
+
### 会话回放
|
|
113
|
+
|
|
114
|
+
`sessionReplay` 省略或为 `false` 时不录制。设为 `true` 或对象后,还要同时满足控制台的采集开关和回放采样。
|
|
76
115
|
|
|
77
|
-
|
|
|
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 先把录制放在内存里。这段访问没有错误,就不会因为页面关闭把回放发出去。
|
|
129
|
+
|
|
130
|
+
隐私默认遮罩页面文本和输入内容,密码框不录入。可以用这些标记补充:
|
|
86
131
|
|
|
87
|
-
|
|
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
|
-
|
|
111
|
-
### 日志上报
|
|
112
155
|
|
|
113
|
-
```javascript
|
|
114
|
-
// 上报消息
|
|
115
156
|
tdem.captureMessage('用户完成注册', {
|
|
116
157
|
level: 'info',
|
|
117
158
|
tags: { step: 'register' },
|
|
118
159
|
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### 异常上报
|
|
122
160
|
|
|
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
168
|
|
|
134
|
-
### 全局标签管理
|
|
135
|
-
|
|
136
|
-
```javascript
|
|
137
|
-
// 设置/追加标签
|
|
138
|
-
tdem.setTags({ role: 'admin', team: 'dev' });
|
|
139
|
-
|
|
140
|
-
// 移除指定标签
|
|
141
|
-
tdem.removeTags(['team']);
|
|
142
|
-
|
|
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
|
-
|
|
157
|
-
### 页面管理
|
|
158
171
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
tdem.
|
|
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
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
- 远程配置:`POST {url}/api/v1/config`
|
|
206
|
-
- 事件上报:`POST {url}/api/v1/collect/events`
|
|
207
|
-
|
|
208
|
-
所有事件统一走 TDEM Event 协议,请求体结构:
|
|
209
|
-
|
|
210
|
-
```json
|
|
211
|
-
{
|
|
212
|
-
"protocol_version": 2,
|
|
213
|
-
"project_key": "your-project-id",
|
|
214
|
-
"sdk": { "name": "tdem-web-sdk", "version": "x.x.x" },
|
|
215
|
-
"app": { "version": "1.0.0" },
|
|
216
|
-
"context": {
|
|
217
|
-
"session_id": "...",
|
|
218
|
-
"user_id": "...",
|
|
219
|
-
"platform": "web",
|
|
220
|
-
"user_agent": "...",
|
|
221
|
-
"screen_resolution": "1920x1080",
|
|
222
|
-
"language": "zh-CN"
|
|
223
|
-
},
|
|
224
|
-
"events": [
|
|
225
|
-
{
|
|
226
|
-
"event_id": "evt_xxx",
|
|
227
|
-
"event_type": "js_error",
|
|
228
|
-
"event_category": "error",
|
|
229
|
-
"timestamp": 1713800000000,
|
|
230
|
-
"page_url": "https://example.com/page",
|
|
231
|
-
"data": { ... }
|
|
232
|
-
}
|
|
233
|
-
]
|
|
234
|
-
}
|
|
235
|
-
```
|
|
184
|
+
`trackStruggle` 的 `severity` 为 `low`、`medium` 或 `high`,默认 `medium`。`captureMessage` 的 `level` 为 `info`、`warn` 或 `error`。`endMeasure` 找不到对应的 `startMeasure` 时会忽略。
|
|
236
185
|
|
|
237
186
|
## 环境枚举
|
|
238
187
|
|
|
239
188
|
```javascript
|
|
240
|
-
TDEM.environment.production
|
|
241
|
-
TDEM.environment.
|
|
242
|
-
TDEM.environment.
|
|
243
|
-
TDEM.environment.
|
|
244
|
-
TDEM.environment.
|
|
245
|
-
TDEM.environment.
|
|
246
|
-
TDEM.environment.
|
|
247
|
-
|
|
189
|
+
TDEM.environment.production
|
|
190
|
+
TDEM.environment.development
|
|
191
|
+
TDEM.environment.gray
|
|
192
|
+
TDEM.environment.pre
|
|
193
|
+
TDEM.environment.daily
|
|
194
|
+
TDEM.environment.local
|
|
195
|
+
TDEM.environment.test
|
|
196
|
+
TDEM.environment.others
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## 看不到数据时
|
|
200
|
+
|
|
201
|
+
1. 确认 `id` 是控制台项目 ID,`url` 是采集域名。
|
|
202
|
+
2. 确认控制台已打开采集,并且采样率不是 0。
|
|
203
|
+
3. 看 Network 里的 `/api/v1/config`。失败且没有本地缓存时,这次访问不会上报。
|
|
204
|
+
4. 把 `debug` 设为 `true`,查看初始化日志。
|
|
205
|
+
5. 非 `production` 环境可能被控制台的默认筛选挡住,换环境条件再查。
|
|
248
206
|
|
|
249
207
|
## License
|
|
250
208
|
|
|
@@ -3,7 +3,7 @@ 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';
|
|
@@ -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",
|
|
@@ -86,6 +89,7 @@ export interface EventContext {
|
|
|
86
89
|
user_agent?: string;
|
|
87
90
|
screen_resolution?: string;
|
|
88
91
|
language?: string;
|
|
92
|
+
device_id?: string;
|
|
89
93
|
}
|
|
90
94
|
/**
|
|
91
95
|
* SDK 和应用信息
|
|
@@ -281,6 +285,56 @@ export interface APICallEvent extends BaseEvent {
|
|
|
281
285
|
};
|
|
282
286
|
};
|
|
283
287
|
}
|
|
288
|
+
export declare type SSECallOutcome = 'success' | 'http_error' | 'transport_error' | 'cancelled' | 'stalled';
|
|
289
|
+
/**
|
|
290
|
+
* SSE 连接事件(Web / Electron renderer / Electron main)
|
|
291
|
+
* 对齐 Android/iOS sse_call:每条必带 measurements.stall_threshold_ms;禁止 stream_duration。
|
|
292
|
+
*/
|
|
293
|
+
export interface SSECallEvent extends BaseEvent {
|
|
294
|
+
event_type: EventType.SSE_CALL;
|
|
295
|
+
event_category: EventCategory.NETWORK;
|
|
296
|
+
data: {
|
|
297
|
+
url: string;
|
|
298
|
+
resource_type: 'sse';
|
|
299
|
+
measurements: {
|
|
300
|
+
duration: number;
|
|
301
|
+
redirect_count: number;
|
|
302
|
+
message_count: number;
|
|
303
|
+
stall_threshold_ms: number;
|
|
304
|
+
gap_lt_500_count: number;
|
|
305
|
+
gap_500_999_count: number;
|
|
306
|
+
gap_1000_2999_count: number;
|
|
307
|
+
gap_3000_9999_count: number;
|
|
308
|
+
gap_10000_59999_count: number;
|
|
309
|
+
gap_ge_60000_count: number;
|
|
310
|
+
time_to_first_message?: number;
|
|
311
|
+
last_message_offset?: number;
|
|
312
|
+
max_message_gap?: number;
|
|
313
|
+
dns_time?: number;
|
|
314
|
+
tcp_time?: number;
|
|
315
|
+
ssl_time?: number;
|
|
316
|
+
request_time?: number;
|
|
317
|
+
ttfb?: number;
|
|
318
|
+
response_time?: number;
|
|
319
|
+
bytes_sent?: number;
|
|
320
|
+
bytes_received?: number;
|
|
321
|
+
};
|
|
322
|
+
replay_id?: string;
|
|
323
|
+
tags?: Record<string, string>;
|
|
324
|
+
event_properties: {
|
|
325
|
+
http_method: string;
|
|
326
|
+
outcome: SSECallOutcome;
|
|
327
|
+
http_status?: string;
|
|
328
|
+
error_domain?: string;
|
|
329
|
+
error_code?: string;
|
|
330
|
+
error_category?: string;
|
|
331
|
+
original_url?: string;
|
|
332
|
+
request_headers?: string;
|
|
333
|
+
response_headers?: string;
|
|
334
|
+
replay_offset_ms?: string;
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
}
|
|
284
338
|
/**
|
|
285
339
|
* Web Vitals 性能事件
|
|
286
340
|
*/
|
|
@@ -374,6 +428,15 @@ export interface AppMemoryEventMeasurements {
|
|
|
374
428
|
app_memory: number;
|
|
375
429
|
memory_size: number;
|
|
376
430
|
free_memory: number;
|
|
431
|
+
main_memory?: number;
|
|
432
|
+
renderer_memory?: number;
|
|
433
|
+
gpu_memory?: number;
|
|
434
|
+
utility_memory?: number;
|
|
435
|
+
app_cpu?: number;
|
|
436
|
+
main_cpu?: number;
|
|
437
|
+
renderer_cpu?: number;
|
|
438
|
+
gpu_cpu?: number;
|
|
439
|
+
utility_cpu?: number;
|
|
377
440
|
}
|
|
378
441
|
export interface WebMemoryEventData {
|
|
379
442
|
measurements: WebMemoryEventMeasurements;
|
|
@@ -387,6 +450,7 @@ export interface AppMemoryEventData {
|
|
|
387
450
|
measurements: AppMemoryEventMeasurements;
|
|
388
451
|
event_properties: {
|
|
389
452
|
detection_source: 'app_metrics';
|
|
453
|
+
renderer_count?: string;
|
|
390
454
|
};
|
|
391
455
|
replay_id?: string;
|
|
392
456
|
tags?: Record<string, string>;
|
|
@@ -397,6 +461,40 @@ export interface MemoryUsageEvent extends BaseEvent {
|
|
|
397
461
|
event_category: EventCategory.PERFORMANCE;
|
|
398
462
|
data: MemoryEventData;
|
|
399
463
|
}
|
|
464
|
+
export declare type ProcessSignalEventName = 'render_process_gone' | 'child_process_gone' | 'unresponsive' | 'responsive';
|
|
465
|
+
export interface ProcessSignalEventProperties {
|
|
466
|
+
process_type: string;
|
|
467
|
+
process_role?: string;
|
|
468
|
+
window_id?: string;
|
|
469
|
+
web_contents_id?: string;
|
|
470
|
+
exit_reason?: string;
|
|
471
|
+
exit_code?: string;
|
|
472
|
+
service_name?: string;
|
|
473
|
+
repeat_count?: string;
|
|
474
|
+
}
|
|
475
|
+
export interface ProcessSignalEventData {
|
|
476
|
+
event_name: ProcessSignalEventName;
|
|
477
|
+
event_properties: ProcessSignalEventProperties;
|
|
478
|
+
measurements?: {
|
|
479
|
+
duration?: number;
|
|
480
|
+
app_memory?: number;
|
|
481
|
+
memory_size?: number;
|
|
482
|
+
free_memory?: number;
|
|
483
|
+
};
|
|
484
|
+
replay_id?: string;
|
|
485
|
+
tags?: Record<string, string>;
|
|
486
|
+
}
|
|
487
|
+
export interface ProcessSignalEvent extends BaseEvent {
|
|
488
|
+
event_type: EventType.PROCESS_SIGNAL;
|
|
489
|
+
event_category: EventCategory.PERFORMANCE;
|
|
490
|
+
event_name: ProcessSignalEventName;
|
|
491
|
+
data: ProcessSignalEventData;
|
|
492
|
+
}
|
|
493
|
+
export interface AppMetricsEvent extends BaseEvent {
|
|
494
|
+
event_type: EventType.APP_METRICS;
|
|
495
|
+
event_category: EventCategory.PERFORMANCE;
|
|
496
|
+
data: AppMemoryEventData;
|
|
497
|
+
}
|
|
400
498
|
export declare type FileIoOperation = 'read' | 'write' | 'open';
|
|
401
499
|
export interface FileIoEventMeasurements {
|
|
402
500
|
duration: number;
|
|
@@ -405,7 +503,7 @@ export interface FileIoEventMeasurements {
|
|
|
405
503
|
export interface FileIoEventProperties {
|
|
406
504
|
operation: FileIoOperation;
|
|
407
505
|
success: string;
|
|
408
|
-
process_type
|
|
506
|
+
process_type?: 'main' | 'renderer';
|
|
409
507
|
path?: string;
|
|
410
508
|
path_missing?: string;
|
|
411
509
|
}
|
|
@@ -629,7 +727,7 @@ export interface LogEvent extends BaseEvent {
|
|
|
629
727
|
/**
|
|
630
728
|
* 所有事件的联合类型
|
|
631
729
|
*/
|
|
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;
|
|
730
|
+
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
731
|
/** @internal Protocol-level input used by automatic struggle detectors. */
|
|
634
732
|
export interface ReportStruggleParams {
|
|
635
733
|
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';
|
|
@@ -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;
|
|
@@ -25,6 +25,11 @@ export interface TDEMSampleGate {
|
|
|
25
25
|
/** 是否被采样命中 */
|
|
26
26
|
readonly isSampled: boolean;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* 远程配置已放行且本 Session 采样命中。
|
|
30
|
+
* 决策前、远程关闭或未命中时都为 false,此时不得改写业务请求的追踪头。
|
|
31
|
+
*/
|
|
32
|
+
export declare function isTDEMCollectionActive(tdem: unknown): boolean;
|
|
28
33
|
/**
|
|
29
34
|
* 创建 TDEM 采样闸门管道
|
|
30
35
|
*
|
|
@@ -12,6 +12,8 @@ export declare type ApiMonitorConfig = CoreApiConfig & {
|
|
|
12
12
|
assetSlowThreshold?: number;
|
|
13
13
|
isSlowApi?: (api: any) => boolean;
|
|
14
14
|
isSlowAsset?: (asset: any) => boolean;
|
|
15
|
+
/** SSE 卡流阈值(ms)。省略或非法值按 60000 解析;SSE 跟随 api 开关,无独立 enabled。 */
|
|
16
|
+
sseStallThresholdMs?: number;
|
|
15
17
|
};
|
|
16
18
|
export declare type AssetMonitorConfig = {
|
|
17
19
|
slowThreshold?: number;
|
|
@@ -5,13 +5,16 @@ export declare const unHackXHR: (options: HackXHROptions) => void;
|
|
|
5
5
|
export interface HackFetchOptions {
|
|
6
6
|
name: string;
|
|
7
7
|
traceRequestHeader?: TraceRequestHeader;
|
|
8
|
+
shouldInjectTrace?: () => boolean;
|
|
8
9
|
ignoreHackReg?: RegExp;
|
|
9
10
|
getCurrentFrom?: () => string;
|
|
10
11
|
beforeFetch?: (url: string, option: RequestInit) => void;
|
|
11
12
|
then?: (res: Response, duration: number, url: string, option?: RequestInit, sendTime?: number, fromParam?: string, originFrom?: string) => void;
|
|
13
|
+
cloneError?: (res: Response, duration: number, url: string, option?: RequestInit, sendTime?: number, fromParam?: string, originFrom?: string) => void;
|
|
12
14
|
catch?: (err: any, duration: number, url: string, option?: RequestInit, sendTime?: number, fromParam?: string, originFrom?: string) => void;
|
|
13
15
|
}
|
|
14
16
|
export declare const hackFetch: (options: HackFetchOptions, ignoreHackReg?: RegExp) => void;
|
|
15
17
|
export declare const unHackFetch: (options: HackFetchOptions) => void;
|
|
18
|
+
export declare function resetHttpHacksForTests(): void;
|
|
16
19
|
export declare const responseHeadersString2Obj: (allResponseHeaders: string) => Record<string, string>;
|
|
17
20
|
export declare const getRequestHeaders: (headers: HeadersInit | undefined, reqHeaders: string[], tag: string) => string;
|