@be-link/cls-logger 1.0.1-beta.9 → 1.0.3

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/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: entry.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: entry.duration,
1147
+ duration,
1121
1148
  pagePath: entry.path || '',
1122
1149
  unit: 'ms',
1123
1150
  });
@@ -1461,7 +1488,7 @@ function installBehaviorMonitor(report, envType, options = {}) {
1461
1488
  const tag = (el.tagName || '').toLowerCase();
1462
1489
  const trackId = getAttr(el, clickTrackIdAttr);
1463
1490
  // 过滤无效点击:白名单 tag + 没有 trackId
1464
- if (clickWhiteList.includes(tag) && !trackId)
1491
+ if (clickWhiteList.includes(tag) || !trackId)
1465
1492
  return;
1466
1493
  void uvStatePromise.then(({ uvId, meta }) => {
1467
1494
  if (destroyed)
@@ -1502,8 +1529,12 @@ function installBehaviorMonitor(report, envType, options = {}) {
1502
1529
  g.Page = function patchedPage(conf) {
1503
1530
  const originalOnShow = conf?.onShow;
1504
1531
  conf.onShow = function (...args) {
1505
- if (pvEnabled)
1506
- reportPv(getPagePath());
1532
+ if (pvEnabled) {
1533
+ const pagePath = getPagePath();
1534
+ if (pagePath?.length > 0) {
1535
+ reportPv(pagePath);
1536
+ }
1537
+ }
1507
1538
  return typeof originalOnShow === 'function' ? originalOnShow.apply(this, args) : undefined;
1508
1539
  };
1509
1540
  // 点击:wrap 页面 methods(bindtap 等会调用到这里的 handler)
@@ -1887,9 +1918,14 @@ class ClsLoggerCore {
1887
1918
  * 子类可按需重写(默认检测 wx)
1888
1919
  */
1889
1920
  detectEnvType() {
1890
- const wxAny = globalThis.wx;
1891
- if (wxAny && typeof wxAny.getSystemInfoSync === 'function')
1921
+ const g = globalThis;
1922
+ // 微信、支付宝、字节跳动、UniApp 等小程序环境通常都有特定全局变量
1923
+ if ((g.wx && typeof g.wx.getSystemInfoSync === 'function') ||
1924
+ (g.my && typeof g.my.getSystemInfoSync === 'function') ||
1925
+ (g.tt && typeof g.tt.getSystemInfoSync === 'function') ||
1926
+ (g.uni && typeof g.uni.getSystemInfoSync === 'function')) {
1892
1927
  return 'miniprogram';
1928
+ }
1893
1929
  return 'browser';
1894
1930
  }
1895
1931
  init(options) {
@@ -2262,15 +2298,57 @@ class ClsLoggerCore {
2262
2298
  return nowTs + this.batchIntervalMs;
2263
2299
  }
2264
2300
  info(message, data = {}) {
2265
- const payload = normalizeFlatFields({ message, ...data }, 'info');
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');
2266
2316
  this.report({ type: 'info', data: payload, timestamp: Date.now() });
2267
2317
  }
2268
2318
  warn(message, data = {}) {
2269
- const payload = normalizeFlatFields({ message, ...data }, 'warn');
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');
2270
2334
  this.report({ type: 'warn', data: payload, timestamp: Date.now() });
2271
2335
  }
2272
2336
  error(message, data = {}) {
2273
- const payload = normalizeFlatFields({ message, ...data }, 'error');
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');
2274
2352
  this.report({ type: 'error', data: payload, timestamp: Date.now() });
2275
2353
  }
2276
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: entry.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: entry.duration,
1170
+ duration,
1144
1171
  pagePath: entry.path || '',
1145
1172
  unit: 'ms',
1146
1173
  });
@@ -1484,7 +1511,7 @@ function installBehaviorMonitor(report, envType, options = {}) {
1484
1511
  const tag = (el.tagName || '').toLowerCase();
1485
1512
  const trackId = getAttr(el, clickTrackIdAttr);
1486
1513
  // 过滤无效点击:白名单 tag + 没有 trackId
1487
- if (clickWhiteList.includes(tag) && !trackId)
1514
+ if (clickWhiteList.includes(tag) || !trackId)
1488
1515
  return;
1489
1516
  void uvStatePromise.then(({ uvId, meta }) => {
1490
1517
  if (destroyed)
@@ -1525,8 +1552,12 @@ function installBehaviorMonitor(report, envType, options = {}) {
1525
1552
  g.Page = function patchedPage(conf) {
1526
1553
  const originalOnShow = conf?.onShow;
1527
1554
  conf.onShow = function (...args) {
1528
- if (pvEnabled)
1529
- reportPv(getPagePath());
1555
+ if (pvEnabled) {
1556
+ const pagePath = getPagePath();
1557
+ if (pagePath?.length > 0) {
1558
+ reportPv(pagePath);
1559
+ }
1560
+ }
1530
1561
  return typeof originalOnShow === 'function' ? originalOnShow.apply(this, args) : undefined;
1531
1562
  };
1532
1563
  // 点击:wrap 页面 methods(bindtap 等会调用到这里的 handler)
@@ -1910,9 +1941,14 @@ class ClsLoggerCore {
1910
1941
  * 子类可按需重写(默认检测 wx)
1911
1942
  */
1912
1943
  detectEnvType() {
1913
- const wxAny = globalThis.wx;
1914
- if (wxAny && typeof wxAny.getSystemInfoSync === 'function')
1944
+ const g = globalThis;
1945
+ // 微信、支付宝、字节跳动、UniApp 等小程序环境通常都有特定全局变量
1946
+ if ((g.wx && typeof g.wx.getSystemInfoSync === 'function') ||
1947
+ (g.my && typeof g.my.getSystemInfoSync === 'function') ||
1948
+ (g.tt && typeof g.tt.getSystemInfoSync === 'function') ||
1949
+ (g.uni && typeof g.uni.getSystemInfoSync === 'function')) {
1915
1950
  return 'miniprogram';
1951
+ }
1916
1952
  return 'browser';
1917
1953
  }
1918
1954
  init(options) {
@@ -2285,15 +2321,57 @@ class ClsLoggerCore {
2285
2321
  return nowTs + this.batchIntervalMs;
2286
2322
  }
2287
2323
  info(message, data = {}) {
2288
- const payload = normalizeFlatFields({ message, ...data }, 'info');
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');
2289
2339
  this.report({ type: 'info', data: payload, timestamp: Date.now() });
2290
2340
  }
2291
2341
  warn(message, data = {}) {
2292
- const payload = normalizeFlatFields({ message, ...data }, 'warn');
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');
2293
2357
  this.report({ type: 'warn', data: payload, timestamp: Date.now() });
2294
2358
  }
2295
2359
  error(message, data = {}) {
2296
- const payload = normalizeFlatFields({ message, ...data }, 'error');
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');
2297
2375
  this.report({ type: 'error', data: payload, timestamp: Date.now() });
2298
2376
  }
2299
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;AAuSzD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,QAAQ,EAChB,IAAI,GAAE,OAAO,GAAG,yBAAyB,GAAG,SAAc,GACzD,IAAI,CAsBN"}
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: entry.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: entry.duration,
1147
+ duration,
1121
1148
  pagePath: entry.path || '',
1122
1149
  unit: 'ms',
1123
1150
  });
@@ -1461,7 +1488,7 @@ function installBehaviorMonitor(report, envType, options = {}) {
1461
1488
  const tag = (el.tagName || '').toLowerCase();
1462
1489
  const trackId = getAttr(el, clickTrackIdAttr);
1463
1490
  // 过滤无效点击:白名单 tag + 没有 trackId
1464
- if (clickWhiteList.includes(tag) && !trackId)
1491
+ if (clickWhiteList.includes(tag) || !trackId)
1465
1492
  return;
1466
1493
  void uvStatePromise.then(({ uvId, meta }) => {
1467
1494
  if (destroyed)
@@ -1502,8 +1529,12 @@ function installBehaviorMonitor(report, envType, options = {}) {
1502
1529
  g.Page = function patchedPage(conf) {
1503
1530
  const originalOnShow = conf?.onShow;
1504
1531
  conf.onShow = function (...args) {
1505
- if (pvEnabled)
1506
- reportPv(getPagePath());
1532
+ if (pvEnabled) {
1533
+ const pagePath = getPagePath();
1534
+ if (pagePath?.length > 0) {
1535
+ reportPv(pagePath);
1536
+ }
1537
+ }
1507
1538
  return typeof originalOnShow === 'function' ? originalOnShow.apply(this, args) : undefined;
1508
1539
  };
1509
1540
  // 点击:wrap 页面 methods(bindtap 等会调用到这里的 handler)
@@ -1887,9 +1918,14 @@ class ClsLoggerCore {
1887
1918
  * 子类可按需重写(默认检测 wx)
1888
1919
  */
1889
1920
  detectEnvType() {
1890
- const wxAny = globalThis.wx;
1891
- if (wxAny && typeof wxAny.getSystemInfoSync === 'function')
1921
+ const g = globalThis;
1922
+ // 微信、支付宝、字节跳动、UniApp 等小程序环境通常都有特定全局变量
1923
+ if ((g.wx && typeof g.wx.getSystemInfoSync === 'function') ||
1924
+ (g.my && typeof g.my.getSystemInfoSync === 'function') ||
1925
+ (g.tt && typeof g.tt.getSystemInfoSync === 'function') ||
1926
+ (g.uni && typeof g.uni.getSystemInfoSync === 'function')) {
1892
1927
  return 'miniprogram';
1928
+ }
1893
1929
  return 'browser';
1894
1930
  }
1895
1931
  init(options) {
@@ -2262,15 +2298,57 @@ class ClsLoggerCore {
2262
2298
  return nowTs + this.batchIntervalMs;
2263
2299
  }
2264
2300
  info(message, data = {}) {
2265
- const payload = normalizeFlatFields({ message, ...data }, 'info');
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');
2266
2316
  this.report({ type: 'info', data: payload, timestamp: Date.now() });
2267
2317
  }
2268
2318
  warn(message, data = {}) {
2269
- const payload = normalizeFlatFields({ message, ...data }, 'warn');
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');
2270
2334
  this.report({ type: 'warn', data: payload, timestamp: Date.now() });
2271
2335
  }
2272
2336
  error(message, data = {}) {
2273
- const payload = normalizeFlatFields({ message, ...data }, 'error');
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');
2274
2352
  this.report({ type: 'error', data: payload, timestamp: Date.now() });
2275
2353
  }
2276
2354
  track(trackType, data = {}) {