@arms/rum-core 0.1.3 → 0.1.5
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 +26 -2
- package/es/model/configManager.js +10 -3
- package/es/model/reporter.js +1 -1
- package/es/types/client.d.ts +8 -0
- package/es/types/rum-event.d.ts +242 -54
- package/es/types/rum-event.js +67 -1
- package/lib/model/configManager.js +10 -3
- package/lib/model/reporter.js +1 -1
- package/lib/types/client.d.ts +8 -0
- package/lib/types/rum-event.d.ts +242 -54
- package/lib/types/rum-event.js +50 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
# @arms/rum-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ARMS RUM SDK 多端方案的核心抽象层,为各平台 shell(`browser` / `uniapp` / `miniapp` / `minigame` / `electron` / `reactnative` 等)提供统一的角色模型、事件协议与跨运行时工具。
|
|
4
|
+
|
|
5
|
+
## 角色模型
|
|
6
|
+
|
|
7
|
+
- **Client**:装载并编排 `Collector` / `Processor` / `Reporter`,串联事件管线。
|
|
8
|
+
- **Context**:运行时上下文,承载 `config` / `session` / `views` / `emitter`。
|
|
9
|
+
- **Shell**:对外 API 入口,提供 `sendCustom` / `sendView` / `sendException` / `sendResource`。
|
|
10
|
+
- **ConfigManager**:本地+远端配置编排,支持 `launch-first` / `remote-first` 两种模式。
|
|
11
|
+
- **Collector / Processor / Reporter**:平台扩展点,分别负责数据采集、加工、上报。
|
|
12
|
+
|
|
13
|
+
事件流:`Collector → sendEvent → Processor 链 → Reporter(队列 / 合并 / 重试) → Transport`。
|
|
14
|
+
|
|
15
|
+
## 支持运行时
|
|
16
|
+
|
|
17
|
+
浏览器(ES2017+,不含 IE)、Node.js 16+、Deno、Bun、Electron、React Native 0.68+、微信/支付宝/字节小程序(基础库 2.10+ 同等能力)、uni-app 3.x。
|
|
18
|
+
|
|
19
|
+
`core` 自身不依赖任何浏览器或 Node 专属 API(`window` / `document` / `fetch` / `localStorage` / `XMLHttpRequest` 等);host API 通过 `env/` 抽象由 shell 注入。
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## 开发
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm run build # 产出 lib/ (CJS) + es/ (ESM)
|
|
26
|
+
npm test # 单元测试(先 build 后 test,重构后改为直接跑 ts 源码)
|
|
27
|
+
```
|
|
@@ -3,8 +3,15 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
4
|
function parseRemoteConfig(config) {
|
|
5
5
|
var remoteConfig = config.remoteConfig || {};
|
|
6
|
+
var enable = false;
|
|
7
|
+
if ('enable' in remoteConfig) {
|
|
8
|
+
enable = !!remoteConfig.enable;
|
|
9
|
+
} else if (remoteConfig.region || remoteConfig.url) {
|
|
10
|
+
enable = true;
|
|
11
|
+
}
|
|
6
12
|
return {
|
|
7
|
-
enable:
|
|
13
|
+
enable: enable,
|
|
14
|
+
// remoteConfig.enable !== false && !!(remoteConfig.url || remoteConfig.region),
|
|
8
15
|
url: remoteConfig.url || '',
|
|
9
16
|
mode: remoteConfig.mode || 'launch-first',
|
|
10
17
|
cacheTimeout: remoteConfig.cacheTimeout || 3600000,
|
|
@@ -94,7 +101,7 @@ export var ConfigManager = /*#__PURE__*/function () {
|
|
|
94
101
|
* 获取配置
|
|
95
102
|
* @returns 配置数据
|
|
96
103
|
*/
|
|
97
|
-
|
|
104
|
+
;
|
|
98
105
|
_proto.getConfig = function getConfig() {
|
|
99
106
|
if (!this.currentConfig) {
|
|
100
107
|
throw new Error('Config not initialized');
|
|
@@ -136,7 +143,7 @@ export var ConfigManager = /*#__PURE__*/function () {
|
|
|
136
143
|
* @param cachedData 缓存数据
|
|
137
144
|
* @param cacheTimeout 缓存超时时间
|
|
138
145
|
*/
|
|
139
|
-
|
|
146
|
+
;
|
|
140
147
|
_proto.isCacheValid = function isCacheValid(cachedData, cacheTimeout) {
|
|
141
148
|
if (!cachedData || !cachedData.timestamp) {
|
|
142
149
|
return false;
|
package/es/model/reporter.js
CHANGED
package/es/types/client.d.ts
CHANGED
|
@@ -33,7 +33,15 @@ export interface IContext {
|
|
|
33
33
|
[key: string]: any;
|
|
34
34
|
}
|
|
35
35
|
export interface SessionConfig {
|
|
36
|
+
/**
|
|
37
|
+
* Session 采样率,取值范围 0 - 1 的小数
|
|
38
|
+
* @deprecated 该字段将在未来版本下线,请使用 {@link SessionConfig.sampling} 替代
|
|
39
|
+
*/
|
|
36
40
|
sampleRate?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Session 采样率,取值范围 0 - 100,支持小数(如 50.5 表示 50.5%)
|
|
43
|
+
*/
|
|
44
|
+
sampling?: number;
|
|
37
45
|
maxDuration?: number;
|
|
38
46
|
overtime?: number;
|
|
39
47
|
storage?: string;
|
package/es/types/rum-event.d.ts
CHANGED
|
@@ -17,7 +17,102 @@ export interface IViewData extends BaseObject {
|
|
|
17
17
|
loading_type?: loading_type;
|
|
18
18
|
}
|
|
19
19
|
export type BaseObjectPrimitiveValue = string | number | boolean | null | undefined;
|
|
20
|
-
export type BaseObjectValue = BaseObjectPrimitiveValue | BaseObject | BaseObjectPrimitiveValue[] | IViewData;
|
|
20
|
+
export type BaseObjectValue = BaseObjectPrimitiveValue | BaseObject | BaseObjectPrimitiveValue[] | IViewData | RumEventContext;
|
|
21
|
+
/** 电池信息 */
|
|
22
|
+
export interface BatteryContext {
|
|
23
|
+
/** 是否正在充电 */
|
|
24
|
+
charging?: boolean;
|
|
25
|
+
/** 电池电量百分比 (0-100) */
|
|
26
|
+
level?: number;
|
|
27
|
+
/** 电池温度(摄氏度) */
|
|
28
|
+
temperature?: number;
|
|
29
|
+
}
|
|
30
|
+
/** 设备信息 */
|
|
31
|
+
export interface DeviceContext {
|
|
32
|
+
/** 设备 CPU 架构,如 'arm64', 'x86_64' */
|
|
33
|
+
architecture?: string;
|
|
34
|
+
/** 屏幕亮度等级 */
|
|
35
|
+
brightness_level?: number;
|
|
36
|
+
/** 芯片组型号 */
|
|
37
|
+
chipset?: string;
|
|
38
|
+
/** 当前语言区域,如 'zh-CN' */
|
|
39
|
+
locale?: string;
|
|
40
|
+
/** 用户偏好语言列表 */
|
|
41
|
+
locales?: string[];
|
|
42
|
+
/** 屏幕方向,如 'portrait', 'landscape' */
|
|
43
|
+
orientation?: string;
|
|
44
|
+
/** 是否开启省电模式 */
|
|
45
|
+
power_saving_mode?: boolean;
|
|
46
|
+
/** CPU 核心数 */
|
|
47
|
+
processor_count?: number;
|
|
48
|
+
/** CPU 主频(Hz) */
|
|
49
|
+
processor_frequency?: number;
|
|
50
|
+
/** 屏幕像素密度 */
|
|
51
|
+
screen_density?: number;
|
|
52
|
+
/** 屏幕 DPI */
|
|
53
|
+
screen_dpi?: number;
|
|
54
|
+
/** 是否为模拟器 */
|
|
55
|
+
simulator?: boolean;
|
|
56
|
+
/** 设备时区,如 'Asia/Shanghai' */
|
|
57
|
+
timezone?: string;
|
|
58
|
+
}
|
|
59
|
+
/** 内存信息 */
|
|
60
|
+
export interface MemoryContext {
|
|
61
|
+
/** 可用内存(字节) */
|
|
62
|
+
free?: number;
|
|
63
|
+
/** 是否处于低内存状态 */
|
|
64
|
+
low?: boolean;
|
|
65
|
+
/** 总内存大小(字节) */
|
|
66
|
+
size?: number;
|
|
67
|
+
}
|
|
68
|
+
/** 网络信息 */
|
|
69
|
+
export interface NetworkContext {
|
|
70
|
+
/** 可用网络接口列表 */
|
|
71
|
+
connectivity_interfaces?: string[];
|
|
72
|
+
/** 网络连接状态,如 'wifi', 'cellular', 'none' */
|
|
73
|
+
connectivity_status?: string;
|
|
74
|
+
/** 网络是否受限(如防火墙限制) */
|
|
75
|
+
is_constrained?: boolean;
|
|
76
|
+
/** 网络是否为计费网络(如蜂窝数据) */
|
|
77
|
+
is_expensive?: boolean;
|
|
78
|
+
/** 信号强度 */
|
|
79
|
+
signal_strength?: number;
|
|
80
|
+
/** 是否支持 IPv6 */
|
|
81
|
+
supports_ipv6?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/** 操作系统信息 */
|
|
84
|
+
export interface OsContext {
|
|
85
|
+
/** 系统构建号 */
|
|
86
|
+
build?: string;
|
|
87
|
+
/** 内核版本 */
|
|
88
|
+
kernel_version?: string;
|
|
89
|
+
/** 是否已 root / 越狱 */
|
|
90
|
+
rooted?: boolean;
|
|
91
|
+
/** 系统主版本号 */
|
|
92
|
+
version_major?: string;
|
|
93
|
+
}
|
|
94
|
+
/** 存储信息 */
|
|
95
|
+
export interface StorageContext {
|
|
96
|
+
/** 可用存储(字节) */
|
|
97
|
+
free?: number;
|
|
98
|
+
/** 总存储大小(字节) */
|
|
99
|
+
size?: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* RUM 事件上下文,描述设备运行时的环境快照。
|
|
103
|
+
* 字段命名与 DataDog / Sentry 的 context 协议对齐,
|
|
104
|
+
* 各端(Android / iOS / Electron)按能力选择性填充。
|
|
105
|
+
*
|
|
106
|
+
* @see docs/内存信息采集方案.md
|
|
107
|
+
*/
|
|
108
|
+
export interface RumEventContext {
|
|
109
|
+
battery?: BatteryContext;
|
|
110
|
+
device?: DeviceContext;
|
|
111
|
+
memory?: MemoryContext;
|
|
112
|
+
network?: NetworkContext;
|
|
113
|
+
os?: OsContext;
|
|
114
|
+
storage?: StorageContext;
|
|
115
|
+
}
|
|
21
116
|
export interface RumBaseEvent extends BaseObject {
|
|
22
117
|
event_type?: RumEventType;
|
|
23
118
|
event_id?: string;
|
|
@@ -25,6 +120,7 @@ export interface RumBaseEvent extends BaseObject {
|
|
|
25
120
|
timestamp?: number;
|
|
26
121
|
times?: number;
|
|
27
122
|
view?: IViewData;
|
|
123
|
+
context?: RumEventContext;
|
|
28
124
|
snapshots?: string;
|
|
29
125
|
properties?: BaseObject;
|
|
30
126
|
}
|
|
@@ -112,7 +208,7 @@ export interface RumResourceEvent extends RumBaseEvent {
|
|
|
112
208
|
download_duration?: number;
|
|
113
209
|
url?: string;
|
|
114
210
|
timing_data?: string;
|
|
115
|
-
|
|
211
|
+
trace_data?: string;
|
|
116
212
|
}
|
|
117
213
|
export interface RumExceptionEvent extends RumBaseEvent {
|
|
118
214
|
source?: string;
|
|
@@ -192,62 +288,154 @@ export declare enum AppType {
|
|
|
192
288
|
uniapp = "uniapp",
|
|
193
289
|
reactnative = "reactnative"
|
|
194
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* 上报包中的应用信息
|
|
293
|
+
*
|
|
294
|
+
* @see {@link AppType} 应用类型枚举
|
|
295
|
+
*/
|
|
296
|
+
export interface RumApp {
|
|
297
|
+
/** 应用唯一标识(由平台分配) */
|
|
298
|
+
id: string;
|
|
299
|
+
/** 应用类型,如 {@link AppType.browser}、{@link AppType.miniapp} */
|
|
300
|
+
type: AppType | string;
|
|
301
|
+
/** 应用名称 */
|
|
302
|
+
name?: string;
|
|
303
|
+
/** 应用版本号,如 '1.2.3' */
|
|
304
|
+
version?: string;
|
|
305
|
+
/** 发布渠道,如 'official'、'appstore' */
|
|
306
|
+
channel?: string;
|
|
307
|
+
/** 运行环境,如 'production'、'staging'、'development' */
|
|
308
|
+
env?: string;
|
|
309
|
+
/** 包名 / Bundle Identifier */
|
|
310
|
+
package?: string;
|
|
311
|
+
/** 宿主框架,如 'react'、'vue'、'uniapp' */
|
|
312
|
+
framework?: string;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* 上报包中的用户信息
|
|
316
|
+
*
|
|
317
|
+
* @see {@link RumEventBundle} 上报数据包结构
|
|
318
|
+
*/
|
|
319
|
+
export interface RumUser {
|
|
320
|
+
/** 用户唯一标识(匿名 ID 或登录 ID) */
|
|
321
|
+
id: string;
|
|
322
|
+
/** 用户名称 */
|
|
323
|
+
name?: string;
|
|
324
|
+
/** 用户标签,多个标签以逗号分隔 */
|
|
325
|
+
tags?: string;
|
|
326
|
+
}
|
|
327
|
+
/** 上报包中的会话信息 */
|
|
328
|
+
export interface RumSession {
|
|
329
|
+
/** 会话唯一标识,同一用户在同一会话周期内保持不变 */
|
|
330
|
+
id: string;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 上报包中的页面信息
|
|
334
|
+
*
|
|
335
|
+
* @see {@link IViewData} 事件级页面数据结构
|
|
336
|
+
*/
|
|
337
|
+
export interface RumView {
|
|
338
|
+
/** 页面唯一标识 */
|
|
339
|
+
id: string;
|
|
340
|
+
/** 页面名称 */
|
|
341
|
+
name: string;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* 上报包中的设备信息
|
|
345
|
+
*
|
|
346
|
+
* @see {@link DeviceContext} 运行时设备详细上下文
|
|
347
|
+
*/
|
|
348
|
+
export interface RumDevice {
|
|
349
|
+
/** 设备唯一标识(如 IDFV、Android ID) */
|
|
350
|
+
id?: string;
|
|
351
|
+
/** 设备类型,如 'mobile'、'tablet'、'desktop' */
|
|
352
|
+
type?: string;
|
|
353
|
+
/** 设备品牌,如 'Apple'、'Huawei' */
|
|
354
|
+
brand?: string;
|
|
355
|
+
/** 设备型号,如 'iPhone 15'、'Mate 60' */
|
|
356
|
+
model?: string;
|
|
357
|
+
/** 设备名称 */
|
|
358
|
+
name?: string;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* 上报包中的操作系统信息
|
|
362
|
+
*
|
|
363
|
+
* @see {@link OsContext} 运行时操作系统详细上下文
|
|
364
|
+
*/
|
|
365
|
+
export interface RumOS {
|
|
366
|
+
/** 操作系统类型,如 'iOS'、'Android'、'Windows' */
|
|
367
|
+
type?: string;
|
|
368
|
+
/** 操作系统完整版本号,如 '17.4.1' */
|
|
369
|
+
version?: string;
|
|
370
|
+
/** 容器环境,如 'WeChat'、'DingTalk'、'Chrome' */
|
|
371
|
+
container?: string;
|
|
372
|
+
/** 容器版本号 */
|
|
373
|
+
container_version?: string;
|
|
374
|
+
}
|
|
375
|
+
/** 上报包中的地理位置信息(由服务端根据 IP 解析填充) */
|
|
376
|
+
export interface RumGeo {
|
|
377
|
+
/** 国家名称 */
|
|
378
|
+
country?: string;
|
|
379
|
+
/** 国家编码,如 ISO 3166-1 alpha-2 */
|
|
380
|
+
country_id?: string;
|
|
381
|
+
/** 省份 / 州名称 */
|
|
382
|
+
province?: string;
|
|
383
|
+
/** 省份编码 */
|
|
384
|
+
province_id?: string;
|
|
385
|
+
/** 城市名称 */
|
|
386
|
+
city?: string;
|
|
387
|
+
/** 城市编码 */
|
|
388
|
+
city_id?: string;
|
|
389
|
+
}
|
|
390
|
+
/** 上报包中的运营商信息(由服务端根据 IP 解析填充) */
|
|
391
|
+
export interface RumISP {
|
|
392
|
+
/** 运营商编码 */
|
|
393
|
+
id?: string;
|
|
394
|
+
/** 运营商名称,如 '中国移动'、'中国联通' */
|
|
395
|
+
name?: string;
|
|
396
|
+
}
|
|
397
|
+
/** 上报包中的网络信息 */
|
|
398
|
+
export interface RumNet {
|
|
399
|
+
/** 网络接入模型,如 '4G'、'5G'、'WiFi' */
|
|
400
|
+
model?: string;
|
|
401
|
+
/** 网络名称(如 SSID 或运营商 APN 名称) */
|
|
402
|
+
name?: string;
|
|
403
|
+
/** 客户端出口 IP 地址 */
|
|
404
|
+
ip?: string;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* RUM 上报数据包,将一批事件与公共上下文打包后发送至服务端。
|
|
408
|
+
*
|
|
409
|
+
* @see {@link RumEvent} 包内携带的事件列表
|
|
410
|
+
* @see {@link RumApp} 应用信息
|
|
411
|
+
* @see {@link RumUser} 用户信息
|
|
412
|
+
*/
|
|
195
413
|
export interface RumEventBundle {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
id: string;
|
|
216
|
-
name: string;
|
|
217
|
-
};
|
|
218
|
-
device?: {
|
|
219
|
-
id?: string;
|
|
220
|
-
type?: string;
|
|
221
|
-
brand?: string;
|
|
222
|
-
model?: string;
|
|
223
|
-
name?: string;
|
|
224
|
-
};
|
|
225
|
-
os?: {
|
|
226
|
-
type?: string;
|
|
227
|
-
version?: string;
|
|
228
|
-
container?: string;
|
|
229
|
-
container_version?: string;
|
|
230
|
-
};
|
|
231
|
-
geo?: {
|
|
232
|
-
country?: string;
|
|
233
|
-
country_id?: string;
|
|
234
|
-
province?: string;
|
|
235
|
-
province_id?: string;
|
|
236
|
-
city?: string;
|
|
237
|
-
city_id?: string;
|
|
238
|
-
};
|
|
239
|
-
isp?: {
|
|
240
|
-
id?: string;
|
|
241
|
-
name?: string;
|
|
242
|
-
};
|
|
243
|
-
net?: {
|
|
244
|
-
model?: string;
|
|
245
|
-
name?: string;
|
|
246
|
-
ip?: string;
|
|
247
|
-
};
|
|
414
|
+
/** 应用信息 */
|
|
415
|
+
app: RumApp;
|
|
416
|
+
/** 用户信息 */
|
|
417
|
+
user: RumUser;
|
|
418
|
+
/** 会话信息 */
|
|
419
|
+
session: RumSession;
|
|
420
|
+
/** 当前页面信息 */
|
|
421
|
+
view: RumView;
|
|
422
|
+
/** 设备信息 */
|
|
423
|
+
device?: RumDevice;
|
|
424
|
+
/** 操作系统信息 */
|
|
425
|
+
os?: RumOS;
|
|
426
|
+
/** 地理位置信息 */
|
|
427
|
+
geo?: RumGeo;
|
|
428
|
+
/** 运营商信息 */
|
|
429
|
+
isp?: RumISP;
|
|
430
|
+
/** 网络信息 */
|
|
431
|
+
net?: RumNet;
|
|
432
|
+
/** 本次上报携带的事件列表 */
|
|
248
433
|
events: Array<RumEvent>;
|
|
434
|
+
/** 全局自定义属性,附加到上报包级别 */
|
|
249
435
|
properties?: BaseObject;
|
|
436
|
+
/** SDK 协议版本号 */
|
|
250
437
|
_v?: string;
|
|
438
|
+
/** 重试次数(内部使用,首次上报为 undefined) */
|
|
251
439
|
_retry?: number;
|
|
252
440
|
[key: string]: unknown;
|
|
253
441
|
}
|
package/es/types/rum-event.js
CHANGED
|
@@ -9,6 +9,26 @@ export var RumEventType = /*#__PURE__*/function (RumEventType) {
|
|
|
9
9
|
return RumEventType;
|
|
10
10
|
}({});
|
|
11
11
|
|
|
12
|
+
/** 电池信息 */
|
|
13
|
+
|
|
14
|
+
/** 设备信息 */
|
|
15
|
+
|
|
16
|
+
/** 内存信息 */
|
|
17
|
+
|
|
18
|
+
/** 网络信息 */
|
|
19
|
+
|
|
20
|
+
/** 操作系统信息 */
|
|
21
|
+
|
|
22
|
+
/** 存储信息 */
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* RUM 事件上下文,描述设备运行时的环境快照。
|
|
26
|
+
* 字段命名与 DataDog / Sentry 的 context 协议对齐,
|
|
27
|
+
* 各端(Android / iOS / Electron)按能力选择性填充。
|
|
28
|
+
*
|
|
29
|
+
* @see docs/内存信息采集方案.md
|
|
30
|
+
*/
|
|
31
|
+
|
|
12
32
|
/** 事件类型:页面浏览、性能指标、Web Vitals、自定义指标、会话回放 */
|
|
13
33
|
|
|
14
34
|
/**
|
|
@@ -27,4 +47,50 @@ export var AppType = /*#__PURE__*/function (AppType) {
|
|
|
27
47
|
AppType["uniapp"] = "uniapp";
|
|
28
48
|
AppType["reactnative"] = "reactnative";
|
|
29
49
|
return AppType;
|
|
30
|
-
}({});
|
|
50
|
+
}({});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 上报包中的应用信息
|
|
54
|
+
*
|
|
55
|
+
* @see {@link AppType} 应用类型枚举
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 上报包中的用户信息
|
|
60
|
+
*
|
|
61
|
+
* @see {@link RumEventBundle} 上报数据包结构
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/** 上报包中的会话信息 */
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 上报包中的页面信息
|
|
68
|
+
*
|
|
69
|
+
* @see {@link IViewData} 事件级页面数据结构
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 上报包中的设备信息
|
|
74
|
+
*
|
|
75
|
+
* @see {@link DeviceContext} 运行时设备详细上下文
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 上报包中的操作系统信息
|
|
80
|
+
*
|
|
81
|
+
* @see {@link OsContext} 运行时操作系统详细上下文
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/** 上报包中的地理位置信息(由服务端根据 IP 解析填充) */
|
|
85
|
+
|
|
86
|
+
/** 上报包中的运营商信息(由服务端根据 IP 解析填充) */
|
|
87
|
+
|
|
88
|
+
/** 上报包中的网络信息 */
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* RUM 上报数据包,将一批事件与公共上下文打包后发送至服务端。
|
|
92
|
+
*
|
|
93
|
+
* @see {@link RumEvent} 包内携带的事件列表
|
|
94
|
+
* @see {@link RumApp} 应用信息
|
|
95
|
+
* @see {@link RumUser} 用户信息
|
|
96
|
+
*/
|
|
@@ -8,8 +8,15 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
8
8
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
9
9
|
function parseRemoteConfig(config) {
|
|
10
10
|
var remoteConfig = config.remoteConfig || {};
|
|
11
|
+
var enable = false;
|
|
12
|
+
if ('enable' in remoteConfig) {
|
|
13
|
+
enable = !!remoteConfig.enable;
|
|
14
|
+
} else if (remoteConfig.region || remoteConfig.url) {
|
|
15
|
+
enable = true;
|
|
16
|
+
}
|
|
11
17
|
return {
|
|
12
|
-
enable:
|
|
18
|
+
enable: enable,
|
|
19
|
+
// remoteConfig.enable !== false && !!(remoteConfig.url || remoteConfig.region),
|
|
13
20
|
url: remoteConfig.url || '',
|
|
14
21
|
mode: remoteConfig.mode || 'launch-first',
|
|
15
22
|
cacheTimeout: remoteConfig.cacheTimeout || 3600000,
|
|
@@ -99,7 +106,7 @@ var ConfigManager = exports.ConfigManager = /*#__PURE__*/function () {
|
|
|
99
106
|
* 获取配置
|
|
100
107
|
* @returns 配置数据
|
|
101
108
|
*/
|
|
102
|
-
|
|
109
|
+
;
|
|
103
110
|
_proto.getConfig = function getConfig() {
|
|
104
111
|
if (!this.currentConfig) {
|
|
105
112
|
throw new Error('Config not initialized');
|
|
@@ -141,7 +148,7 @@ var ConfigManager = exports.ConfigManager = /*#__PURE__*/function () {
|
|
|
141
148
|
* @param cachedData 缓存数据
|
|
142
149
|
* @param cacheTimeout 缓存超时时间
|
|
143
150
|
*/
|
|
144
|
-
|
|
151
|
+
;
|
|
145
152
|
_proto.isCacheValid = function isCacheValid(cachedData, cacheTimeout) {
|
|
146
153
|
if (!cachedData || !cachedData.timestamp) {
|
|
147
154
|
return false;
|
package/lib/model/reporter.js
CHANGED
package/lib/types/client.d.ts
CHANGED
|
@@ -33,7 +33,15 @@ export interface IContext {
|
|
|
33
33
|
[key: string]: any;
|
|
34
34
|
}
|
|
35
35
|
export interface SessionConfig {
|
|
36
|
+
/**
|
|
37
|
+
* Session 采样率,取值范围 0 - 1 的小数
|
|
38
|
+
* @deprecated 该字段将在未来版本下线,请使用 {@link SessionConfig.sampling} 替代
|
|
39
|
+
*/
|
|
36
40
|
sampleRate?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Session 采样率,取值范围 0 - 100,支持小数(如 50.5 表示 50.5%)
|
|
43
|
+
*/
|
|
44
|
+
sampling?: number;
|
|
37
45
|
maxDuration?: number;
|
|
38
46
|
overtime?: number;
|
|
39
47
|
storage?: string;
|
package/lib/types/rum-event.d.ts
CHANGED
|
@@ -17,7 +17,102 @@ export interface IViewData extends BaseObject {
|
|
|
17
17
|
loading_type?: loading_type;
|
|
18
18
|
}
|
|
19
19
|
export type BaseObjectPrimitiveValue = string | number | boolean | null | undefined;
|
|
20
|
-
export type BaseObjectValue = BaseObjectPrimitiveValue | BaseObject | BaseObjectPrimitiveValue[] | IViewData;
|
|
20
|
+
export type BaseObjectValue = BaseObjectPrimitiveValue | BaseObject | BaseObjectPrimitiveValue[] | IViewData | RumEventContext;
|
|
21
|
+
/** 电池信息 */
|
|
22
|
+
export interface BatteryContext {
|
|
23
|
+
/** 是否正在充电 */
|
|
24
|
+
charging?: boolean;
|
|
25
|
+
/** 电池电量百分比 (0-100) */
|
|
26
|
+
level?: number;
|
|
27
|
+
/** 电池温度(摄氏度) */
|
|
28
|
+
temperature?: number;
|
|
29
|
+
}
|
|
30
|
+
/** 设备信息 */
|
|
31
|
+
export interface DeviceContext {
|
|
32
|
+
/** 设备 CPU 架构,如 'arm64', 'x86_64' */
|
|
33
|
+
architecture?: string;
|
|
34
|
+
/** 屏幕亮度等级 */
|
|
35
|
+
brightness_level?: number;
|
|
36
|
+
/** 芯片组型号 */
|
|
37
|
+
chipset?: string;
|
|
38
|
+
/** 当前语言区域,如 'zh-CN' */
|
|
39
|
+
locale?: string;
|
|
40
|
+
/** 用户偏好语言列表 */
|
|
41
|
+
locales?: string[];
|
|
42
|
+
/** 屏幕方向,如 'portrait', 'landscape' */
|
|
43
|
+
orientation?: string;
|
|
44
|
+
/** 是否开启省电模式 */
|
|
45
|
+
power_saving_mode?: boolean;
|
|
46
|
+
/** CPU 核心数 */
|
|
47
|
+
processor_count?: number;
|
|
48
|
+
/** CPU 主频(Hz) */
|
|
49
|
+
processor_frequency?: number;
|
|
50
|
+
/** 屏幕像素密度 */
|
|
51
|
+
screen_density?: number;
|
|
52
|
+
/** 屏幕 DPI */
|
|
53
|
+
screen_dpi?: number;
|
|
54
|
+
/** 是否为模拟器 */
|
|
55
|
+
simulator?: boolean;
|
|
56
|
+
/** 设备时区,如 'Asia/Shanghai' */
|
|
57
|
+
timezone?: string;
|
|
58
|
+
}
|
|
59
|
+
/** 内存信息 */
|
|
60
|
+
export interface MemoryContext {
|
|
61
|
+
/** 可用内存(字节) */
|
|
62
|
+
free?: number;
|
|
63
|
+
/** 是否处于低内存状态 */
|
|
64
|
+
low?: boolean;
|
|
65
|
+
/** 总内存大小(字节) */
|
|
66
|
+
size?: number;
|
|
67
|
+
}
|
|
68
|
+
/** 网络信息 */
|
|
69
|
+
export interface NetworkContext {
|
|
70
|
+
/** 可用网络接口列表 */
|
|
71
|
+
connectivity_interfaces?: string[];
|
|
72
|
+
/** 网络连接状态,如 'wifi', 'cellular', 'none' */
|
|
73
|
+
connectivity_status?: string;
|
|
74
|
+
/** 网络是否受限(如防火墙限制) */
|
|
75
|
+
is_constrained?: boolean;
|
|
76
|
+
/** 网络是否为计费网络(如蜂窝数据) */
|
|
77
|
+
is_expensive?: boolean;
|
|
78
|
+
/** 信号强度 */
|
|
79
|
+
signal_strength?: number;
|
|
80
|
+
/** 是否支持 IPv6 */
|
|
81
|
+
supports_ipv6?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/** 操作系统信息 */
|
|
84
|
+
export interface OsContext {
|
|
85
|
+
/** 系统构建号 */
|
|
86
|
+
build?: string;
|
|
87
|
+
/** 内核版本 */
|
|
88
|
+
kernel_version?: string;
|
|
89
|
+
/** 是否已 root / 越狱 */
|
|
90
|
+
rooted?: boolean;
|
|
91
|
+
/** 系统主版本号 */
|
|
92
|
+
version_major?: string;
|
|
93
|
+
}
|
|
94
|
+
/** 存储信息 */
|
|
95
|
+
export interface StorageContext {
|
|
96
|
+
/** 可用存储(字节) */
|
|
97
|
+
free?: number;
|
|
98
|
+
/** 总存储大小(字节) */
|
|
99
|
+
size?: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* RUM 事件上下文,描述设备运行时的环境快照。
|
|
103
|
+
* 字段命名与 DataDog / Sentry 的 context 协议对齐,
|
|
104
|
+
* 各端(Android / iOS / Electron)按能力选择性填充。
|
|
105
|
+
*
|
|
106
|
+
* @see docs/内存信息采集方案.md
|
|
107
|
+
*/
|
|
108
|
+
export interface RumEventContext {
|
|
109
|
+
battery?: BatteryContext;
|
|
110
|
+
device?: DeviceContext;
|
|
111
|
+
memory?: MemoryContext;
|
|
112
|
+
network?: NetworkContext;
|
|
113
|
+
os?: OsContext;
|
|
114
|
+
storage?: StorageContext;
|
|
115
|
+
}
|
|
21
116
|
export interface RumBaseEvent extends BaseObject {
|
|
22
117
|
event_type?: RumEventType;
|
|
23
118
|
event_id?: string;
|
|
@@ -25,6 +120,7 @@ export interface RumBaseEvent extends BaseObject {
|
|
|
25
120
|
timestamp?: number;
|
|
26
121
|
times?: number;
|
|
27
122
|
view?: IViewData;
|
|
123
|
+
context?: RumEventContext;
|
|
28
124
|
snapshots?: string;
|
|
29
125
|
properties?: BaseObject;
|
|
30
126
|
}
|
|
@@ -112,7 +208,7 @@ export interface RumResourceEvent extends RumBaseEvent {
|
|
|
112
208
|
download_duration?: number;
|
|
113
209
|
url?: string;
|
|
114
210
|
timing_data?: string;
|
|
115
|
-
|
|
211
|
+
trace_data?: string;
|
|
116
212
|
}
|
|
117
213
|
export interface RumExceptionEvent extends RumBaseEvent {
|
|
118
214
|
source?: string;
|
|
@@ -192,62 +288,154 @@ export declare enum AppType {
|
|
|
192
288
|
uniapp = "uniapp",
|
|
193
289
|
reactnative = "reactnative"
|
|
194
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* 上报包中的应用信息
|
|
293
|
+
*
|
|
294
|
+
* @see {@link AppType} 应用类型枚举
|
|
295
|
+
*/
|
|
296
|
+
export interface RumApp {
|
|
297
|
+
/** 应用唯一标识(由平台分配) */
|
|
298
|
+
id: string;
|
|
299
|
+
/** 应用类型,如 {@link AppType.browser}、{@link AppType.miniapp} */
|
|
300
|
+
type: AppType | string;
|
|
301
|
+
/** 应用名称 */
|
|
302
|
+
name?: string;
|
|
303
|
+
/** 应用版本号,如 '1.2.3' */
|
|
304
|
+
version?: string;
|
|
305
|
+
/** 发布渠道,如 'official'、'appstore' */
|
|
306
|
+
channel?: string;
|
|
307
|
+
/** 运行环境,如 'production'、'staging'、'development' */
|
|
308
|
+
env?: string;
|
|
309
|
+
/** 包名 / Bundle Identifier */
|
|
310
|
+
package?: string;
|
|
311
|
+
/** 宿主框架,如 'react'、'vue'、'uniapp' */
|
|
312
|
+
framework?: string;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* 上报包中的用户信息
|
|
316
|
+
*
|
|
317
|
+
* @see {@link RumEventBundle} 上报数据包结构
|
|
318
|
+
*/
|
|
319
|
+
export interface RumUser {
|
|
320
|
+
/** 用户唯一标识(匿名 ID 或登录 ID) */
|
|
321
|
+
id: string;
|
|
322
|
+
/** 用户名称 */
|
|
323
|
+
name?: string;
|
|
324
|
+
/** 用户标签,多个标签以逗号分隔 */
|
|
325
|
+
tags?: string;
|
|
326
|
+
}
|
|
327
|
+
/** 上报包中的会话信息 */
|
|
328
|
+
export interface RumSession {
|
|
329
|
+
/** 会话唯一标识,同一用户在同一会话周期内保持不变 */
|
|
330
|
+
id: string;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 上报包中的页面信息
|
|
334
|
+
*
|
|
335
|
+
* @see {@link IViewData} 事件级页面数据结构
|
|
336
|
+
*/
|
|
337
|
+
export interface RumView {
|
|
338
|
+
/** 页面唯一标识 */
|
|
339
|
+
id: string;
|
|
340
|
+
/** 页面名称 */
|
|
341
|
+
name: string;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* 上报包中的设备信息
|
|
345
|
+
*
|
|
346
|
+
* @see {@link DeviceContext} 运行时设备详细上下文
|
|
347
|
+
*/
|
|
348
|
+
export interface RumDevice {
|
|
349
|
+
/** 设备唯一标识(如 IDFV、Android ID) */
|
|
350
|
+
id?: string;
|
|
351
|
+
/** 设备类型,如 'mobile'、'tablet'、'desktop' */
|
|
352
|
+
type?: string;
|
|
353
|
+
/** 设备品牌,如 'Apple'、'Huawei' */
|
|
354
|
+
brand?: string;
|
|
355
|
+
/** 设备型号,如 'iPhone 15'、'Mate 60' */
|
|
356
|
+
model?: string;
|
|
357
|
+
/** 设备名称 */
|
|
358
|
+
name?: string;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* 上报包中的操作系统信息
|
|
362
|
+
*
|
|
363
|
+
* @see {@link OsContext} 运行时操作系统详细上下文
|
|
364
|
+
*/
|
|
365
|
+
export interface RumOS {
|
|
366
|
+
/** 操作系统类型,如 'iOS'、'Android'、'Windows' */
|
|
367
|
+
type?: string;
|
|
368
|
+
/** 操作系统完整版本号,如 '17.4.1' */
|
|
369
|
+
version?: string;
|
|
370
|
+
/** 容器环境,如 'WeChat'、'DingTalk'、'Chrome' */
|
|
371
|
+
container?: string;
|
|
372
|
+
/** 容器版本号 */
|
|
373
|
+
container_version?: string;
|
|
374
|
+
}
|
|
375
|
+
/** 上报包中的地理位置信息(由服务端根据 IP 解析填充) */
|
|
376
|
+
export interface RumGeo {
|
|
377
|
+
/** 国家名称 */
|
|
378
|
+
country?: string;
|
|
379
|
+
/** 国家编码,如 ISO 3166-1 alpha-2 */
|
|
380
|
+
country_id?: string;
|
|
381
|
+
/** 省份 / 州名称 */
|
|
382
|
+
province?: string;
|
|
383
|
+
/** 省份编码 */
|
|
384
|
+
province_id?: string;
|
|
385
|
+
/** 城市名称 */
|
|
386
|
+
city?: string;
|
|
387
|
+
/** 城市编码 */
|
|
388
|
+
city_id?: string;
|
|
389
|
+
}
|
|
390
|
+
/** 上报包中的运营商信息(由服务端根据 IP 解析填充) */
|
|
391
|
+
export interface RumISP {
|
|
392
|
+
/** 运营商编码 */
|
|
393
|
+
id?: string;
|
|
394
|
+
/** 运营商名称,如 '中国移动'、'中国联通' */
|
|
395
|
+
name?: string;
|
|
396
|
+
}
|
|
397
|
+
/** 上报包中的网络信息 */
|
|
398
|
+
export interface RumNet {
|
|
399
|
+
/** 网络接入模型,如 '4G'、'5G'、'WiFi' */
|
|
400
|
+
model?: string;
|
|
401
|
+
/** 网络名称(如 SSID 或运营商 APN 名称) */
|
|
402
|
+
name?: string;
|
|
403
|
+
/** 客户端出口 IP 地址 */
|
|
404
|
+
ip?: string;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* RUM 上报数据包,将一批事件与公共上下文打包后发送至服务端。
|
|
408
|
+
*
|
|
409
|
+
* @see {@link RumEvent} 包内携带的事件列表
|
|
410
|
+
* @see {@link RumApp} 应用信息
|
|
411
|
+
* @see {@link RumUser} 用户信息
|
|
412
|
+
*/
|
|
195
413
|
export interface RumEventBundle {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
id: string;
|
|
216
|
-
name: string;
|
|
217
|
-
};
|
|
218
|
-
device?: {
|
|
219
|
-
id?: string;
|
|
220
|
-
type?: string;
|
|
221
|
-
brand?: string;
|
|
222
|
-
model?: string;
|
|
223
|
-
name?: string;
|
|
224
|
-
};
|
|
225
|
-
os?: {
|
|
226
|
-
type?: string;
|
|
227
|
-
version?: string;
|
|
228
|
-
container?: string;
|
|
229
|
-
container_version?: string;
|
|
230
|
-
};
|
|
231
|
-
geo?: {
|
|
232
|
-
country?: string;
|
|
233
|
-
country_id?: string;
|
|
234
|
-
province?: string;
|
|
235
|
-
province_id?: string;
|
|
236
|
-
city?: string;
|
|
237
|
-
city_id?: string;
|
|
238
|
-
};
|
|
239
|
-
isp?: {
|
|
240
|
-
id?: string;
|
|
241
|
-
name?: string;
|
|
242
|
-
};
|
|
243
|
-
net?: {
|
|
244
|
-
model?: string;
|
|
245
|
-
name?: string;
|
|
246
|
-
ip?: string;
|
|
247
|
-
};
|
|
414
|
+
/** 应用信息 */
|
|
415
|
+
app: RumApp;
|
|
416
|
+
/** 用户信息 */
|
|
417
|
+
user: RumUser;
|
|
418
|
+
/** 会话信息 */
|
|
419
|
+
session: RumSession;
|
|
420
|
+
/** 当前页面信息 */
|
|
421
|
+
view: RumView;
|
|
422
|
+
/** 设备信息 */
|
|
423
|
+
device?: RumDevice;
|
|
424
|
+
/** 操作系统信息 */
|
|
425
|
+
os?: RumOS;
|
|
426
|
+
/** 地理位置信息 */
|
|
427
|
+
geo?: RumGeo;
|
|
428
|
+
/** 运营商信息 */
|
|
429
|
+
isp?: RumISP;
|
|
430
|
+
/** 网络信息 */
|
|
431
|
+
net?: RumNet;
|
|
432
|
+
/** 本次上报携带的事件列表 */
|
|
248
433
|
events: Array<RumEvent>;
|
|
434
|
+
/** 全局自定义属性,附加到上报包级别 */
|
|
249
435
|
properties?: BaseObject;
|
|
436
|
+
/** SDK 协议版本号 */
|
|
250
437
|
_v?: string;
|
|
438
|
+
/** 重试次数(内部使用,首次上报为 undefined) */
|
|
251
439
|
_retry?: number;
|
|
252
440
|
[key: string]: unknown;
|
|
253
441
|
}
|
package/lib/types/rum-event.js
CHANGED
|
@@ -12,6 +12,19 @@ var RumEventType = exports.RumEventType = /*#__PURE__*/function (RumEventType) {
|
|
|
12
12
|
RumEventType["APPLICATION"] = "application";
|
|
13
13
|
return RumEventType;
|
|
14
14
|
}({});
|
|
15
|
+
/** 电池信息 */
|
|
16
|
+
/** 设备信息 */
|
|
17
|
+
/** 内存信息 */
|
|
18
|
+
/** 网络信息 */
|
|
19
|
+
/** 操作系统信息 */
|
|
20
|
+
/** 存储信息 */
|
|
21
|
+
/**
|
|
22
|
+
* RUM 事件上下文,描述设备运行时的环境快照。
|
|
23
|
+
* 字段命名与 DataDog / Sentry 的 context 协议对齐,
|
|
24
|
+
* 各端(Android / iOS / Electron)按能力选择性填充。
|
|
25
|
+
*
|
|
26
|
+
* @see docs/内存信息采集方案.md
|
|
27
|
+
*/
|
|
15
28
|
/** 事件类型:页面浏览、性能指标、Web Vitals、自定义指标、会话回放 */
|
|
16
29
|
/**
|
|
17
30
|
* 枚举值,表示资源是否加载成功
|
|
@@ -29,4 +42,40 @@ var AppType = exports.AppType = /*#__PURE__*/function (AppType) {
|
|
|
29
42
|
AppType["uniapp"] = "uniapp";
|
|
30
43
|
AppType["reactnative"] = "reactnative";
|
|
31
44
|
return AppType;
|
|
32
|
-
}({});
|
|
45
|
+
}({});
|
|
46
|
+
/**
|
|
47
|
+
* 上报包中的应用信息
|
|
48
|
+
*
|
|
49
|
+
* @see {@link AppType} 应用类型枚举
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* 上报包中的用户信息
|
|
53
|
+
*
|
|
54
|
+
* @see {@link RumEventBundle} 上报数据包结构
|
|
55
|
+
*/
|
|
56
|
+
/** 上报包中的会话信息 */
|
|
57
|
+
/**
|
|
58
|
+
* 上报包中的页面信息
|
|
59
|
+
*
|
|
60
|
+
* @see {@link IViewData} 事件级页面数据结构
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* 上报包中的设备信息
|
|
64
|
+
*
|
|
65
|
+
* @see {@link DeviceContext} 运行时设备详细上下文
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* 上报包中的操作系统信息
|
|
69
|
+
*
|
|
70
|
+
* @see {@link OsContext} 运行时操作系统详细上下文
|
|
71
|
+
*/
|
|
72
|
+
/** 上报包中的地理位置信息(由服务端根据 IP 解析填充) */
|
|
73
|
+
/** 上报包中的运营商信息(由服务端根据 IP 解析填充) */
|
|
74
|
+
/** 上报包中的网络信息 */
|
|
75
|
+
/**
|
|
76
|
+
* RUM 上报数据包,将一批事件与公共上下文打包后发送至服务端。
|
|
77
|
+
*
|
|
78
|
+
* @see {@link RumEvent} 包内携带的事件列表
|
|
79
|
+
* @see {@link RumApp} 应用信息
|
|
80
|
+
* @see {@link RumUser} 用户信息
|
|
81
|
+
*/
|