@be-link/cls-logger 1.0.1-beta.11 → 1.0.1-beta.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 +63 -29
- package/dist/ClsLoggerCore.d.ts +3 -3
- package/dist/ClsLoggerCore.d.ts.map +1 -1
- package/dist/errorMonitor.d.ts.map +1 -1
- package/dist/index.esm.js +74 -5
- package/dist/index.js +74 -5
- package/dist/index.umd.js +74 -5
- package/dist/mini.esm.js +74 -5
- package/dist/mini.js +74 -5
- package/dist/performanceMonitor.d.ts.map +1 -1
- package/dist/web.esm.js +74 -5
- package/dist/web.js +74 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @be-link/cls-logger
|
|
2
2
|
|
|
3
|
-
腾讯云 CLS(`tencentcloud-cls-sdk-js-web
|
|
3
|
+
腾讯云 CLS(`tencentcloud-cls-sdk-js-web` / `tencentcloud-cls-sdk-js-mini`)日志上报封装,支持 Web、H5 和小程序环境,提供统一的调用方式。
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
@@ -8,58 +8,92 @@
|
|
|
8
8
|
pnpm add @be-link/cls-logger
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
> 依赖说明:本包依赖了腾讯云的 Web 和小程序 SDK。在使用时,内部会自动根据运行环境加载对应的 SDK。
|
|
12
|
+
|
|
11
13
|
## 使用
|
|
12
14
|
|
|
15
|
+
**统一引入方式**,无需关心运行环境(Web 或 小程序),SDK 内部会自动识别并适配。
|
|
16
|
+
|
|
13
17
|
```ts
|
|
14
|
-
import clsLogger
|
|
18
|
+
import clsLogger from '@be-link/cls-logger';
|
|
15
19
|
|
|
20
|
+
// 1. 初始化(建议在应用入口处调用)
|
|
16
21
|
clsLogger.init({
|
|
17
|
-
topic_id: 'xxx',
|
|
22
|
+
topic_id: 'xxx', // 你的 CLS Topic ID
|
|
18
23
|
projectName: 'my-project',
|
|
24
|
+
// 可选:环境信息(内部会自动采集,这里可以补充业务相关基础字段)
|
|
19
25
|
generateBaseFields: () => ({ env: 'prod', uid: 'u_1' }),
|
|
20
26
|
});
|
|
21
27
|
|
|
22
|
-
//
|
|
23
|
-
|
|
28
|
+
// 2. 日志上报
|
|
29
|
+
// Info 日志
|
|
30
|
+
clsLogger.info('应用启动', { startUpTime: 120 });
|
|
31
|
+
|
|
32
|
+
// Error 日志(支持直接传入 Error 对象,自动解析堆栈)
|
|
33
|
+
try {
|
|
34
|
+
doSomething();
|
|
35
|
+
} catch (err) {
|
|
36
|
+
clsLogger.error(err, { module: 'payment' });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 3. 自定义埋点 (Track)
|
|
40
|
+
clsLogger.track('click_event', {
|
|
41
|
+
button: 'submit',
|
|
42
|
+
page: '/home',
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 功能特性
|
|
47
|
+
|
|
48
|
+
### 1. 自动环境适配
|
|
49
|
+
|
|
50
|
+
- **Web / H5**: 自动加载 `tencentcloud-cls-sdk-js-web`,采集浏览器环境信息(UserAgent、Web Vitals 等)。
|
|
51
|
+
- **小程序**: 自动加载 `tencentcloud-cls-sdk-js-mini`,适配 `wx.request`,采集小程序环境信息(SystemInfo、NetworkType 等)。
|
|
52
|
+
|
|
53
|
+
### 2. 请求监控 (Request Monitor)
|
|
24
54
|
|
|
25
|
-
|
|
26
|
-
clsLogger.putJson({ event: 'click', x: 1, y: 2 });
|
|
55
|
+
默认开启 HTTP 请求监控。
|
|
27
56
|
|
|
28
|
-
|
|
29
|
-
|
|
57
|
+
- Web: 拦截 `fetch` / `XMLHttpRequest`
|
|
58
|
+
- 小程序: 拦截 `wx.request` / `wx.cloud.callFunction`
|
|
59
|
+
|
|
60
|
+
如需关闭或配置:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
clsLogger.init({
|
|
64
|
+
requestMonitor: {
|
|
65
|
+
enabled: true,
|
|
66
|
+
ignoreUrls: ['example.com', /login/], // 忽略特定 URL
|
|
67
|
+
},
|
|
68
|
+
});
|
|
30
69
|
```
|
|
31
70
|
|
|
32
|
-
|
|
71
|
+
### 3. 性能监控 (Performance Monitor)
|
|
72
|
+
|
|
73
|
+
默认开启性能指标采集。
|
|
74
|
+
|
|
75
|
+
- Web: 采集 FCP, LCP, CLS, FID 等 Core Web Vitals 及资源加载耗时。
|
|
76
|
+
- 小程序: 暂不支持性能指标自动采集。
|
|
33
77
|
|
|
34
|
-
|
|
78
|
+
### 4. 行为埋点 (Behavior Monitor)
|
|
35
79
|
|
|
36
|
-
|
|
37
|
-
- **忽略上报请求避免递归**:默认会忽略 CLS 上报域名(会把 `endpoint` 自动加入 `ignoreUrls`),并在内部增加了“上报发送”保护,避免上报请求在跨域失败时出现递归上报/死循环。
|
|
38
|
-
- **自定义忽略**:`clsLogger.init({ requestMonitor: { ignoreUrls: ['example.com', /\\/internal\\//] } })`
|
|
80
|
+
默认开启,支持 PV (Page View) 和 UV (User View) 自动上报。
|
|
39
81
|
|
|
40
|
-
|
|
82
|
+
- 自动生成/持久化 UV ID。
|
|
83
|
+
- 支持点击事件自动上报(需配置)。
|
|
41
84
|
|
|
42
|
-
|
|
85
|
+
## 高级用法
|
|
43
86
|
|
|
44
|
-
|
|
45
|
-
- **Navigation Timing**:TTFB 等
|
|
46
|
-
- **Resource Timing**:资源加载耗时(`PerformanceObserver({ type: 'resource', buffered: true })`,首屏会比较多)
|
|
87
|
+
### 手动注入 SDK
|
|
47
88
|
|
|
48
|
-
|
|
89
|
+
在某些特殊构建环境(如某些不允许动态 require 的小程序框架)下,如果自动加载 SDK 失败,可以手动注入:
|
|
49
90
|
|
|
50
91
|
```ts
|
|
51
92
|
import clsLogger from '@be-link/cls-logger';
|
|
93
|
+
import * as MiniSdk from 'tencentcloud-cls-sdk-js-mini';
|
|
52
94
|
|
|
53
95
|
clsLogger.init({
|
|
54
96
|
topic_id: 'xxx',
|
|
55
|
-
|
|
56
|
-
performanceMonitor: {
|
|
57
|
-
// 降低采样(0~1)
|
|
58
|
-
sampleRate: 0.1,
|
|
59
|
-
// 忽略本地开发资源 & sourcemap(按你的资源特征调整)
|
|
60
|
-
ignoreUrls: ['localhost:8080', /\\.map$/],
|
|
61
|
-
},
|
|
62
|
-
// 可选:启动阶段合并窗口,减少首屏 perf/resource 被 intervalMs 拆成多次上报
|
|
63
|
-
// batch: { startupDelayMs: 2000 },
|
|
97
|
+
sdk: MiniSdk, // 手动传入 SDK 实例
|
|
64
98
|
});
|
|
65
99
|
```
|
package/dist/ClsLoggerCore.d.ts
CHANGED
|
@@ -101,9 +101,9 @@ export declare abstract class ClsLoggerCore {
|
|
|
101
101
|
*/
|
|
102
102
|
report(log: ReportLog): void;
|
|
103
103
|
private getDesiredBatchFlushDueAt;
|
|
104
|
-
info(message: string, data?: FlatFields): void;
|
|
105
|
-
warn(message: string, data?: FlatFields): void;
|
|
106
|
-
error(message: string, data?: FlatFields): void;
|
|
104
|
+
info(message: string | Error, data?: FlatFields): void;
|
|
105
|
+
warn(message: string | Error, data?: FlatFields): void;
|
|
106
|
+
error(message: string | Error, data?: FlatFields): void;
|
|
107
107
|
track(trackType: string, data?: FlatFields): void;
|
|
108
108
|
/**
|
|
109
109
|
* 立即发送内存队列
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClsLoggerCore.d.ts","sourceRoot":"","sources":["../src/ClsLoggerCore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAEpB,OAAO,EACP,UAAU,EAEV,UAAU,EACV,SAAS,EACT,SAAS,EAEV,MAAM,SAAS,CAAC;AAgBjB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAYlD;;;;;GAKG;AACH,8BAAsB,aAAa;IACjC,SAAS,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAAQ;IAC1C,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC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AC,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE,UAAe,GAAG,IAAI;IASrD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBjC,OAAO,CAAC,iBAAiB;YAmBX,cAAc;IAgC5B,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,qBAAqB;IAc7B,WAAW,IAAI,IAAI;IAkBnB;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,IAAI;CAcjG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorMonitor.d.ts","sourceRoot":"","sources":["../src/errorMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG/D,KAAK,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"errorMonitor.d.ts","sourceRoot":"","sources":["../src/errorMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG/D,KAAK,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;AA8SzD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAE,OAAO,GAAG,mBAAmB,GAAG,SAAc,GAAG,IAAI,CAqBhH"}
|
package/dist/index.esm.js
CHANGED
|
@@ -558,6 +558,19 @@ function getPagePath$1() {
|
|
|
558
558
|
return '';
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
|
+
function getMpPagePath() {
|
|
562
|
+
try {
|
|
563
|
+
const pages = globalThis.getCurrentPages?.();
|
|
564
|
+
if (Array.isArray(pages) && pages.length > 0) {
|
|
565
|
+
const page = pages[pages.length - 1];
|
|
566
|
+
return page.route || page.__route__ || '';
|
|
567
|
+
}
|
|
568
|
+
return '';
|
|
569
|
+
}
|
|
570
|
+
catch {
|
|
571
|
+
return '';
|
|
572
|
+
}
|
|
573
|
+
}
|
|
561
574
|
function normalizeErrorLike(err, maxTextLength) {
|
|
562
575
|
if (err && typeof err === 'object') {
|
|
563
576
|
const anyErr = err;
|
|
@@ -717,6 +730,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
717
730
|
return;
|
|
718
731
|
const e = normalizeErrorLike(msg, options.maxTextLength);
|
|
719
732
|
const payload = {
|
|
733
|
+
pagePath: getMpPagePath(),
|
|
720
734
|
source: 'wx.onError',
|
|
721
735
|
message: e.message,
|
|
722
736
|
errorName: e.name,
|
|
@@ -743,6 +757,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
743
757
|
return;
|
|
744
758
|
const e = normalizeErrorLike(res?.reason, options.maxTextLength);
|
|
745
759
|
const payload = {
|
|
760
|
+
pagePath: getMpPagePath(),
|
|
746
761
|
source: 'wx.onUnhandledRejection',
|
|
747
762
|
message: e.message,
|
|
748
763
|
errorName: e.name,
|
|
@@ -774,6 +789,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
774
789
|
if (sampleHit$1(options.sampleRate)) {
|
|
775
790
|
const e = normalizeErrorLike(args?.[0], options.maxTextLength);
|
|
776
791
|
const payload = {
|
|
792
|
+
pagePath: getMpPagePath(),
|
|
777
793
|
source: 'App.onError',
|
|
778
794
|
message: e.message,
|
|
779
795
|
errorName: e.name,
|
|
@@ -797,6 +813,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
797
813
|
const reason = args?.[0]?.reason ?? args?.[0];
|
|
798
814
|
const e = normalizeErrorLike(reason, options.maxTextLength);
|
|
799
815
|
const payload = {
|
|
816
|
+
pagePath: getMpPagePath(),
|
|
800
817
|
source: 'App.onUnhandledRejection',
|
|
801
818
|
message: e.message,
|
|
802
819
|
errorName: e.name,
|
|
@@ -1104,18 +1121,28 @@ function installMiniProgramPerformanceMonitor(report, options) {
|
|
|
1104
1121
|
continue;
|
|
1105
1122
|
// Page Render: firstRender
|
|
1106
1123
|
if (entry.entryType === 'render' && entry.name === 'firstRender') {
|
|
1124
|
+
const duration = typeof entry.duration === 'number'
|
|
1125
|
+
? entry.duration
|
|
1126
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1127
|
+
? entry.endTime - entry.startTime
|
|
1128
|
+
: 0;
|
|
1107
1129
|
report(options.reportType, {
|
|
1108
1130
|
metric: 'page-render',
|
|
1109
|
-
duration
|
|
1131
|
+
duration,
|
|
1110
1132
|
pagePath: entry.path || '',
|
|
1111
1133
|
unit: 'ms',
|
|
1112
1134
|
});
|
|
1113
1135
|
}
|
|
1114
1136
|
// Route Switch: route
|
|
1115
1137
|
else if (entry.entryType === 'navigation' && entry.name === 'route') {
|
|
1138
|
+
const duration = typeof entry.duration === 'number'
|
|
1139
|
+
? entry.duration
|
|
1140
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1141
|
+
? entry.endTime - entry.startTime
|
|
1142
|
+
: 0;
|
|
1116
1143
|
report(options.reportType, {
|
|
1117
1144
|
metric: 'route',
|
|
1118
|
-
duration
|
|
1145
|
+
duration,
|
|
1119
1146
|
pagePath: entry.path || '',
|
|
1120
1147
|
unit: 'ms',
|
|
1121
1148
|
});
|
|
@@ -2269,15 +2296,57 @@ class ClsLoggerCore {
|
|
|
2269
2296
|
return nowTs + this.batchIntervalMs;
|
|
2270
2297
|
}
|
|
2271
2298
|
info(message, data = {}) {
|
|
2272
|
-
|
|
2299
|
+
let msg = '';
|
|
2300
|
+
let extra = {};
|
|
2301
|
+
if (message instanceof Error) {
|
|
2302
|
+
msg = message.message;
|
|
2303
|
+
extra = {
|
|
2304
|
+
stack: message.stack,
|
|
2305
|
+
name: message.name,
|
|
2306
|
+
...data,
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
else {
|
|
2310
|
+
msg = String(message);
|
|
2311
|
+
extra = data;
|
|
2312
|
+
}
|
|
2313
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'info');
|
|
2273
2314
|
this.report({ type: 'info', data: payload, timestamp: Date.now() });
|
|
2274
2315
|
}
|
|
2275
2316
|
warn(message, data = {}) {
|
|
2276
|
-
|
|
2317
|
+
let msg = '';
|
|
2318
|
+
let extra = {};
|
|
2319
|
+
if (message instanceof Error) {
|
|
2320
|
+
msg = message.message;
|
|
2321
|
+
extra = {
|
|
2322
|
+
stack: message.stack,
|
|
2323
|
+
name: message.name,
|
|
2324
|
+
...data,
|
|
2325
|
+
};
|
|
2326
|
+
}
|
|
2327
|
+
else {
|
|
2328
|
+
msg = String(message);
|
|
2329
|
+
extra = data;
|
|
2330
|
+
}
|
|
2331
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'warn');
|
|
2277
2332
|
this.report({ type: 'warn', data: payload, timestamp: Date.now() });
|
|
2278
2333
|
}
|
|
2279
2334
|
error(message, data = {}) {
|
|
2280
|
-
|
|
2335
|
+
let msg = '';
|
|
2336
|
+
let extra = {};
|
|
2337
|
+
if (message instanceof Error) {
|
|
2338
|
+
msg = message.message;
|
|
2339
|
+
extra = {
|
|
2340
|
+
stack: message.stack,
|
|
2341
|
+
name: message.name,
|
|
2342
|
+
...data,
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
else {
|
|
2346
|
+
msg = String(message);
|
|
2347
|
+
extra = data;
|
|
2348
|
+
}
|
|
2349
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'error');
|
|
2281
2350
|
this.report({ type: 'error', data: payload, timestamp: Date.now() });
|
|
2282
2351
|
}
|
|
2283
2352
|
track(trackType, data = {}) {
|
package/dist/index.js
CHANGED
|
@@ -562,6 +562,19 @@ function getPagePath$1() {
|
|
|
562
562
|
return '';
|
|
563
563
|
}
|
|
564
564
|
}
|
|
565
|
+
function getMpPagePath() {
|
|
566
|
+
try {
|
|
567
|
+
const pages = globalThis.getCurrentPages?.();
|
|
568
|
+
if (Array.isArray(pages) && pages.length > 0) {
|
|
569
|
+
const page = pages[pages.length - 1];
|
|
570
|
+
return page.route || page.__route__ || '';
|
|
571
|
+
}
|
|
572
|
+
return '';
|
|
573
|
+
}
|
|
574
|
+
catch {
|
|
575
|
+
return '';
|
|
576
|
+
}
|
|
577
|
+
}
|
|
565
578
|
function normalizeErrorLike(err, maxTextLength) {
|
|
566
579
|
if (err && typeof err === 'object') {
|
|
567
580
|
const anyErr = err;
|
|
@@ -721,6 +734,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
721
734
|
return;
|
|
722
735
|
const e = normalizeErrorLike(msg, options.maxTextLength);
|
|
723
736
|
const payload = {
|
|
737
|
+
pagePath: getMpPagePath(),
|
|
724
738
|
source: 'wx.onError',
|
|
725
739
|
message: e.message,
|
|
726
740
|
errorName: e.name,
|
|
@@ -747,6 +761,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
747
761
|
return;
|
|
748
762
|
const e = normalizeErrorLike(res?.reason, options.maxTextLength);
|
|
749
763
|
const payload = {
|
|
764
|
+
pagePath: getMpPagePath(),
|
|
750
765
|
source: 'wx.onUnhandledRejection',
|
|
751
766
|
message: e.message,
|
|
752
767
|
errorName: e.name,
|
|
@@ -778,6 +793,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
778
793
|
if (sampleHit$1(options.sampleRate)) {
|
|
779
794
|
const e = normalizeErrorLike(args?.[0], options.maxTextLength);
|
|
780
795
|
const payload = {
|
|
796
|
+
pagePath: getMpPagePath(),
|
|
781
797
|
source: 'App.onError',
|
|
782
798
|
message: e.message,
|
|
783
799
|
errorName: e.name,
|
|
@@ -801,6 +817,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
801
817
|
const reason = args?.[0]?.reason ?? args?.[0];
|
|
802
818
|
const e = normalizeErrorLike(reason, options.maxTextLength);
|
|
803
819
|
const payload = {
|
|
820
|
+
pagePath: getMpPagePath(),
|
|
804
821
|
source: 'App.onUnhandledRejection',
|
|
805
822
|
message: e.message,
|
|
806
823
|
errorName: e.name,
|
|
@@ -1108,18 +1125,28 @@ function installMiniProgramPerformanceMonitor(report, options) {
|
|
|
1108
1125
|
continue;
|
|
1109
1126
|
// Page Render: firstRender
|
|
1110
1127
|
if (entry.entryType === 'render' && entry.name === 'firstRender') {
|
|
1128
|
+
const duration = typeof entry.duration === 'number'
|
|
1129
|
+
? entry.duration
|
|
1130
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1131
|
+
? entry.endTime - entry.startTime
|
|
1132
|
+
: 0;
|
|
1111
1133
|
report(options.reportType, {
|
|
1112
1134
|
metric: 'page-render',
|
|
1113
|
-
duration
|
|
1135
|
+
duration,
|
|
1114
1136
|
pagePath: entry.path || '',
|
|
1115
1137
|
unit: 'ms',
|
|
1116
1138
|
});
|
|
1117
1139
|
}
|
|
1118
1140
|
// Route Switch: route
|
|
1119
1141
|
else if (entry.entryType === 'navigation' && entry.name === 'route') {
|
|
1142
|
+
const duration = typeof entry.duration === 'number'
|
|
1143
|
+
? entry.duration
|
|
1144
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1145
|
+
? entry.endTime - entry.startTime
|
|
1146
|
+
: 0;
|
|
1120
1147
|
report(options.reportType, {
|
|
1121
1148
|
metric: 'route',
|
|
1122
|
-
duration
|
|
1149
|
+
duration,
|
|
1123
1150
|
pagePath: entry.path || '',
|
|
1124
1151
|
unit: 'ms',
|
|
1125
1152
|
});
|
|
@@ -2273,15 +2300,57 @@ class ClsLoggerCore {
|
|
|
2273
2300
|
return nowTs + this.batchIntervalMs;
|
|
2274
2301
|
}
|
|
2275
2302
|
info(message, data = {}) {
|
|
2276
|
-
|
|
2303
|
+
let msg = '';
|
|
2304
|
+
let extra = {};
|
|
2305
|
+
if (message instanceof Error) {
|
|
2306
|
+
msg = message.message;
|
|
2307
|
+
extra = {
|
|
2308
|
+
stack: message.stack,
|
|
2309
|
+
name: message.name,
|
|
2310
|
+
...data,
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
else {
|
|
2314
|
+
msg = String(message);
|
|
2315
|
+
extra = data;
|
|
2316
|
+
}
|
|
2317
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'info');
|
|
2277
2318
|
this.report({ type: 'info', data: payload, timestamp: Date.now() });
|
|
2278
2319
|
}
|
|
2279
2320
|
warn(message, data = {}) {
|
|
2280
|
-
|
|
2321
|
+
let msg = '';
|
|
2322
|
+
let extra = {};
|
|
2323
|
+
if (message instanceof Error) {
|
|
2324
|
+
msg = message.message;
|
|
2325
|
+
extra = {
|
|
2326
|
+
stack: message.stack,
|
|
2327
|
+
name: message.name,
|
|
2328
|
+
...data,
|
|
2329
|
+
};
|
|
2330
|
+
}
|
|
2331
|
+
else {
|
|
2332
|
+
msg = String(message);
|
|
2333
|
+
extra = data;
|
|
2334
|
+
}
|
|
2335
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'warn');
|
|
2281
2336
|
this.report({ type: 'warn', data: payload, timestamp: Date.now() });
|
|
2282
2337
|
}
|
|
2283
2338
|
error(message, data = {}) {
|
|
2284
|
-
|
|
2339
|
+
let msg = '';
|
|
2340
|
+
let extra = {};
|
|
2341
|
+
if (message instanceof Error) {
|
|
2342
|
+
msg = message.message;
|
|
2343
|
+
extra = {
|
|
2344
|
+
stack: message.stack,
|
|
2345
|
+
name: message.name,
|
|
2346
|
+
...data,
|
|
2347
|
+
};
|
|
2348
|
+
}
|
|
2349
|
+
else {
|
|
2350
|
+
msg = String(message);
|
|
2351
|
+
extra = data;
|
|
2352
|
+
}
|
|
2353
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'error');
|
|
2285
2354
|
this.report({ type: 'error', data: payload, timestamp: Date.now() });
|
|
2286
2355
|
}
|
|
2287
2356
|
track(trackType, data = {}) {
|
package/dist/index.umd.js
CHANGED
|
@@ -564,6 +564,19 @@
|
|
|
564
564
|
return '';
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
|
+
function getMpPagePath() {
|
|
568
|
+
try {
|
|
569
|
+
const pages = globalThis.getCurrentPages?.();
|
|
570
|
+
if (Array.isArray(pages) && pages.length > 0) {
|
|
571
|
+
const page = pages[pages.length - 1];
|
|
572
|
+
return page.route || page.__route__ || '';
|
|
573
|
+
}
|
|
574
|
+
return '';
|
|
575
|
+
}
|
|
576
|
+
catch {
|
|
577
|
+
return '';
|
|
578
|
+
}
|
|
579
|
+
}
|
|
567
580
|
function normalizeErrorLike(err, maxTextLength) {
|
|
568
581
|
if (err && typeof err === 'object') {
|
|
569
582
|
const anyErr = err;
|
|
@@ -723,6 +736,7 @@
|
|
|
723
736
|
return;
|
|
724
737
|
const e = normalizeErrorLike(msg, options.maxTextLength);
|
|
725
738
|
const payload = {
|
|
739
|
+
pagePath: getMpPagePath(),
|
|
726
740
|
source: 'wx.onError',
|
|
727
741
|
message: e.message,
|
|
728
742
|
errorName: e.name,
|
|
@@ -749,6 +763,7 @@
|
|
|
749
763
|
return;
|
|
750
764
|
const e = normalizeErrorLike(res?.reason, options.maxTextLength);
|
|
751
765
|
const payload = {
|
|
766
|
+
pagePath: getMpPagePath(),
|
|
752
767
|
source: 'wx.onUnhandledRejection',
|
|
753
768
|
message: e.message,
|
|
754
769
|
errorName: e.name,
|
|
@@ -780,6 +795,7 @@
|
|
|
780
795
|
if (sampleHit$1(options.sampleRate)) {
|
|
781
796
|
const e = normalizeErrorLike(args?.[0], options.maxTextLength);
|
|
782
797
|
const payload = {
|
|
798
|
+
pagePath: getMpPagePath(),
|
|
783
799
|
source: 'App.onError',
|
|
784
800
|
message: e.message,
|
|
785
801
|
errorName: e.name,
|
|
@@ -803,6 +819,7 @@
|
|
|
803
819
|
const reason = args?.[0]?.reason ?? args?.[0];
|
|
804
820
|
const e = normalizeErrorLike(reason, options.maxTextLength);
|
|
805
821
|
const payload = {
|
|
822
|
+
pagePath: getMpPagePath(),
|
|
806
823
|
source: 'App.onUnhandledRejection',
|
|
807
824
|
message: e.message,
|
|
808
825
|
errorName: e.name,
|
|
@@ -1110,18 +1127,28 @@
|
|
|
1110
1127
|
continue;
|
|
1111
1128
|
// Page Render: firstRender
|
|
1112
1129
|
if (entry.entryType === 'render' && entry.name === 'firstRender') {
|
|
1130
|
+
const duration = typeof entry.duration === 'number'
|
|
1131
|
+
? entry.duration
|
|
1132
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1133
|
+
? entry.endTime - entry.startTime
|
|
1134
|
+
: 0;
|
|
1113
1135
|
report(options.reportType, {
|
|
1114
1136
|
metric: 'page-render',
|
|
1115
|
-
duration
|
|
1137
|
+
duration,
|
|
1116
1138
|
pagePath: entry.path || '',
|
|
1117
1139
|
unit: 'ms',
|
|
1118
1140
|
});
|
|
1119
1141
|
}
|
|
1120
1142
|
// Route Switch: route
|
|
1121
1143
|
else if (entry.entryType === 'navigation' && entry.name === 'route') {
|
|
1144
|
+
const duration = typeof entry.duration === 'number'
|
|
1145
|
+
? entry.duration
|
|
1146
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1147
|
+
? entry.endTime - entry.startTime
|
|
1148
|
+
: 0;
|
|
1122
1149
|
report(options.reportType, {
|
|
1123
1150
|
metric: 'route',
|
|
1124
|
-
duration
|
|
1151
|
+
duration,
|
|
1125
1152
|
pagePath: entry.path || '',
|
|
1126
1153
|
unit: 'ms',
|
|
1127
1154
|
});
|
|
@@ -2275,15 +2302,57 @@
|
|
|
2275
2302
|
return nowTs + this.batchIntervalMs;
|
|
2276
2303
|
}
|
|
2277
2304
|
info(message, data = {}) {
|
|
2278
|
-
|
|
2305
|
+
let msg = '';
|
|
2306
|
+
let extra = {};
|
|
2307
|
+
if (message instanceof Error) {
|
|
2308
|
+
msg = message.message;
|
|
2309
|
+
extra = {
|
|
2310
|
+
stack: message.stack,
|
|
2311
|
+
name: message.name,
|
|
2312
|
+
...data,
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2315
|
+
else {
|
|
2316
|
+
msg = String(message);
|
|
2317
|
+
extra = data;
|
|
2318
|
+
}
|
|
2319
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'info');
|
|
2279
2320
|
this.report({ type: 'info', data: payload, timestamp: Date.now() });
|
|
2280
2321
|
}
|
|
2281
2322
|
warn(message, data = {}) {
|
|
2282
|
-
|
|
2323
|
+
let msg = '';
|
|
2324
|
+
let extra = {};
|
|
2325
|
+
if (message instanceof Error) {
|
|
2326
|
+
msg = message.message;
|
|
2327
|
+
extra = {
|
|
2328
|
+
stack: message.stack,
|
|
2329
|
+
name: message.name,
|
|
2330
|
+
...data,
|
|
2331
|
+
};
|
|
2332
|
+
}
|
|
2333
|
+
else {
|
|
2334
|
+
msg = String(message);
|
|
2335
|
+
extra = data;
|
|
2336
|
+
}
|
|
2337
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'warn');
|
|
2283
2338
|
this.report({ type: 'warn', data: payload, timestamp: Date.now() });
|
|
2284
2339
|
}
|
|
2285
2340
|
error(message, data = {}) {
|
|
2286
|
-
|
|
2341
|
+
let msg = '';
|
|
2342
|
+
let extra = {};
|
|
2343
|
+
if (message instanceof Error) {
|
|
2344
|
+
msg = message.message;
|
|
2345
|
+
extra = {
|
|
2346
|
+
stack: message.stack,
|
|
2347
|
+
name: message.name,
|
|
2348
|
+
...data,
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
else {
|
|
2352
|
+
msg = String(message);
|
|
2353
|
+
extra = data;
|
|
2354
|
+
}
|
|
2355
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'error');
|
|
2287
2356
|
this.report({ type: 'error', data: payload, timestamp: Date.now() });
|
|
2288
2357
|
}
|
|
2289
2358
|
track(trackType, data = {}) {
|
package/dist/mini.esm.js
CHANGED
|
@@ -560,6 +560,19 @@ function getPagePath$1() {
|
|
|
560
560
|
return '';
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
|
+
function getMpPagePath() {
|
|
564
|
+
try {
|
|
565
|
+
const pages = globalThis.getCurrentPages?.();
|
|
566
|
+
if (Array.isArray(pages) && pages.length > 0) {
|
|
567
|
+
const page = pages[pages.length - 1];
|
|
568
|
+
return page.route || page.__route__ || '';
|
|
569
|
+
}
|
|
570
|
+
return '';
|
|
571
|
+
}
|
|
572
|
+
catch {
|
|
573
|
+
return '';
|
|
574
|
+
}
|
|
575
|
+
}
|
|
563
576
|
function normalizeErrorLike(err, maxTextLength) {
|
|
564
577
|
if (err && typeof err === 'object') {
|
|
565
578
|
const anyErr = err;
|
|
@@ -719,6 +732,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
719
732
|
return;
|
|
720
733
|
const e = normalizeErrorLike(msg, options.maxTextLength);
|
|
721
734
|
const payload = {
|
|
735
|
+
pagePath: getMpPagePath(),
|
|
722
736
|
source: 'wx.onError',
|
|
723
737
|
message: e.message,
|
|
724
738
|
errorName: e.name,
|
|
@@ -745,6 +759,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
745
759
|
return;
|
|
746
760
|
const e = normalizeErrorLike(res?.reason, options.maxTextLength);
|
|
747
761
|
const payload = {
|
|
762
|
+
pagePath: getMpPagePath(),
|
|
748
763
|
source: 'wx.onUnhandledRejection',
|
|
749
764
|
message: e.message,
|
|
750
765
|
errorName: e.name,
|
|
@@ -776,6 +791,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
776
791
|
if (sampleHit$1(options.sampleRate)) {
|
|
777
792
|
const e = normalizeErrorLike(args?.[0], options.maxTextLength);
|
|
778
793
|
const payload = {
|
|
794
|
+
pagePath: getMpPagePath(),
|
|
779
795
|
source: 'App.onError',
|
|
780
796
|
message: e.message,
|
|
781
797
|
errorName: e.name,
|
|
@@ -799,6 +815,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
799
815
|
const reason = args?.[0]?.reason ?? args?.[0];
|
|
800
816
|
const e = normalizeErrorLike(reason, options.maxTextLength);
|
|
801
817
|
const payload = {
|
|
818
|
+
pagePath: getMpPagePath(),
|
|
802
819
|
source: 'App.onUnhandledRejection',
|
|
803
820
|
message: e.message,
|
|
804
821
|
errorName: e.name,
|
|
@@ -1106,18 +1123,28 @@ function installMiniProgramPerformanceMonitor(report, options) {
|
|
|
1106
1123
|
continue;
|
|
1107
1124
|
// Page Render: firstRender
|
|
1108
1125
|
if (entry.entryType === 'render' && entry.name === 'firstRender') {
|
|
1126
|
+
const duration = typeof entry.duration === 'number'
|
|
1127
|
+
? entry.duration
|
|
1128
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1129
|
+
? entry.endTime - entry.startTime
|
|
1130
|
+
: 0;
|
|
1109
1131
|
report(options.reportType, {
|
|
1110
1132
|
metric: 'page-render',
|
|
1111
|
-
duration
|
|
1133
|
+
duration,
|
|
1112
1134
|
pagePath: entry.path || '',
|
|
1113
1135
|
unit: 'ms',
|
|
1114
1136
|
});
|
|
1115
1137
|
}
|
|
1116
1138
|
// Route Switch: route
|
|
1117
1139
|
else if (entry.entryType === 'navigation' && entry.name === 'route') {
|
|
1140
|
+
const duration = typeof entry.duration === 'number'
|
|
1141
|
+
? entry.duration
|
|
1142
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1143
|
+
? entry.endTime - entry.startTime
|
|
1144
|
+
: 0;
|
|
1118
1145
|
report(options.reportType, {
|
|
1119
1146
|
metric: 'route',
|
|
1120
|
-
duration
|
|
1147
|
+
duration,
|
|
1121
1148
|
pagePath: entry.path || '',
|
|
1122
1149
|
unit: 'ms',
|
|
1123
1150
|
});
|
|
@@ -2271,15 +2298,57 @@ class ClsLoggerCore {
|
|
|
2271
2298
|
return nowTs + this.batchIntervalMs;
|
|
2272
2299
|
}
|
|
2273
2300
|
info(message, data = {}) {
|
|
2274
|
-
|
|
2301
|
+
let msg = '';
|
|
2302
|
+
let extra = {};
|
|
2303
|
+
if (message instanceof Error) {
|
|
2304
|
+
msg = message.message;
|
|
2305
|
+
extra = {
|
|
2306
|
+
stack: message.stack,
|
|
2307
|
+
name: message.name,
|
|
2308
|
+
...data,
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
else {
|
|
2312
|
+
msg = String(message);
|
|
2313
|
+
extra = data;
|
|
2314
|
+
}
|
|
2315
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'info');
|
|
2275
2316
|
this.report({ type: 'info', data: payload, timestamp: Date.now() });
|
|
2276
2317
|
}
|
|
2277
2318
|
warn(message, data = {}) {
|
|
2278
|
-
|
|
2319
|
+
let msg = '';
|
|
2320
|
+
let extra = {};
|
|
2321
|
+
if (message instanceof Error) {
|
|
2322
|
+
msg = message.message;
|
|
2323
|
+
extra = {
|
|
2324
|
+
stack: message.stack,
|
|
2325
|
+
name: message.name,
|
|
2326
|
+
...data,
|
|
2327
|
+
};
|
|
2328
|
+
}
|
|
2329
|
+
else {
|
|
2330
|
+
msg = String(message);
|
|
2331
|
+
extra = data;
|
|
2332
|
+
}
|
|
2333
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'warn');
|
|
2279
2334
|
this.report({ type: 'warn', data: payload, timestamp: Date.now() });
|
|
2280
2335
|
}
|
|
2281
2336
|
error(message, data = {}) {
|
|
2282
|
-
|
|
2337
|
+
let msg = '';
|
|
2338
|
+
let extra = {};
|
|
2339
|
+
if (message instanceof Error) {
|
|
2340
|
+
msg = message.message;
|
|
2341
|
+
extra = {
|
|
2342
|
+
stack: message.stack,
|
|
2343
|
+
name: message.name,
|
|
2344
|
+
...data,
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
else {
|
|
2348
|
+
msg = String(message);
|
|
2349
|
+
extra = data;
|
|
2350
|
+
}
|
|
2351
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'error');
|
|
2283
2352
|
this.report({ type: 'error', data: payload, timestamp: Date.now() });
|
|
2284
2353
|
}
|
|
2285
2354
|
track(trackType, data = {}) {
|
package/dist/mini.js
CHANGED
|
@@ -583,6 +583,19 @@ function getPagePath$1() {
|
|
|
583
583
|
return '';
|
|
584
584
|
}
|
|
585
585
|
}
|
|
586
|
+
function getMpPagePath() {
|
|
587
|
+
try {
|
|
588
|
+
const pages = globalThis.getCurrentPages?.();
|
|
589
|
+
if (Array.isArray(pages) && pages.length > 0) {
|
|
590
|
+
const page = pages[pages.length - 1];
|
|
591
|
+
return page.route || page.__route__ || '';
|
|
592
|
+
}
|
|
593
|
+
return '';
|
|
594
|
+
}
|
|
595
|
+
catch {
|
|
596
|
+
return '';
|
|
597
|
+
}
|
|
598
|
+
}
|
|
586
599
|
function normalizeErrorLike(err, maxTextLength) {
|
|
587
600
|
if (err && typeof err === 'object') {
|
|
588
601
|
const anyErr = err;
|
|
@@ -742,6 +755,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
742
755
|
return;
|
|
743
756
|
const e = normalizeErrorLike(msg, options.maxTextLength);
|
|
744
757
|
const payload = {
|
|
758
|
+
pagePath: getMpPagePath(),
|
|
745
759
|
source: 'wx.onError',
|
|
746
760
|
message: e.message,
|
|
747
761
|
errorName: e.name,
|
|
@@ -768,6 +782,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
768
782
|
return;
|
|
769
783
|
const e = normalizeErrorLike(res?.reason, options.maxTextLength);
|
|
770
784
|
const payload = {
|
|
785
|
+
pagePath: getMpPagePath(),
|
|
771
786
|
source: 'wx.onUnhandledRejection',
|
|
772
787
|
message: e.message,
|
|
773
788
|
errorName: e.name,
|
|
@@ -799,6 +814,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
799
814
|
if (sampleHit$1(options.sampleRate)) {
|
|
800
815
|
const e = normalizeErrorLike(args?.[0], options.maxTextLength);
|
|
801
816
|
const payload = {
|
|
817
|
+
pagePath: getMpPagePath(),
|
|
802
818
|
source: 'App.onError',
|
|
803
819
|
message: e.message,
|
|
804
820
|
errorName: e.name,
|
|
@@ -822,6 +838,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
822
838
|
const reason = args?.[0]?.reason ?? args?.[0];
|
|
823
839
|
const e = normalizeErrorLike(reason, options.maxTextLength);
|
|
824
840
|
const payload = {
|
|
841
|
+
pagePath: getMpPagePath(),
|
|
825
842
|
source: 'App.onUnhandledRejection',
|
|
826
843
|
message: e.message,
|
|
827
844
|
errorName: e.name,
|
|
@@ -1129,18 +1146,28 @@ function installMiniProgramPerformanceMonitor(report, options) {
|
|
|
1129
1146
|
continue;
|
|
1130
1147
|
// Page Render: firstRender
|
|
1131
1148
|
if (entry.entryType === 'render' && entry.name === 'firstRender') {
|
|
1149
|
+
const duration = typeof entry.duration === 'number'
|
|
1150
|
+
? entry.duration
|
|
1151
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1152
|
+
? entry.endTime - entry.startTime
|
|
1153
|
+
: 0;
|
|
1132
1154
|
report(options.reportType, {
|
|
1133
1155
|
metric: 'page-render',
|
|
1134
|
-
duration
|
|
1156
|
+
duration,
|
|
1135
1157
|
pagePath: entry.path || '',
|
|
1136
1158
|
unit: 'ms',
|
|
1137
1159
|
});
|
|
1138
1160
|
}
|
|
1139
1161
|
// Route Switch: route
|
|
1140
1162
|
else if (entry.entryType === 'navigation' && entry.name === 'route') {
|
|
1163
|
+
const duration = typeof entry.duration === 'number'
|
|
1164
|
+
? entry.duration
|
|
1165
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1166
|
+
? entry.endTime - entry.startTime
|
|
1167
|
+
: 0;
|
|
1141
1168
|
report(options.reportType, {
|
|
1142
1169
|
metric: 'route',
|
|
1143
|
-
duration
|
|
1170
|
+
duration,
|
|
1144
1171
|
pagePath: entry.path || '',
|
|
1145
1172
|
unit: 'ms',
|
|
1146
1173
|
});
|
|
@@ -2294,15 +2321,57 @@ class ClsLoggerCore {
|
|
|
2294
2321
|
return nowTs + this.batchIntervalMs;
|
|
2295
2322
|
}
|
|
2296
2323
|
info(message, data = {}) {
|
|
2297
|
-
|
|
2324
|
+
let msg = '';
|
|
2325
|
+
let extra = {};
|
|
2326
|
+
if (message instanceof Error) {
|
|
2327
|
+
msg = message.message;
|
|
2328
|
+
extra = {
|
|
2329
|
+
stack: message.stack,
|
|
2330
|
+
name: message.name,
|
|
2331
|
+
...data,
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
else {
|
|
2335
|
+
msg = String(message);
|
|
2336
|
+
extra = data;
|
|
2337
|
+
}
|
|
2338
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'info');
|
|
2298
2339
|
this.report({ type: 'info', data: payload, timestamp: Date.now() });
|
|
2299
2340
|
}
|
|
2300
2341
|
warn(message, data = {}) {
|
|
2301
|
-
|
|
2342
|
+
let msg = '';
|
|
2343
|
+
let extra = {};
|
|
2344
|
+
if (message instanceof Error) {
|
|
2345
|
+
msg = message.message;
|
|
2346
|
+
extra = {
|
|
2347
|
+
stack: message.stack,
|
|
2348
|
+
name: message.name,
|
|
2349
|
+
...data,
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
else {
|
|
2353
|
+
msg = String(message);
|
|
2354
|
+
extra = data;
|
|
2355
|
+
}
|
|
2356
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'warn');
|
|
2302
2357
|
this.report({ type: 'warn', data: payload, timestamp: Date.now() });
|
|
2303
2358
|
}
|
|
2304
2359
|
error(message, data = {}) {
|
|
2305
|
-
|
|
2360
|
+
let msg = '';
|
|
2361
|
+
let extra = {};
|
|
2362
|
+
if (message instanceof Error) {
|
|
2363
|
+
msg = message.message;
|
|
2364
|
+
extra = {
|
|
2365
|
+
stack: message.stack,
|
|
2366
|
+
name: message.name,
|
|
2367
|
+
...data,
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
else {
|
|
2371
|
+
msg = String(message);
|
|
2372
|
+
extra = data;
|
|
2373
|
+
}
|
|
2374
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'error');
|
|
2306
2375
|
this.report({ type: 'error', data: payload, timestamp: Date.now() });
|
|
2307
2376
|
}
|
|
2308
2377
|
track(trackType, data = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceMonitor.d.ts","sourceRoot":"","sources":["../src/performanceMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAGrE,KAAK,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"performanceMonitor.d.ts","sourceRoot":"","sources":["../src/performanceMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAGrE,KAAK,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;AAqTzD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,QAAQ,EAChB,IAAI,GAAE,OAAO,GAAG,yBAAyB,GAAG,SAAc,GACzD,IAAI,CAsBN"}
|
package/dist/web.esm.js
CHANGED
|
@@ -560,6 +560,19 @@ function getPagePath$1() {
|
|
|
560
560
|
return '';
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
|
+
function getMpPagePath() {
|
|
564
|
+
try {
|
|
565
|
+
const pages = globalThis.getCurrentPages?.();
|
|
566
|
+
if (Array.isArray(pages) && pages.length > 0) {
|
|
567
|
+
const page = pages[pages.length - 1];
|
|
568
|
+
return page.route || page.__route__ || '';
|
|
569
|
+
}
|
|
570
|
+
return '';
|
|
571
|
+
}
|
|
572
|
+
catch {
|
|
573
|
+
return '';
|
|
574
|
+
}
|
|
575
|
+
}
|
|
563
576
|
function normalizeErrorLike(err, maxTextLength) {
|
|
564
577
|
if (err && typeof err === 'object') {
|
|
565
578
|
const anyErr = err;
|
|
@@ -719,6 +732,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
719
732
|
return;
|
|
720
733
|
const e = normalizeErrorLike(msg, options.maxTextLength);
|
|
721
734
|
const payload = {
|
|
735
|
+
pagePath: getMpPagePath(),
|
|
722
736
|
source: 'wx.onError',
|
|
723
737
|
message: e.message,
|
|
724
738
|
errorName: e.name,
|
|
@@ -745,6 +759,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
745
759
|
return;
|
|
746
760
|
const e = normalizeErrorLike(res?.reason, options.maxTextLength);
|
|
747
761
|
const payload = {
|
|
762
|
+
pagePath: getMpPagePath(),
|
|
748
763
|
source: 'wx.onUnhandledRejection',
|
|
749
764
|
message: e.message,
|
|
750
765
|
errorName: e.name,
|
|
@@ -776,6 +791,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
776
791
|
if (sampleHit$1(options.sampleRate)) {
|
|
777
792
|
const e = normalizeErrorLike(args?.[0], options.maxTextLength);
|
|
778
793
|
const payload = {
|
|
794
|
+
pagePath: getMpPagePath(),
|
|
779
795
|
source: 'App.onError',
|
|
780
796
|
message: e.message,
|
|
781
797
|
errorName: e.name,
|
|
@@ -799,6 +815,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
799
815
|
const reason = args?.[0]?.reason ?? args?.[0];
|
|
800
816
|
const e = normalizeErrorLike(reason, options.maxTextLength);
|
|
801
817
|
const payload = {
|
|
818
|
+
pagePath: getMpPagePath(),
|
|
802
819
|
source: 'App.onUnhandledRejection',
|
|
803
820
|
message: e.message,
|
|
804
821
|
errorName: e.name,
|
|
@@ -1106,18 +1123,28 @@ function installMiniProgramPerformanceMonitor(report, options) {
|
|
|
1106
1123
|
continue;
|
|
1107
1124
|
// Page Render: firstRender
|
|
1108
1125
|
if (entry.entryType === 'render' && entry.name === 'firstRender') {
|
|
1126
|
+
const duration = typeof entry.duration === 'number'
|
|
1127
|
+
? entry.duration
|
|
1128
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1129
|
+
? entry.endTime - entry.startTime
|
|
1130
|
+
: 0;
|
|
1109
1131
|
report(options.reportType, {
|
|
1110
1132
|
metric: 'page-render',
|
|
1111
|
-
duration
|
|
1133
|
+
duration,
|
|
1112
1134
|
pagePath: entry.path || '',
|
|
1113
1135
|
unit: 'ms',
|
|
1114
1136
|
});
|
|
1115
1137
|
}
|
|
1116
1138
|
// Route Switch: route
|
|
1117
1139
|
else if (entry.entryType === 'navigation' && entry.name === 'route') {
|
|
1140
|
+
const duration = typeof entry.duration === 'number'
|
|
1141
|
+
? entry.duration
|
|
1142
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1143
|
+
? entry.endTime - entry.startTime
|
|
1144
|
+
: 0;
|
|
1118
1145
|
report(options.reportType, {
|
|
1119
1146
|
metric: 'route',
|
|
1120
|
-
duration
|
|
1147
|
+
duration,
|
|
1121
1148
|
pagePath: entry.path || '',
|
|
1122
1149
|
unit: 'ms',
|
|
1123
1150
|
});
|
|
@@ -2271,15 +2298,57 @@ class ClsLoggerCore {
|
|
|
2271
2298
|
return nowTs + this.batchIntervalMs;
|
|
2272
2299
|
}
|
|
2273
2300
|
info(message, data = {}) {
|
|
2274
|
-
|
|
2301
|
+
let msg = '';
|
|
2302
|
+
let extra = {};
|
|
2303
|
+
if (message instanceof Error) {
|
|
2304
|
+
msg = message.message;
|
|
2305
|
+
extra = {
|
|
2306
|
+
stack: message.stack,
|
|
2307
|
+
name: message.name,
|
|
2308
|
+
...data,
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
else {
|
|
2312
|
+
msg = String(message);
|
|
2313
|
+
extra = data;
|
|
2314
|
+
}
|
|
2315
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'info');
|
|
2275
2316
|
this.report({ type: 'info', data: payload, timestamp: Date.now() });
|
|
2276
2317
|
}
|
|
2277
2318
|
warn(message, data = {}) {
|
|
2278
|
-
|
|
2319
|
+
let msg = '';
|
|
2320
|
+
let extra = {};
|
|
2321
|
+
if (message instanceof Error) {
|
|
2322
|
+
msg = message.message;
|
|
2323
|
+
extra = {
|
|
2324
|
+
stack: message.stack,
|
|
2325
|
+
name: message.name,
|
|
2326
|
+
...data,
|
|
2327
|
+
};
|
|
2328
|
+
}
|
|
2329
|
+
else {
|
|
2330
|
+
msg = String(message);
|
|
2331
|
+
extra = data;
|
|
2332
|
+
}
|
|
2333
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'warn');
|
|
2279
2334
|
this.report({ type: 'warn', data: payload, timestamp: Date.now() });
|
|
2280
2335
|
}
|
|
2281
2336
|
error(message, data = {}) {
|
|
2282
|
-
|
|
2337
|
+
let msg = '';
|
|
2338
|
+
let extra = {};
|
|
2339
|
+
if (message instanceof Error) {
|
|
2340
|
+
msg = message.message;
|
|
2341
|
+
extra = {
|
|
2342
|
+
stack: message.stack,
|
|
2343
|
+
name: message.name,
|
|
2344
|
+
...data,
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
else {
|
|
2348
|
+
msg = String(message);
|
|
2349
|
+
extra = data;
|
|
2350
|
+
}
|
|
2351
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'error');
|
|
2283
2352
|
this.report({ type: 'error', data: payload, timestamp: Date.now() });
|
|
2284
2353
|
}
|
|
2285
2354
|
track(trackType, data = {}) {
|
package/dist/web.js
CHANGED
|
@@ -583,6 +583,19 @@ function getPagePath$1() {
|
|
|
583
583
|
return '';
|
|
584
584
|
}
|
|
585
585
|
}
|
|
586
|
+
function getMpPagePath() {
|
|
587
|
+
try {
|
|
588
|
+
const pages = globalThis.getCurrentPages?.();
|
|
589
|
+
if (Array.isArray(pages) && pages.length > 0) {
|
|
590
|
+
const page = pages[pages.length - 1];
|
|
591
|
+
return page.route || page.__route__ || '';
|
|
592
|
+
}
|
|
593
|
+
return '';
|
|
594
|
+
}
|
|
595
|
+
catch {
|
|
596
|
+
return '';
|
|
597
|
+
}
|
|
598
|
+
}
|
|
586
599
|
function normalizeErrorLike(err, maxTextLength) {
|
|
587
600
|
if (err && typeof err === 'object') {
|
|
588
601
|
const anyErr = err;
|
|
@@ -742,6 +755,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
742
755
|
return;
|
|
743
756
|
const e = normalizeErrorLike(msg, options.maxTextLength);
|
|
744
757
|
const payload = {
|
|
758
|
+
pagePath: getMpPagePath(),
|
|
745
759
|
source: 'wx.onError',
|
|
746
760
|
message: e.message,
|
|
747
761
|
errorName: e.name,
|
|
@@ -768,6 +782,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
768
782
|
return;
|
|
769
783
|
const e = normalizeErrorLike(res?.reason, options.maxTextLength);
|
|
770
784
|
const payload = {
|
|
785
|
+
pagePath: getMpPagePath(),
|
|
771
786
|
source: 'wx.onUnhandledRejection',
|
|
772
787
|
message: e.message,
|
|
773
788
|
errorName: e.name,
|
|
@@ -799,6 +814,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
799
814
|
if (sampleHit$1(options.sampleRate)) {
|
|
800
815
|
const e = normalizeErrorLike(args?.[0], options.maxTextLength);
|
|
801
816
|
const payload = {
|
|
817
|
+
pagePath: getMpPagePath(),
|
|
802
818
|
source: 'App.onError',
|
|
803
819
|
message: e.message,
|
|
804
820
|
errorName: e.name,
|
|
@@ -822,6 +838,7 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
822
838
|
const reason = args?.[0]?.reason ?? args?.[0];
|
|
823
839
|
const e = normalizeErrorLike(reason, options.maxTextLength);
|
|
824
840
|
const payload = {
|
|
841
|
+
pagePath: getMpPagePath(),
|
|
825
842
|
source: 'App.onUnhandledRejection',
|
|
826
843
|
message: e.message,
|
|
827
844
|
errorName: e.name,
|
|
@@ -1129,18 +1146,28 @@ function installMiniProgramPerformanceMonitor(report, options) {
|
|
|
1129
1146
|
continue;
|
|
1130
1147
|
// Page Render: firstRender
|
|
1131
1148
|
if (entry.entryType === 'render' && entry.name === 'firstRender') {
|
|
1149
|
+
const duration = typeof entry.duration === 'number'
|
|
1150
|
+
? entry.duration
|
|
1151
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1152
|
+
? entry.endTime - entry.startTime
|
|
1153
|
+
: 0;
|
|
1132
1154
|
report(options.reportType, {
|
|
1133
1155
|
metric: 'page-render',
|
|
1134
|
-
duration
|
|
1156
|
+
duration,
|
|
1135
1157
|
pagePath: entry.path || '',
|
|
1136
1158
|
unit: 'ms',
|
|
1137
1159
|
});
|
|
1138
1160
|
}
|
|
1139
1161
|
// Route Switch: route
|
|
1140
1162
|
else if (entry.entryType === 'navigation' && entry.name === 'route') {
|
|
1163
|
+
const duration = typeof entry.duration === 'number'
|
|
1164
|
+
? entry.duration
|
|
1165
|
+
: typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
|
|
1166
|
+
? entry.endTime - entry.startTime
|
|
1167
|
+
: 0;
|
|
1141
1168
|
report(options.reportType, {
|
|
1142
1169
|
metric: 'route',
|
|
1143
|
-
duration
|
|
1170
|
+
duration,
|
|
1144
1171
|
pagePath: entry.path || '',
|
|
1145
1172
|
unit: 'ms',
|
|
1146
1173
|
});
|
|
@@ -2294,15 +2321,57 @@ class ClsLoggerCore {
|
|
|
2294
2321
|
return nowTs + this.batchIntervalMs;
|
|
2295
2322
|
}
|
|
2296
2323
|
info(message, data = {}) {
|
|
2297
|
-
|
|
2324
|
+
let msg = '';
|
|
2325
|
+
let extra = {};
|
|
2326
|
+
if (message instanceof Error) {
|
|
2327
|
+
msg = message.message;
|
|
2328
|
+
extra = {
|
|
2329
|
+
stack: message.stack,
|
|
2330
|
+
name: message.name,
|
|
2331
|
+
...data,
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
else {
|
|
2335
|
+
msg = String(message);
|
|
2336
|
+
extra = data;
|
|
2337
|
+
}
|
|
2338
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'info');
|
|
2298
2339
|
this.report({ type: 'info', data: payload, timestamp: Date.now() });
|
|
2299
2340
|
}
|
|
2300
2341
|
warn(message, data = {}) {
|
|
2301
|
-
|
|
2342
|
+
let msg = '';
|
|
2343
|
+
let extra = {};
|
|
2344
|
+
if (message instanceof Error) {
|
|
2345
|
+
msg = message.message;
|
|
2346
|
+
extra = {
|
|
2347
|
+
stack: message.stack,
|
|
2348
|
+
name: message.name,
|
|
2349
|
+
...data,
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
else {
|
|
2353
|
+
msg = String(message);
|
|
2354
|
+
extra = data;
|
|
2355
|
+
}
|
|
2356
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'warn');
|
|
2302
2357
|
this.report({ type: 'warn', data: payload, timestamp: Date.now() });
|
|
2303
2358
|
}
|
|
2304
2359
|
error(message, data = {}) {
|
|
2305
|
-
|
|
2360
|
+
let msg = '';
|
|
2361
|
+
let extra = {};
|
|
2362
|
+
if (message instanceof Error) {
|
|
2363
|
+
msg = message.message;
|
|
2364
|
+
extra = {
|
|
2365
|
+
stack: message.stack,
|
|
2366
|
+
name: message.name,
|
|
2367
|
+
...data,
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
else {
|
|
2371
|
+
msg = String(message);
|
|
2372
|
+
extra = data;
|
|
2373
|
+
}
|
|
2374
|
+
const payload = normalizeFlatFields({ message: msg, ...extra }, 'error');
|
|
2306
2375
|
this.report({ type: 'error', data: payload, timestamp: Date.now() });
|
|
2307
2376
|
}
|
|
2308
2377
|
track(trackType, data = {}) {
|