@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
package/dist/web.js
CHANGED
|
@@ -586,7 +586,17 @@ function getPagePath$1() {
|
|
|
586
586
|
function normalizeErrorLike(err, maxTextLength) {
|
|
587
587
|
if (err && typeof err === 'object') {
|
|
588
588
|
const anyErr = err;
|
|
589
|
-
|
|
589
|
+
let rawMsg = anyErr.message;
|
|
590
|
+
if (!rawMsg) {
|
|
591
|
+
const str = anyErr.toString?.();
|
|
592
|
+
if (!str || str === '[object Object]') {
|
|
593
|
+
rawMsg = stringifyLogValue(anyErr);
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
rawMsg = str;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const message = truncate$2(String(rawMsg ?? ''), maxTextLength);
|
|
590
600
|
const name = truncate$2(String(anyErr.name ?? ''), 200);
|
|
591
601
|
const stack = truncate$2(String(anyErr.stack ?? ''), maxTextLength);
|
|
592
602
|
return { message, name, stack };
|
|
@@ -730,9 +740,12 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
730
740
|
try {
|
|
731
741
|
if (!sampleHit$1(options.sampleRate))
|
|
732
742
|
return;
|
|
743
|
+
const e = normalizeErrorLike(msg, options.maxTextLength);
|
|
733
744
|
const payload = {
|
|
734
745
|
source: 'wx.onError',
|
|
735
|
-
message:
|
|
746
|
+
message: e.message,
|
|
747
|
+
errorName: e.name,
|
|
748
|
+
stack: e.stack,
|
|
736
749
|
};
|
|
737
750
|
if (!shouldReport(buildErrorKey(options.reportType, payload)))
|
|
738
751
|
return;
|
|
@@ -784,9 +797,12 @@ function installMiniProgramErrorMonitor(report, options) {
|
|
|
784
797
|
next.onError = function (...args) {
|
|
785
798
|
try {
|
|
786
799
|
if (sampleHit$1(options.sampleRate)) {
|
|
800
|
+
const e = normalizeErrorLike(args?.[0], options.maxTextLength);
|
|
787
801
|
const payload = {
|
|
788
802
|
source: 'App.onError',
|
|
789
|
-
message:
|
|
803
|
+
message: e.message,
|
|
804
|
+
errorName: e.name,
|
|
805
|
+
stack: e.stack,
|
|
790
806
|
};
|
|
791
807
|
if (shouldReport(buildErrorKey(options.reportType, payload)))
|
|
792
808
|
report(options.reportType, payload);
|
|
@@ -1093,140 +1109,58 @@ function installBrowserPerformanceMonitor(report, options) {
|
|
|
1093
1109
|
}
|
|
1094
1110
|
}
|
|
1095
1111
|
}
|
|
1096
|
-
function wrapMiniProgramRouteApi(report, reportType, apiName, options) {
|
|
1097
|
-
const wxAny = globalThis.wx;
|
|
1098
|
-
if (!wxAny || typeof wxAny[apiName] !== 'function')
|
|
1099
|
-
return;
|
|
1100
|
-
const flagKey = `__beLinkClsLoggerMpRouteWrapped__${apiName}`;
|
|
1101
|
-
if (wxAny[flagKey])
|
|
1102
|
-
return;
|
|
1103
|
-
wxAny[flagKey] = true;
|
|
1104
|
-
const raw = wxAny[apiName].bind(wxAny);
|
|
1105
|
-
wxAny[apiName] = (opts) => {
|
|
1106
|
-
const start = Date.now();
|
|
1107
|
-
const url = opts?.url ? String(opts.url) : '';
|
|
1108
|
-
const wrapCb = (cb, success) => {
|
|
1109
|
-
return (...args) => {
|
|
1110
|
-
try {
|
|
1111
|
-
if (sampleHit(options.sampleRate)) {
|
|
1112
|
-
report(reportType, {
|
|
1113
|
-
metric: 'route',
|
|
1114
|
-
api: apiName,
|
|
1115
|
-
url,
|
|
1116
|
-
duration: Date.now() - start,
|
|
1117
|
-
success: success ? 1 : 0,
|
|
1118
|
-
error: success ? '' : truncate$1(stringifyLogValue(args?.[0]), options.maxTextLength),
|
|
1119
|
-
unit: 'ms',
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
catch {
|
|
1124
|
-
// ignore
|
|
1125
|
-
}
|
|
1126
|
-
if (typeof cb === 'function')
|
|
1127
|
-
return cb(...args);
|
|
1128
|
-
return undefined;
|
|
1129
|
-
};
|
|
1130
|
-
};
|
|
1131
|
-
const next = { ...(opts ?? {}) };
|
|
1132
|
-
next.success = wrapCb(next.success, true);
|
|
1133
|
-
next.fail = wrapCb(next.fail, false);
|
|
1134
|
-
return raw(next);
|
|
1135
|
-
};
|
|
1136
|
-
}
|
|
1137
|
-
function installMiniProgramPageRenderMonitor(report, reportType, options) {
|
|
1138
|
-
const g = globalThis;
|
|
1139
|
-
if (typeof g.Page !== 'function')
|
|
1140
|
-
return;
|
|
1141
|
-
if (g.__beLinkClsLoggerPageWrapped__)
|
|
1142
|
-
return;
|
|
1143
|
-
g.__beLinkClsLoggerPageWrapped__ = true;
|
|
1144
|
-
const rawPage = g.Page;
|
|
1145
|
-
g.Page = (pageOptions) => {
|
|
1146
|
-
const next = { ...(pageOptions ?? {}) };
|
|
1147
|
-
const rawOnLoad = next.onLoad;
|
|
1148
|
-
const rawOnReady = next.onReady;
|
|
1149
|
-
next.onLoad = function (...args) {
|
|
1150
|
-
try {
|
|
1151
|
-
this.__beLinkClsLoggerPageLoadTs__ = Date.now();
|
|
1152
|
-
}
|
|
1153
|
-
catch {
|
|
1154
|
-
// ignore
|
|
1155
|
-
}
|
|
1156
|
-
if (typeof rawOnLoad === 'function')
|
|
1157
|
-
return rawOnLoad.apply(this, args);
|
|
1158
|
-
return undefined;
|
|
1159
|
-
};
|
|
1160
|
-
next.onReady = function (...args) {
|
|
1161
|
-
try {
|
|
1162
|
-
const start = this.__beLinkClsLoggerPageLoadTs__;
|
|
1163
|
-
if (typeof start === 'number' && sampleHit(options.sampleRate)) {
|
|
1164
|
-
report(reportType, {
|
|
1165
|
-
metric: 'page-render',
|
|
1166
|
-
route: this?.route ? String(this.route) : '',
|
|
1167
|
-
duration: Date.now() - start,
|
|
1168
|
-
unit: 'ms',
|
|
1169
|
-
});
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
catch {
|
|
1173
|
-
// ignore
|
|
1174
|
-
}
|
|
1175
|
-
if (typeof rawOnReady === 'function')
|
|
1176
|
-
return rawOnReady.apply(this, args);
|
|
1177
|
-
return undefined;
|
|
1178
|
-
};
|
|
1179
|
-
return rawPage(next);
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
1112
|
function installMiniProgramPerformanceMonitor(report, options) {
|
|
1183
1113
|
const g = globalThis;
|
|
1114
|
+
const ctx = g.wx || g.Taro;
|
|
1115
|
+
if (!ctx || typeof ctx.getPerformance !== 'function')
|
|
1116
|
+
return;
|
|
1184
1117
|
if (g.__beLinkClsLoggerMpPerfInstalled__)
|
|
1185
1118
|
return;
|
|
1186
1119
|
g.__beLinkClsLoggerMpPerfInstalled__ = true;
|
|
1187
|
-
// 路由切换耗时(用 API 回调近似)
|
|
1188
|
-
for (const apiName of ['navigateTo', 'redirectTo', 'switchTab', 'reLaunch']) {
|
|
1189
|
-
try {
|
|
1190
|
-
wrapMiniProgramRouteApi(report, options.reportType, apiName, options);
|
|
1191
|
-
}
|
|
1192
|
-
catch {
|
|
1193
|
-
// ignore
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
// 页面渲染耗时(onLoad -> onReady)
|
|
1197
|
-
try {
|
|
1198
|
-
installMiniProgramPageRenderMonitor(report, options.reportType, options);
|
|
1199
|
-
}
|
|
1200
|
-
catch {
|
|
1201
|
-
// ignore
|
|
1202
|
-
}
|
|
1203
|
-
// wx.getPerformance()(若可用,尝试读取已有 entries)
|
|
1204
1120
|
try {
|
|
1205
|
-
const
|
|
1206
|
-
if (
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
: typeof perf.getEntriesByType === 'function'
|
|
1217
|
-
? perf.getEntriesByType('navigation')
|
|
1218
|
-
: [];
|
|
1121
|
+
const perf = ctx.getPerformance();
|
|
1122
|
+
if (!perf || typeof perf.createObserver !== 'function')
|
|
1123
|
+
return;
|
|
1124
|
+
const observer = perf.createObserver((entryList) => {
|
|
1125
|
+
try {
|
|
1126
|
+
const entries = entryList.getEntries();
|
|
1127
|
+
for (const entry of entries) {
|
|
1128
|
+
if (!sampleHit(options.sampleRate))
|
|
1129
|
+
continue;
|
|
1130
|
+
// Page Render: firstRender
|
|
1131
|
+
if (entry.entryType === 'render' && entry.name === 'firstRender') {
|
|
1219
1132
|
report(options.reportType, {
|
|
1220
|
-
metric: '
|
|
1221
|
-
|
|
1133
|
+
metric: 'page-render',
|
|
1134
|
+
duration: entry.duration,
|
|
1135
|
+
pagePath: entry.path || '',
|
|
1136
|
+
unit: 'ms',
|
|
1222
1137
|
});
|
|
1223
1138
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1139
|
+
// Route Switch: route
|
|
1140
|
+
else if (entry.entryType === 'navigation' && entry.name === 'route') {
|
|
1141
|
+
report(options.reportType, {
|
|
1142
|
+
metric: 'route',
|
|
1143
|
+
duration: entry.duration,
|
|
1144
|
+
pagePath: entry.path || '',
|
|
1145
|
+
unit: 'ms',
|
|
1146
|
+
});
|
|
1226
1147
|
}
|
|
1227
|
-
|
|
1148
|
+
// App Launch: appLaunch (Cold)
|
|
1149
|
+
else if (entry.entryType === 'navigation' && entry.name === 'appLaunch') {
|
|
1150
|
+
report(options.reportType, {
|
|
1151
|
+
metric: 'app-launch',
|
|
1152
|
+
duration: entry.duration,
|
|
1153
|
+
launchType: 'cold',
|
|
1154
|
+
unit: 'ms',
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1228
1158
|
}
|
|
1229
|
-
|
|
1159
|
+
catch {
|
|
1160
|
+
// ignore
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
observer.observe({ entryTypes: ['navigation', 'render'] });
|
|
1230
1164
|
}
|
|
1231
1165
|
catch {
|
|
1232
1166
|
// ignore
|
|
@@ -2056,7 +1990,7 @@ class ClsLoggerCore {
|
|
|
2056
1990
|
try {
|
|
2057
1991
|
const userRaw = this.userGenerateBaseFields ? this.userGenerateBaseFields() : undefined;
|
|
2058
1992
|
if (userRaw && isPlainObject(userRaw))
|
|
2059
|
-
user = normalizeFlatFields({ ...userRaw
|
|
1993
|
+
user = normalizeFlatFields({ ...userRaw }, 'generateBaseFields');
|
|
2060
1994
|
}
|
|
2061
1995
|
catch {
|
|
2062
1996
|
user = undefined;
|