@be-link/cls-logger 1.0.1-beta.7 → 1.0.1-beta.9
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/dist/ClsLoggerCore.d.ts.map +1 -1
- package/dist/errorMonitor.d.ts.map +1 -1
- package/dist/index.esm.js +61 -127
- package/dist/index.js +61 -127
- package/dist/index.umd.js +61 -127
- package/dist/mini.esm.js +61 -127
- package/dist/mini.js +61 -127
- package/dist/performanceMonitor.d.ts.map +1 -1
- package/dist/web.esm.js +61 -127
- package/dist/web.js +61 -127
- package/package.json +1 -1
|
@@ -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,GAAG,IAAI,CAAQ;IAC1D,SAAS,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAAQ;IAC7C,SAAS,CAAC,iBAAiB,EAAE,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAQ;IAC9E,SAAS,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI,CAAQ;IAC9F,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO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;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;AA6RzD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAE,OAAO,GAAG,mBAAmB,GAAG,SAAc,GAAG,IAAI,CAqBhH"}
|
package/dist/index.esm.js
CHANGED
|
@@ -561,7 +561,17 @@ function getPagePath$1() {
|
|
|
561
561
|
function normalizeErrorLike(err, maxTextLength) {
|
|
562
562
|
if (err && typeof err === 'object') {
|
|
563
563
|
const anyErr = err;
|
|
564
|
-
|
|
564
|
+
let rawMsg = anyErr.message;
|
|
565
|
+
if (!rawMsg) {
|
|
566
|
+
const str = anyErr.toString?.();
|
|
567
|
+
if (!str || str === '[object Object]') {
|
|
568
|
+
rawMsg = stringifyLogValue(anyErr);
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
rawMsg = str;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const message = truncate$2(String(rawMsg ?? ''), maxTextLength);
|
|
565
575
|
const name = truncate$2(String(anyErr.name ?? ''), 200);
|
|
566
576
|
const stack = truncate$2(String(anyErr.stack ?? ''), maxTextLength);
|
|
567
577
|
return { message, name, stack };
|
|
@@ -705,9 +715,12 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
705
715
|
try {
|
|
706
716
|
if (!sampleHit$1(options.sampleRate))
|
|
707
717
|
return;
|
|
718
|
+
const e = normalizeErrorLike(msg, options.maxTextLength);
|
|
708
719
|
const payload = {
|
|
709
720
|
source: 'wx.onError',
|
|
710
|
-
message:
|
|
721
|
+
message: e.message,
|
|
722
|
+
errorName: e.name,
|
|
723
|
+
stack: e.stack,
|
|
711
724
|
};
|
|
712
725
|
if (!shouldReport(buildErrorKey(options.reportType, payload)))
|
|
713
726
|
return;
|
|
@@ -759,9 +772,12 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
759
772
|
next.onError = function (...args) {
|
|
760
773
|
try {
|
|
761
774
|
if (sampleHit$1(options.sampleRate)) {
|
|
775
|
+
const e = normalizeErrorLike(args?.[0], options.maxTextLength);
|
|
762
776
|
const payload = {
|
|
763
777
|
source: 'App.onError',
|
|
764
|
-
message:
|
|
778
|
+
message: e.message,
|
|
779
|
+
errorName: e.name,
|
|
780
|
+
stack: e.stack,
|
|
765
781
|
};
|
|
766
782
|
if (shouldReport(buildErrorKey(options.reportType, payload)))
|
|
767
783
|
report(options.reportType, payload);
|
|
@@ -1068,140 +1084,58 @@ function installBrowserPerformanceMonitor(report, options) {
|
|
|
1068
1084
|
}
|
|
1069
1085
|
}
|
|
1070
1086
|
}
|
|
1071
|
-
function wrapMiniProgramRouteApi(report, reportType, apiName, options) {
|
|
1072
|
-
const wxAny = globalThis.wx;
|
|
1073
|
-
if (!wxAny || typeof wxAny[apiName] !== 'function')
|
|
1074
|
-
return;
|
|
1075
|
-
const flagKey = `__beLinkClsLoggerMpRouteWrapped__${apiName}`;
|
|
1076
|
-
if (wxAny[flagKey])
|
|
1077
|
-
return;
|
|
1078
|
-
wxAny[flagKey] = true;
|
|
1079
|
-
const raw = wxAny[apiName].bind(wxAny);
|
|
1080
|
-
wxAny[apiName] = (opts) => {
|
|
1081
|
-
const start = Date.now();
|
|
1082
|
-
const url = opts?.url ? String(opts.url) : '';
|
|
1083
|
-
const wrapCb = (cb, success) => {
|
|
1084
|
-
return (...args) => {
|
|
1085
|
-
try {
|
|
1086
|
-
if (sampleHit(options.sampleRate)) {
|
|
1087
|
-
report(reportType, {
|
|
1088
|
-
metric: 'route',
|
|
1089
|
-
api: apiName,
|
|
1090
|
-
url,
|
|
1091
|
-
duration: Date.now() - start,
|
|
1092
|
-
success: success ? 1 : 0,
|
|
1093
|
-
error: success ? '' : truncate$1(stringifyLogValue(args?.[0]), options.maxTextLength),
|
|
1094
|
-
unit: 'ms',
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
catch {
|
|
1099
|
-
// ignore
|
|
1100
|
-
}
|
|
1101
|
-
if (typeof cb === 'function')
|
|
1102
|
-
return cb(...args);
|
|
1103
|
-
return undefined;
|
|
1104
|
-
};
|
|
1105
|
-
};
|
|
1106
|
-
const next = { ...(opts ?? {}) };
|
|
1107
|
-
next.success = wrapCb(next.success, true);
|
|
1108
|
-
next.fail = wrapCb(next.fail, false);
|
|
1109
|
-
return raw(next);
|
|
1110
|
-
};
|
|
1111
|
-
}
|
|
1112
|
-
function installMiniProgramPageRenderMonitor(report, reportType, options) {
|
|
1113
|
-
const g = globalThis;
|
|
1114
|
-
if (typeof g.Page !== 'function')
|
|
1115
|
-
return;
|
|
1116
|
-
if (g.__beLinkClsLoggerPageWrapped__)
|
|
1117
|
-
return;
|
|
1118
|
-
g.__beLinkClsLoggerPageWrapped__ = true;
|
|
1119
|
-
const rawPage = g.Page;
|
|
1120
|
-
g.Page = (pageOptions) => {
|
|
1121
|
-
const next = { ...(pageOptions ?? {}) };
|
|
1122
|
-
const rawOnLoad = next.onLoad;
|
|
1123
|
-
const rawOnReady = next.onReady;
|
|
1124
|
-
next.onLoad = function (...args) {
|
|
1125
|
-
try {
|
|
1126
|
-
this.__beLinkClsLoggerPageLoadTs__ = Date.now();
|
|
1127
|
-
}
|
|
1128
|
-
catch {
|
|
1129
|
-
// ignore
|
|
1130
|
-
}
|
|
1131
|
-
if (typeof rawOnLoad === 'function')
|
|
1132
|
-
return rawOnLoad.apply(this, args);
|
|
1133
|
-
return undefined;
|
|
1134
|
-
};
|
|
1135
|
-
next.onReady = function (...args) {
|
|
1136
|
-
try {
|
|
1137
|
-
const start = this.__beLinkClsLoggerPageLoadTs__;
|
|
1138
|
-
if (typeof start === 'number' && sampleHit(options.sampleRate)) {
|
|
1139
|
-
report(reportType, {
|
|
1140
|
-
metric: 'page-render',
|
|
1141
|
-
route: this?.route ? String(this.route) : '',
|
|
1142
|
-
duration: Date.now() - start,
|
|
1143
|
-
unit: 'ms',
|
|
1144
|
-
});
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
catch {
|
|
1148
|
-
// ignore
|
|
1149
|
-
}
|
|
1150
|
-
if (typeof rawOnReady === 'function')
|
|
1151
|
-
return rawOnReady.apply(this, args);
|
|
1152
|
-
return undefined;
|
|
1153
|
-
};
|
|
1154
|
-
return rawPage(next);
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
1087
|
function installMiniProgramPerformanceMonitor(report, options) {
|
|
1158
1088
|
const g = globalThis;
|
|
1089
|
+
const ctx = g.wx || g.Taro;
|
|
1090
|
+
if (!ctx || typeof ctx.getPerformance !== 'function')
|
|
1091
|
+
return;
|
|
1159
1092
|
if (g.__beLinkClsLoggerMpPerfInstalled__)
|
|
1160
1093
|
return;
|
|
1161
1094
|
g.__beLinkClsLoggerMpPerfInstalled__ = true;
|
|
1162
|
-
// 路由切换耗时(用 API 回调近似)
|
|
1163
|
-
for (const apiName of ['navigateTo', 'redirectTo', 'switchTab', 'reLaunch']) {
|
|
1164
|
-
try {
|
|
1165
|
-
wrapMiniProgramRouteApi(report, options.reportType, apiName, options);
|
|
1166
|
-
}
|
|
1167
|
-
catch {
|
|
1168
|
-
// ignore
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
// 页面渲染耗时(onLoad -> onReady)
|
|
1172
|
-
try {
|
|
1173
|
-
installMiniProgramPageRenderMonitor(report, options.reportType, options);
|
|
1174
|
-
}
|
|
1175
|
-
catch {
|
|
1176
|
-
// ignore
|
|
1177
|
-
}
|
|
1178
|
-
// wx.getPerformance()(若可用,尝试读取已有 entries)
|
|
1179
1095
|
try {
|
|
1180
|
-
const
|
|
1181
|
-
if (
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
: typeof perf.getEntriesByType === 'function'
|
|
1192
|
-
? perf.getEntriesByType('navigation')
|
|
1193
|
-
: [];
|
|
1096
|
+
const perf = ctx.getPerformance();
|
|
1097
|
+
if (!perf || typeof perf.createObserver !== 'function')
|
|
1098
|
+
return;
|
|
1099
|
+
const observer = perf.createObserver((entryList) => {
|
|
1100
|
+
try {
|
|
1101
|
+
const entries = entryList.getEntries();
|
|
1102
|
+
for (const entry of entries) {
|
|
1103
|
+
if (!sampleHit(options.sampleRate))
|
|
1104
|
+
continue;
|
|
1105
|
+
// Page Render: firstRender
|
|
1106
|
+
if (entry.entryType === 'render' && entry.name === 'firstRender') {
|
|
1194
1107
|
report(options.reportType, {
|
|
1195
|
-
metric: '
|
|
1196
|
-
|
|
1108
|
+
metric: 'page-render',
|
|
1109
|
+
duration: entry.duration,
|
|
1110
|
+
pagePath: entry.path || '',
|
|
1111
|
+
unit: 'ms',
|
|
1197
1112
|
});
|
|
1198
1113
|
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1114
|
+
// Route Switch: route
|
|
1115
|
+
else if (entry.entryType === 'navigation' && entry.name === 'route') {
|
|
1116
|
+
report(options.reportType, {
|
|
1117
|
+
metric: 'route',
|
|
1118
|
+
duration: entry.duration,
|
|
1119
|
+
pagePath: entry.path || '',
|
|
1120
|
+
unit: 'ms',
|
|
1121
|
+
});
|
|
1201
1122
|
}
|
|
1202
|
-
|
|
1123
|
+
// App Launch: appLaunch (Cold)
|
|
1124
|
+
else if (entry.entryType === 'navigation' && entry.name === 'appLaunch') {
|
|
1125
|
+
report(options.reportType, {
|
|
1126
|
+
metric: 'app-launch',
|
|
1127
|
+
duration: entry.duration,
|
|
1128
|
+
launchType: 'cold',
|
|
1129
|
+
unit: 'ms',
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1203
1133
|
}
|
|
1204
|
-
|
|
1134
|
+
catch {
|
|
1135
|
+
// ignore
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
1138
|
+
observer.observe({ entryTypes: ['navigation', 'render'] });
|
|
1205
1139
|
}
|
|
1206
1140
|
catch {
|
|
1207
1141
|
// ignore
|
|
@@ -2031,7 +1965,7 @@ class ClsLoggerCore {
|
|
|
2031
1965
|
try {
|
|
2032
1966
|
const userRaw = this.userGenerateBaseFields ? this.userGenerateBaseFields() : undefined;
|
|
2033
1967
|
if (userRaw && isPlainObject(userRaw))
|
|
2034
|
-
user = normalizeFlatFields({ ...userRaw
|
|
1968
|
+
user = normalizeFlatFields({ ...userRaw }, 'generateBaseFields');
|
|
2035
1969
|
}
|
|
2036
1970
|
catch {
|
|
2037
1971
|
user = undefined;
|
package/dist/index.js
CHANGED
|
@@ -565,7 +565,17 @@ function getPagePath$1() {
|
|
|
565
565
|
function normalizeErrorLike(err, maxTextLength) {
|
|
566
566
|
if (err && typeof err === 'object') {
|
|
567
567
|
const anyErr = err;
|
|
568
|
-
|
|
568
|
+
let rawMsg = anyErr.message;
|
|
569
|
+
if (!rawMsg) {
|
|
570
|
+
const str = anyErr.toString?.();
|
|
571
|
+
if (!str || str === '[object Object]') {
|
|
572
|
+
rawMsg = stringifyLogValue(anyErr);
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
rawMsg = str;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
const message = truncate$2(String(rawMsg ?? ''), maxTextLength);
|
|
569
579
|
const name = truncate$2(String(anyErr.name ?? ''), 200);
|
|
570
580
|
const stack = truncate$2(String(anyErr.stack ?? ''), maxTextLength);
|
|
571
581
|
return { message, name, stack };
|
|
@@ -709,9 +719,12 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
709
719
|
try {
|
|
710
720
|
if (!sampleHit$1(options.sampleRate))
|
|
711
721
|
return;
|
|
722
|
+
const e = normalizeErrorLike(msg, options.maxTextLength);
|
|
712
723
|
const payload = {
|
|
713
724
|
source: 'wx.onError',
|
|
714
|
-
message:
|
|
725
|
+
message: e.message,
|
|
726
|
+
errorName: e.name,
|
|
727
|
+
stack: e.stack,
|
|
715
728
|
};
|
|
716
729
|
if (!shouldReport(buildErrorKey(options.reportType, payload)))
|
|
717
730
|
return;
|
|
@@ -763,9 +776,12 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
763
776
|
next.onError = function (...args) {
|
|
764
777
|
try {
|
|
765
778
|
if (sampleHit$1(options.sampleRate)) {
|
|
779
|
+
const e = normalizeErrorLike(args?.[0], options.maxTextLength);
|
|
766
780
|
const payload = {
|
|
767
781
|
source: 'App.onError',
|
|
768
|
-
message:
|
|
782
|
+
message: e.message,
|
|
783
|
+
errorName: e.name,
|
|
784
|
+
stack: e.stack,
|
|
769
785
|
};
|
|
770
786
|
if (shouldReport(buildErrorKey(options.reportType, payload)))
|
|
771
787
|
report(options.reportType, payload);
|
|
@@ -1072,140 +1088,58 @@ function installBrowserPerformanceMonitor(report, options) {
|
|
|
1072
1088
|
}
|
|
1073
1089
|
}
|
|
1074
1090
|
}
|
|
1075
|
-
function wrapMiniProgramRouteApi(report, reportType, apiName, options) {
|
|
1076
|
-
const wxAny = globalThis.wx;
|
|
1077
|
-
if (!wxAny || typeof wxAny[apiName] !== 'function')
|
|
1078
|
-
return;
|
|
1079
|
-
const flagKey = `__beLinkClsLoggerMpRouteWrapped__${apiName}`;
|
|
1080
|
-
if (wxAny[flagKey])
|
|
1081
|
-
return;
|
|
1082
|
-
wxAny[flagKey] = true;
|
|
1083
|
-
const raw = wxAny[apiName].bind(wxAny);
|
|
1084
|
-
wxAny[apiName] = (opts) => {
|
|
1085
|
-
const start = Date.now();
|
|
1086
|
-
const url = opts?.url ? String(opts.url) : '';
|
|
1087
|
-
const wrapCb = (cb, success) => {
|
|
1088
|
-
return (...args) => {
|
|
1089
|
-
try {
|
|
1090
|
-
if (sampleHit(options.sampleRate)) {
|
|
1091
|
-
report(reportType, {
|
|
1092
|
-
metric: 'route',
|
|
1093
|
-
api: apiName,
|
|
1094
|
-
url,
|
|
1095
|
-
duration: Date.now() - start,
|
|
1096
|
-
success: success ? 1 : 0,
|
|
1097
|
-
error: success ? '' : truncate$1(stringifyLogValue(args?.[0]), options.maxTextLength),
|
|
1098
|
-
unit: 'ms',
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
catch {
|
|
1103
|
-
// ignore
|
|
1104
|
-
}
|
|
1105
|
-
if (typeof cb === 'function')
|
|
1106
|
-
return cb(...args);
|
|
1107
|
-
return undefined;
|
|
1108
|
-
};
|
|
1109
|
-
};
|
|
1110
|
-
const next = { ...(opts ?? {}) };
|
|
1111
|
-
next.success = wrapCb(next.success, true);
|
|
1112
|
-
next.fail = wrapCb(next.fail, false);
|
|
1113
|
-
return raw(next);
|
|
1114
|
-
};
|
|
1115
|
-
}
|
|
1116
|
-
function installMiniProgramPageRenderMonitor(report, reportType, options) {
|
|
1117
|
-
const g = globalThis;
|
|
1118
|
-
if (typeof g.Page !== 'function')
|
|
1119
|
-
return;
|
|
1120
|
-
if (g.__beLinkClsLoggerPageWrapped__)
|
|
1121
|
-
return;
|
|
1122
|
-
g.__beLinkClsLoggerPageWrapped__ = true;
|
|
1123
|
-
const rawPage = g.Page;
|
|
1124
|
-
g.Page = (pageOptions) => {
|
|
1125
|
-
const next = { ...(pageOptions ?? {}) };
|
|
1126
|
-
const rawOnLoad = next.onLoad;
|
|
1127
|
-
const rawOnReady = next.onReady;
|
|
1128
|
-
next.onLoad = function (...args) {
|
|
1129
|
-
try {
|
|
1130
|
-
this.__beLinkClsLoggerPageLoadTs__ = Date.now();
|
|
1131
|
-
}
|
|
1132
|
-
catch {
|
|
1133
|
-
// ignore
|
|
1134
|
-
}
|
|
1135
|
-
if (typeof rawOnLoad === 'function')
|
|
1136
|
-
return rawOnLoad.apply(this, args);
|
|
1137
|
-
return undefined;
|
|
1138
|
-
};
|
|
1139
|
-
next.onReady = function (...args) {
|
|
1140
|
-
try {
|
|
1141
|
-
const start = this.__beLinkClsLoggerPageLoadTs__;
|
|
1142
|
-
if (typeof start === 'number' && sampleHit(options.sampleRate)) {
|
|
1143
|
-
report(reportType, {
|
|
1144
|
-
metric: 'page-render',
|
|
1145
|
-
route: this?.route ? String(this.route) : '',
|
|
1146
|
-
duration: Date.now() - start,
|
|
1147
|
-
unit: 'ms',
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
catch {
|
|
1152
|
-
// ignore
|
|
1153
|
-
}
|
|
1154
|
-
if (typeof rawOnReady === 'function')
|
|
1155
|
-
return rawOnReady.apply(this, args);
|
|
1156
|
-
return undefined;
|
|
1157
|
-
};
|
|
1158
|
-
return rawPage(next);
|
|
1159
|
-
};
|
|
1160
|
-
}
|
|
1161
1091
|
function installMiniProgramPerformanceMonitor(report, options) {
|
|
1162
1092
|
const g = globalThis;
|
|
1093
|
+
const ctx = g.wx || g.Taro;
|
|
1094
|
+
if (!ctx || typeof ctx.getPerformance !== 'function')
|
|
1095
|
+
return;
|
|
1163
1096
|
if (g.__beLinkClsLoggerMpPerfInstalled__)
|
|
1164
1097
|
return;
|
|
1165
1098
|
g.__beLinkClsLoggerMpPerfInstalled__ = true;
|
|
1166
|
-
// 路由切换耗时(用 API 回调近似)
|
|
1167
|
-
for (const apiName of ['navigateTo', 'redirectTo', 'switchTab', 'reLaunch']) {
|
|
1168
|
-
try {
|
|
1169
|
-
wrapMiniProgramRouteApi(report, options.reportType, apiName, options);
|
|
1170
|
-
}
|
|
1171
|
-
catch {
|
|
1172
|
-
// ignore
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
// 页面渲染耗时(onLoad -> onReady)
|
|
1176
|
-
try {
|
|
1177
|
-
installMiniProgramPageRenderMonitor(report, options.reportType, options);
|
|
1178
|
-
}
|
|
1179
|
-
catch {
|
|
1180
|
-
// ignore
|
|
1181
|
-
}
|
|
1182
|
-
// wx.getPerformance()(若可用,尝试读取已有 entries)
|
|
1183
1099
|
try {
|
|
1184
|
-
const
|
|
1185
|
-
if (
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
: typeof perf.getEntriesByType === 'function'
|
|
1196
|
-
? perf.getEntriesByType('navigation')
|
|
1197
|
-
: [];
|
|
1100
|
+
const perf = ctx.getPerformance();
|
|
1101
|
+
if (!perf || typeof perf.createObserver !== 'function')
|
|
1102
|
+
return;
|
|
1103
|
+
const observer = perf.createObserver((entryList) => {
|
|
1104
|
+
try {
|
|
1105
|
+
const entries = entryList.getEntries();
|
|
1106
|
+
for (const entry of entries) {
|
|
1107
|
+
if (!sampleHit(options.sampleRate))
|
|
1108
|
+
continue;
|
|
1109
|
+
// Page Render: firstRender
|
|
1110
|
+
if (entry.entryType === 'render' && entry.name === 'firstRender') {
|
|
1198
1111
|
report(options.reportType, {
|
|
1199
|
-
metric: '
|
|
1200
|
-
|
|
1112
|
+
metric: 'page-render',
|
|
1113
|
+
duration: entry.duration,
|
|
1114
|
+
pagePath: entry.path || '',
|
|
1115
|
+
unit: 'ms',
|
|
1201
1116
|
});
|
|
1202
1117
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1118
|
+
// Route Switch: route
|
|
1119
|
+
else if (entry.entryType === 'navigation' && entry.name === 'route') {
|
|
1120
|
+
report(options.reportType, {
|
|
1121
|
+
metric: 'route',
|
|
1122
|
+
duration: entry.duration,
|
|
1123
|
+
pagePath: entry.path || '',
|
|
1124
|
+
unit: 'ms',
|
|
1125
|
+
});
|
|
1205
1126
|
}
|
|
1206
|
-
|
|
1127
|
+
// App Launch: appLaunch (Cold)
|
|
1128
|
+
else if (entry.entryType === 'navigation' && entry.name === 'appLaunch') {
|
|
1129
|
+
report(options.reportType, {
|
|
1130
|
+
metric: 'app-launch',
|
|
1131
|
+
duration: entry.duration,
|
|
1132
|
+
launchType: 'cold',
|
|
1133
|
+
unit: 'ms',
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1207
1137
|
}
|
|
1208
|
-
|
|
1138
|
+
catch {
|
|
1139
|
+
// ignore
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
observer.observe({ entryTypes: ['navigation', 'render'] });
|
|
1209
1143
|
}
|
|
1210
1144
|
catch {
|
|
1211
1145
|
// ignore
|
|
@@ -2035,7 +1969,7 @@ class ClsLoggerCore {
|
|
|
2035
1969
|
try {
|
|
2036
1970
|
const userRaw = this.userGenerateBaseFields ? this.userGenerateBaseFields() : undefined;
|
|
2037
1971
|
if (userRaw && isPlainObject(userRaw))
|
|
2038
|
-
user = normalizeFlatFields({ ...userRaw
|
|
1972
|
+
user = normalizeFlatFields({ ...userRaw }, 'generateBaseFields');
|
|
2039
1973
|
}
|
|
2040
1974
|
catch {
|
|
2041
1975
|
user = undefined;
|