sentry-miniapp 1.4.0 → 1.5.0

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.
Files changed (57) hide show
  1. package/dist/sentry-miniapp.cjs.js +386 -143
  2. package/dist/sentry-miniapp.cjs.js.map +1 -1
  3. package/dist/sentry-miniapp.esm.js +386 -143
  4. package/dist/sentry-miniapp.esm.js.map +1 -1
  5. package/dist/sentry-miniapp.umd.js +386 -143
  6. package/dist/sentry-miniapp.umd.js.map +1 -1
  7. package/dist/types/client.d.ts.map +1 -1
  8. package/dist/types/crossPlatform.d.ts.map +1 -1
  9. package/dist/types/eventbuilder.d.ts.map +1 -1
  10. package/dist/types/helpers.d.ts.map +1 -1
  11. package/dist/types/index.d.ts +1 -1
  12. package/dist/types/index.d.ts.map +1 -1
  13. package/dist/types/integrations/console.d.ts +31 -0
  14. package/dist/types/integrations/console.d.ts.map +1 -0
  15. package/dist/types/integrations/dedupe.d.ts.map +1 -1
  16. package/dist/types/integrations/globalhandlers.d.ts.map +1 -1
  17. package/dist/types/integrations/index.d.ts +2 -0
  18. package/dist/types/integrations/index.d.ts.map +1 -1
  19. package/dist/types/integrations/linkederrors.d.ts.map +1 -1
  20. package/dist/types/integrations/networkbreadcrumbs.d.ts.map +1 -1
  21. package/dist/types/integrations/pagebreadcrumbs.d.ts +38 -0
  22. package/dist/types/integrations/pagebreadcrumbs.d.ts.map +1 -0
  23. package/dist/types/integrations/performance.d.ts +17 -0
  24. package/dist/types/integrations/performance.d.ts.map +1 -1
  25. package/dist/types/integrations/router.d.ts.map +1 -1
  26. package/dist/types/integrations/trycatch.d.ts.map +1 -1
  27. package/dist/types/sdk.d.ts.map +1 -1
  28. package/dist/types/transports/offlineStore.d.ts.map +1 -1
  29. package/dist/types/transports/xhr.d.ts.map +1 -1
  30. package/dist/types/types.d.ts.map +1 -1
  31. package/dist/types/version.d.ts +1 -1
  32. package/package.json +18 -9
  33. package/CHANGELOG.md +0 -123
  34. package/src/.keep +0 -0
  35. package/src/client.ts +0 -203
  36. package/src/crossPlatform.ts +0 -407
  37. package/src/eventbuilder.ts +0 -291
  38. package/src/helpers.ts +0 -214
  39. package/src/index.ts +0 -86
  40. package/src/integrations/dedupe.ts +0 -215
  41. package/src/integrations/globalhandlers.ts +0 -209
  42. package/src/integrations/httpcontext.ts +0 -140
  43. package/src/integrations/index.ts +0 -10
  44. package/src/integrations/linkederrors.ts +0 -107
  45. package/src/integrations/networkbreadcrumbs.ts +0 -155
  46. package/src/integrations/performance.ts +0 -622
  47. package/src/integrations/rewriteframes.ts +0 -77
  48. package/src/integrations/router.ts +0 -180
  49. package/src/integrations/system.ts +0 -135
  50. package/src/integrations/trycatch.ts +0 -233
  51. package/src/polyfills.ts +0 -242
  52. package/src/sdk.ts +0 -182
  53. package/src/transports/index.ts +0 -3
  54. package/src/transports/offlineStore.ts +0 -85
  55. package/src/transports/xhr.ts +0 -68
  56. package/src/types.ts +0 -129
  57. package/src/version.ts +0 -3
@@ -4938,7 +4938,7 @@ function addBreadcrumb(breadcrumb, hint) {
4938
4938
  }
4939
4939
  isolationScope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs);
4940
4940
  }
4941
- const SDK_VERSION = "1.3.1";
4941
+ const SDK_VERSION = "1.5.0";
4942
4942
  const SDK_NAME = "sentry.javascript.miniapp";
4943
4943
  const getSDK = () => {
4944
4944
  let currentSdk = {
@@ -5126,7 +5126,11 @@ function createMiniappTransport(options) {
5126
5126
  });
5127
5127
  },
5128
5128
  fail: (error2) => {
5129
- reject(new Error(`Network request failed: ${error2.errMsg || error2.errorMessage || error2.message || "Unknown error"}`));
5129
+ reject(
5130
+ new Error(
5131
+ `Network request failed: ${error2.errMsg || error2.errorMessage || error2.message || "Unknown error"}`
5132
+ )
5133
+ );
5130
5134
  }
5131
5135
  };
5132
5136
  if (sdk().request) {
@@ -5194,7 +5198,7 @@ function getStore() {
5194
5198
  return typeof storedStr === "string" ? JSON.parse(storedStr) : storedStr;
5195
5199
  }
5196
5200
  }
5197
- } catch (e) {
5201
+ } catch (_e) {
5198
5202
  }
5199
5203
  return [];
5200
5204
  }
@@ -5204,7 +5208,7 @@ function setStore(store) {
5204
5208
  if (storageApi) {
5205
5209
  storageApi(OFFLINE_STORE_KEY, JSON.stringify(store));
5206
5210
  }
5207
- } catch (e) {
5211
+ } catch (_e) {
5208
5212
  }
5209
5213
  }
5210
5214
  const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
@@ -5242,10 +5246,12 @@ class MiniappClient extends Client {
5242
5246
  eventFromException(exception) {
5243
5247
  return Promise.resolve({
5244
5248
  exception: {
5245
- values: [{
5246
- type: exception.name || "Error",
5247
- value: exception.message || String(exception)
5248
- }]
5249
+ values: [
5250
+ {
5251
+ type: exception.name || "Error",
5252
+ value: exception.message || String(exception)
5253
+ }
5254
+ ]
5249
5255
  },
5250
5256
  level: "error"
5251
5257
  });
@@ -5316,7 +5322,7 @@ class MiniappClient extends Client {
5316
5322
  const currentScope = scope || getCurrentScope();
5317
5323
  const isolationScope = getIsolationScope();
5318
5324
  return super._prepareEvent(event, hint || {}, currentScope, isolationScope);
5319
- } catch (error2) {
5325
+ } catch (_error) {
5320
5326
  return Promise.resolve(event);
5321
5327
  }
5322
5328
  }
@@ -5438,23 +5444,26 @@ const _GlobalHandlers = class _GlobalHandlers {
5438
5444
  return;
5439
5445
  }
5440
5446
  if (sdk().onPageNotFound) {
5441
- (_b = (_a = sdk()).onPageNotFound) == null ? void 0 : _b.call(_a, (res) => {
5442
- const scope = getCurrentScope();
5443
- const url = res.path.split("?")[0];
5444
- scope.setTag("pagenotfound", url);
5445
- scope.setContext("page_not_found", {
5446
- path: res.path,
5447
- query: res.query,
5448
- isEntryPage: res.isEntryPage
5449
- });
5450
- captureException(new Error(`页面无法找到: ${url}`), {
5451
- level: "warning",
5452
- mechanism: {
5453
- type: "onpagenotfound",
5454
- handled: true
5455
- }
5456
- });
5457
- });
5447
+ (_b = (_a = sdk()).onPageNotFound) == null ? void 0 : _b.call(
5448
+ _a,
5449
+ (res) => {
5450
+ const scope = getCurrentScope();
5451
+ const url = res.path.split("?")[0];
5452
+ scope.setTag("pagenotfound", url);
5453
+ scope.setContext("page_not_found", {
5454
+ path: res.path,
5455
+ query: res.query,
5456
+ isEntryPage: res.isEntryPage
5457
+ });
5458
+ captureException(new Error(`页面无法找到: ${url}`), {
5459
+ level: "warning",
5460
+ mechanism: {
5461
+ type: "onpagenotfound",
5462
+ handled: true
5463
+ }
5464
+ });
5465
+ }
5466
+ );
5458
5467
  }
5459
5468
  this._onPageNotFoundHandlerInstalled = true;
5460
5469
  }
@@ -5565,7 +5574,7 @@ function wrap$1(fn, options = {}, before) {
5565
5574
  if (fn.__sentry_wrapped__) {
5566
5575
  return fn.__sentry_wrapped__;
5567
5576
  }
5568
- } catch (e) {
5577
+ } catch (_e) {
5569
5578
  return fn;
5570
5579
  }
5571
5580
  const sentryWrapped = function(...args) {
@@ -5647,7 +5656,7 @@ function fill$1(source, name, replacementFactory) {
5647
5656
  function getFunctionName(fn) {
5648
5657
  try {
5649
5658
  return fn && fn.name || "<anonymous>";
5650
- } catch (e) {
5659
+ } catch (_e) {
5651
5660
  return "<anonymous>";
5652
5661
  }
5653
5662
  }
@@ -5757,7 +5766,7 @@ const _HttpContext = class _HttpContext {
5757
5766
  const accountInfo = (_b = (_a = sdk()).getAccountInfoSync) == null ? void 0 : _b.call(_a);
5758
5767
  return ((_c = accountInfo.miniProgram) == null ? void 0 : _c.appId) || "unknown";
5759
5768
  }
5760
- } catch (e) {
5769
+ } catch (_e) {
5761
5770
  }
5762
5771
  return "unknown";
5763
5772
  }
@@ -5771,7 +5780,7 @@ const _HttpContext = class _HttpContext {
5771
5780
  const accountInfo = (_b = (_a = sdk()).getAccountInfoSync) == null ? void 0 : _b.call(_a);
5772
5781
  return ((_c = accountInfo == null ? void 0 : accountInfo.miniProgram) == null ? void 0 : _c.version) || "unknown";
5773
5782
  }
5774
- } catch (e) {
5783
+ } catch (_e) {
5775
5784
  }
5776
5785
  return "unknown";
5777
5786
  }
@@ -5810,7 +5819,7 @@ const _HttpContext = class _HttpContext {
5810
5819
  }
5811
5820
  });
5812
5821
  }
5813
- } catch (e) {
5822
+ } catch (_e) {
5814
5823
  }
5815
5824
  return {};
5816
5825
  }
@@ -6003,7 +6012,7 @@ const _System = class _System {
6003
6012
  scope.setTag("app.version", systemInfo.version);
6004
6013
  scope.setTag("language", systemInfo.language);
6005
6014
  }
6006
- } catch (e) {
6015
+ } catch (_e) {
6007
6016
  }
6008
6017
  }
6009
6018
  /**
@@ -6025,7 +6034,7 @@ const _System = class _System {
6025
6034
  }
6026
6035
  });
6027
6036
  }
6028
- } catch (e) {
6037
+ } catch (_e) {
6029
6038
  }
6030
6039
  }
6031
6040
  /**
@@ -6048,7 +6057,7 @@ const _System = class _System {
6048
6057
  }
6049
6058
  });
6050
6059
  }
6051
- } catch (e) {
6060
+ } catch (_e) {
6052
6061
  }
6053
6062
  }
6054
6063
  };
@@ -6070,40 +6079,27 @@ const _Router = class _Router {
6070
6079
  * Instrument navigation functions
6071
6080
  */
6072
6081
  _instrumentNavigation() {
6073
- const global2 = globalThis;
6074
- if (global2.wx && global2.wx.navigateTo) {
6075
- const originalNavigateTo = global2.wx.navigateTo;
6076
- global2.wx.navigateTo = (options) => {
6077
- this._recordNavigation("navigateTo", options.url, this._getCurrentRoute());
6078
- return originalNavigateTo.call(global2.wx, options);
6079
- };
6080
- }
6081
- if (global2.wx && global2.wx.redirectTo) {
6082
- const originalRedirectTo = global2.wx.redirectTo;
6083
- global2.wx.redirectTo = (options) => {
6084
- this._recordNavigation("redirectTo", options.url, this._getCurrentRoute());
6085
- return originalRedirectTo.call(global2.wx, options);
6086
- };
6082
+ let currentSdk;
6083
+ try {
6084
+ currentSdk = sdk();
6085
+ } catch (_e) {
6086
+ return;
6087
6087
  }
6088
- if (global2.wx && global2.wx.switchTab) {
6089
- const originalSwitchTab = global2.wx.switchTab;
6090
- global2.wx.switchTab = (options) => {
6091
- this._recordNavigation("switchTab", options.url, this._getCurrentRoute());
6092
- return originalSwitchTab.call(global2.wx, options);
6093
- };
6088
+ const methods = ["navigateTo", "redirectTo", "switchTab", "reLaunch"];
6089
+ for (const method of methods) {
6090
+ if (currentSdk[method]) {
6091
+ const original = currentSdk[method];
6092
+ currentSdk[method] = (options) => {
6093
+ this._recordNavigation(method, options.url, this._getCurrentRoute());
6094
+ return original.call(currentSdk, options);
6095
+ };
6096
+ }
6094
6097
  }
6095
- if (global2.wx && global2.wx.navigateBack) {
6096
- const originalNavigateBack = global2.wx.navigateBack;
6097
- global2.wx.navigateBack = (options = {}) => {
6098
+ if (currentSdk.navigateBack) {
6099
+ const originalNavigateBack = currentSdk.navigateBack;
6100
+ currentSdk.navigateBack = (options = {}) => {
6098
6101
  this._recordNavigation("navigateBack", "back", this._getCurrentRoute(), options.delta);
6099
- return originalNavigateBack.call(global2.wx, options);
6100
- };
6101
- }
6102
- if (global2.wx && global2.wx.reLaunch) {
6103
- const originalReLaunch = global2.wx.reLaunch;
6104
- global2.wx.reLaunch = (options) => {
6105
- this._recordNavigation("reLaunch", options.url, this._getCurrentRoute());
6106
- return originalReLaunch.call(global2.wx, options);
6102
+ return originalNavigateBack.call(currentSdk, options);
6107
6103
  };
6108
6104
  }
6109
6105
  }
@@ -6132,7 +6128,7 @@ const _Router = class _Router {
6132
6128
  return currentPage.route || currentPage.__route__ || "";
6133
6129
  }
6134
6130
  }
6135
- } catch (e) {
6131
+ } catch (_e) {
6136
6132
  }
6137
6133
  return "";
6138
6134
  }
@@ -6192,15 +6188,24 @@ const _PerformanceIntegration = class _PerformanceIntegration {
6192
6188
  this._observers = [];
6193
6189
  this._entryBuffer = [];
6194
6190
  this._reportTimer = null;
6195
- this._options = __spreadValues({
6191
+ this._options = __spreadProps(__spreadValues({
6196
6192
  enableNavigation: true,
6197
6193
  enableRender: true,
6198
6194
  enableResource: true,
6199
6195
  enableUserTiming: false,
6200
6196
  sampleRate: 1,
6201
6197
  bufferSize: 100,
6202
- reportInterval: 3e4
6203
- }, options);
6198
+ reportInterval: 3e4,
6199
+ // 30秒
6200
+ enableMemory: false
6201
+ }, options), {
6202
+ thresholds: __spreadValues({
6203
+ navigation: 3e3,
6204
+ render: 1e3,
6205
+ resource: 2e3,
6206
+ setData: 50
6207
+ }, options == null ? void 0 : options.thresholds)
6208
+ });
6204
6209
  }
6205
6210
  /**
6206
6211
  * @inheritDoc
@@ -6284,7 +6289,10 @@ const _PerformanceIntegration = class _PerformanceIntegration {
6284
6289
  const safeTypes = entryTypes.filter((t) => t !== "measure" && t !== "mark");
6285
6290
  if (safeTypes.length < entryTypes.length && safeTypes.length > 0) {
6286
6291
  observer.observe({ entryTypes: safeTypes });
6287
- console.warn("[Sentry Performance] Failed to observe all types, falling back to:", safeTypes);
6292
+ console.warn(
6293
+ "[Sentry Performance] Failed to observe all types, falling back to:",
6294
+ safeTypes
6295
+ );
6288
6296
  entryTypes.length = 0;
6289
6297
  entryTypes.push(...safeTypes);
6290
6298
  } else {
@@ -6370,86 +6378,117 @@ const _PerformanceIntegration = class _PerformanceIntegration {
6370
6378
  pageReadyTime: entry.pageReadyTime
6371
6379
  }
6372
6380
  });
6373
- startSpan({
6374
- name: `Navigation: ${entry.name}`,
6375
- op: "navigation",
6376
- startTime: entry.startTime / 1e3
6377
- // 转换为秒
6378
- }, (span) => {
6379
- span.setAttributes({
6380
- "navigation.name": entry.name,
6381
- "navigation.duration": entry.duration,
6382
- "navigation.app_launch_time": entry.appLaunchTime || 0,
6383
- "navigation.page_ready_time": entry.pageReadyTime || 0,
6384
- "navigation.first_render_time": entry.firstRenderTime || 0
6385
- });
6386
- span.end((entry.startTime + entry.duration) / 1e3);
6387
- });
6381
+ startSpan(
6382
+ {
6383
+ name: `Navigation: ${entry.name}`,
6384
+ op: "navigation",
6385
+ startTime: entry.startTime / 1e3
6386
+ // 转换为秒
6387
+ },
6388
+ (span) => {
6389
+ span.setAttributes({
6390
+ "navigation.name": entry.name,
6391
+ "navigation.duration": entry.duration,
6392
+ "navigation.app_launch_time": entry.appLaunchTime || 0,
6393
+ "navigation.page_ready_time": entry.pageReadyTime || 0,
6394
+ "navigation.first_render_time": entry.firstRenderTime || 0
6395
+ });
6396
+ span.end((entry.startTime + entry.duration) / 1e3);
6397
+ }
6398
+ );
6388
6399
  }
6389
6400
  /**
6390
6401
  * 处理渲染性能条目
6391
6402
  */
6392
6403
  _processRenderEntry(entry) {
6393
- startSpan({
6394
- name: `Render: ${entry.name}`,
6395
- op: "render",
6396
- startTime: entry.startTime / 1e3
6397
- }, (span) => {
6398
- span.setAttributes({
6399
- "render.name": entry.name,
6400
- "render.duration": entry.duration,
6401
- "render.start": entry.renderStart || 0,
6402
- "render.end": entry.renderEnd || 0,
6403
- "render.script_start": entry.scriptStart || 0,
6404
- "render.script_end": entry.scriptEnd || 0
6404
+ var _a, _b;
6405
+ startSpan(
6406
+ {
6407
+ name: `Render: ${entry.name}`,
6408
+ op: "render",
6409
+ startTime: entry.startTime / 1e3
6410
+ },
6411
+ (span) => {
6412
+ span.setAttributes({
6413
+ "render.name": entry.name,
6414
+ "render.duration": entry.duration,
6415
+ "render.start": entry.renderStart || 0,
6416
+ "render.end": entry.renderEnd || 0,
6417
+ "render.script_start": entry.scriptStart || 0,
6418
+ "render.script_end": entry.scriptEnd || 0
6419
+ });
6420
+ span.end((entry.startTime + entry.duration) / 1e3);
6421
+ }
6422
+ );
6423
+ const setDataThreshold = (_b = (_a = this._options.thresholds) == null ? void 0 : _a.setData) != null ? _b : 50;
6424
+ if (entry.duration > setDataThreshold) {
6425
+ const scope = getCurrentScope();
6426
+ scope.addBreadcrumb({
6427
+ message: `慢渲染检测: ${entry.name} (${entry.duration.toFixed(1)}ms)`,
6428
+ category: "performance.setData.slow",
6429
+ level: "warning",
6430
+ data: {
6431
+ name: entry.name,
6432
+ duration: entry.duration,
6433
+ threshold: setDataThreshold,
6434
+ renderStart: entry.renderStart,
6435
+ renderEnd: entry.renderEnd,
6436
+ scriptStart: entry.scriptStart,
6437
+ scriptEnd: entry.scriptEnd
6438
+ }
6405
6439
  });
6406
- span.end((entry.startTime + entry.duration) / 1e3);
6407
- });
6440
+ }
6408
6441
  }
6409
6442
  /**
6410
6443
  * 处理资源加载性能条目
6411
6444
  */
6412
6445
  _processResourceEntry(entry) {
6413
- startSpan({
6414
- name: `Resource: ${entry.name}`,
6415
- op: "resource",
6416
- startTime: entry.startTime / 1e3
6417
- }, (span) => {
6418
- span.setAttributes({
6419
- "resource.name": entry.name,
6420
- "resource.duration": entry.duration,
6421
- "resource.type": entry.initiatorType || "unknown",
6422
- "resource.transfer_size": entry.transferSize || 0,
6423
- "resource.encoded_size": entry.encodedBodySize || 0,
6424
- "resource.decoded_size": entry.decodedBodySize || 0
6425
- });
6426
- if (entry.fetchStart && entry.responseEnd) {
6446
+ startSpan(
6447
+ {
6448
+ name: `Resource: ${entry.name}`,
6449
+ op: "resource",
6450
+ startTime: entry.startTime / 1e3
6451
+ },
6452
+ (span) => {
6427
6453
  span.setAttributes({
6428
- "resource.fetch_start": entry.fetchStart,
6429
- "resource.response_end": entry.responseEnd,
6430
- "resource.network_time": entry.responseEnd - entry.fetchStart
6454
+ "resource.name": entry.name,
6455
+ "resource.duration": entry.duration,
6456
+ "resource.type": entry.initiatorType || "unknown",
6457
+ "resource.transfer_size": entry.transferSize || 0,
6458
+ "resource.encoded_size": entry.encodedBodySize || 0,
6459
+ "resource.decoded_size": entry.decodedBodySize || 0
6431
6460
  });
6461
+ if (entry.fetchStart && entry.responseEnd) {
6462
+ span.setAttributes({
6463
+ "resource.fetch_start": entry.fetchStart,
6464
+ "resource.response_end": entry.responseEnd,
6465
+ "resource.network_time": entry.responseEnd - entry.fetchStart
6466
+ });
6467
+ }
6468
+ span.end((entry.startTime + entry.duration) / 1e3);
6432
6469
  }
6433
- span.end((entry.startTime + entry.duration) / 1e3);
6434
- });
6470
+ );
6435
6471
  }
6436
6472
  /**
6437
6473
  * 处理用户自定义性能条目
6438
6474
  */
6439
6475
  _processUserTimingEntry(entry) {
6440
6476
  if (entry.entryType === "measure") {
6441
- startSpan({
6442
- name: `Measure: ${entry.name}`,
6443
- op: "measure",
6444
- startTime: entry.startTime / 1e3
6445
- }, (span) => {
6446
- span.setAttributes({
6447
- "measure.name": entry.name,
6448
- "measure.duration": entry.duration,
6449
- "measure.detail": entry.detail ? JSON.stringify(entry.detail) : void 0
6450
- });
6451
- span.end((entry.startTime + entry.duration) / 1e3);
6452
- });
6477
+ startSpan(
6478
+ {
6479
+ name: `Measure: ${entry.name}`,
6480
+ op: "measure",
6481
+ startTime: entry.startTime / 1e3
6482
+ },
6483
+ (span) => {
6484
+ span.setAttributes({
6485
+ "measure.name": entry.name,
6486
+ "measure.duration": entry.duration,
6487
+ "measure.detail": entry.detail ? JSON.stringify(entry.detail) : void 0
6488
+ });
6489
+ span.end((entry.startTime + entry.duration) / 1e3);
6490
+ }
6491
+ );
6453
6492
  } else if (entry.entryType === "mark") {
6454
6493
  const scope = getCurrentScope();
6455
6494
  scope.addBreadcrumb({
@@ -6493,6 +6532,10 @@ const _PerformanceIntegration = class _PerformanceIntegration {
6493
6532
  try {
6494
6533
  const scope = getCurrentScope();
6495
6534
  const stats = this._calculatePerformanceStats();
6535
+ const memoryInfo = this._collectMemoryInfo();
6536
+ if (memoryInfo) {
6537
+ stats["memory"] = memoryInfo;
6538
+ }
6496
6539
  scope.setContext("performance_summary", __spreadValues({
6497
6540
  total_entries: this._entryBuffer.length,
6498
6541
  navigation_count: this._entryBuffer.filter((e) => e.entryType === "navigation").length,
@@ -6532,6 +6575,14 @@ const _PerformanceIntegration = class _PerformanceIntegration {
6532
6575
  max_duration: Math.max(...durations),
6533
6576
  min_duration: Math.min(...durations)
6534
6577
  };
6578
+ const slowRenders = renderEntries.filter(
6579
+ (e) => {
6580
+ var _a, _b;
6581
+ return e.duration > ((_b = (_a = this._options.thresholds) == null ? void 0 : _a.setData) != null ? _b : 50);
6582
+ }
6583
+ );
6584
+ stats["render_stats"].slow_render_count = slowRenders.length;
6585
+ stats["render_stats"].slow_render_ratio = slowRenders.length / renderEntries.length;
6535
6586
  }
6536
6587
  if (resourceEntries.length > 0) {
6537
6588
  const durations = resourceEntries.map((e) => e.duration);
@@ -6549,38 +6600,41 @@ const _PerformanceIntegration = class _PerformanceIntegration {
6549
6600
  * 检查性能阈值
6550
6601
  */
6551
6602
  _checkPerformanceThresholds(stats) {
6552
- var _a, _b, _c;
6603
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
6553
6604
  const scope = getCurrentScope();
6554
- if (((_a = stats["navigation_stats"]) == null ? void 0 : _a.avg_duration) > 3e3) {
6605
+ const navigationThreshold = (_b = (_a = this._options.thresholds) == null ? void 0 : _a.navigation) != null ? _b : 3e3;
6606
+ if (((_c = stats["navigation_stats"]) == null ? void 0 : _c.avg_duration) > navigationThreshold) {
6555
6607
  scope.addBreadcrumb({
6556
6608
  message: "页面导航性能较慢",
6557
6609
  category: "performance.warning",
6558
6610
  level: "warning",
6559
6611
  data: {
6560
6612
  avg_duration: stats["navigation_stats"].avg_duration,
6561
- threshold: 3e3
6613
+ threshold: navigationThreshold
6562
6614
  }
6563
6615
  });
6564
6616
  }
6565
- if (((_b = stats["render_stats"]) == null ? void 0 : _b.avg_duration) > 1e3) {
6617
+ const renderThreshold = (_e = (_d = this._options.thresholds) == null ? void 0 : _d.render) != null ? _e : 1e3;
6618
+ if (((_f = stats["render_stats"]) == null ? void 0 : _f.avg_duration) > renderThreshold) {
6566
6619
  scope.addBreadcrumb({
6567
6620
  message: "页面渲染性能较慢",
6568
6621
  category: "performance.warning",
6569
6622
  level: "warning",
6570
6623
  data: {
6571
6624
  avg_duration: stats["render_stats"].avg_duration,
6572
- threshold: 1e3
6625
+ threshold: renderThreshold
6573
6626
  }
6574
6627
  });
6575
6628
  }
6576
- if (((_c = stats["resource_stats"]) == null ? void 0 : _c.avg_load_time) > 2e3) {
6629
+ const resourceThreshold = (_h = (_g = this._options.thresholds) == null ? void 0 : _g.resource) != null ? _h : 2e3;
6630
+ if (((_i = stats["resource_stats"]) == null ? void 0 : _i.avg_load_time) > resourceThreshold) {
6577
6631
  scope.addBreadcrumb({
6578
6632
  message: "资源加载性能较慢",
6579
6633
  category: "performance.warning",
6580
6634
  level: "warning",
6581
6635
  data: {
6582
6636
  avg_load_time: stats["resource_stats"].avg_load_time,
6583
- threshold: 2e3
6637
+ threshold: resourceThreshold
6584
6638
  }
6585
6639
  });
6586
6640
  }
@@ -6608,6 +6662,26 @@ const _PerformanceIntegration = class _PerformanceIntegration {
6608
6662
  console.warn("[Sentry Performance] Failed to report to native API:", error2);
6609
6663
  }
6610
6664
  }
6665
+ /**
6666
+ * 采集内存信息
6667
+ */
6668
+ _collectMemoryInfo() {
6669
+ if (!this._options.enableMemory) return null;
6670
+ try {
6671
+ const currentSdk = sdk();
6672
+ if (currentSdk.getPerformance) {
6673
+ const perf = currentSdk.getPerformance();
6674
+ if (perf && perf.memory) {
6675
+ return {
6676
+ jsHeapSizeUsed: perf.memory.jsHeapSizeUsed,
6677
+ jsHeapSizeLimit: perf.memory.jsHeapSizeLimit
6678
+ };
6679
+ }
6680
+ }
6681
+ } catch (_e) {
6682
+ }
6683
+ return null;
6684
+ }
6611
6685
  /**
6612
6686
  * 添加性能上下文信息
6613
6687
  */
@@ -6745,12 +6819,14 @@ const _NetworkBreadcrumbs = class _NetworkBreadcrumbs {
6745
6819
  if (dsnMatch && dsnMatch[1]) {
6746
6820
  dsnUrl = dsnMatch[1];
6747
6821
  }
6748
- } catch (e) {
6822
+ } catch (_e) {
6749
6823
  }
6750
6824
  }
6751
6825
  }
6752
6826
  if (typeof url === "string") {
6753
- const isSentryRequest = dsnUrl && url.indexOf(dsnUrl) !== -1 || url.indexOf("sentry.io") !== -1;
6827
+ const hostMatch = url.match(/^https?:\/\/([^:/\n]+)/i);
6828
+ const requestHost = hostMatch && hostMatch[1] ? hostMatch[1] : "";
6829
+ const isSentryRequest = dsnUrl && requestHost === dsnUrl || requestHost === "sentry.io" || requestHost.endsWith(".sentry.io");
6754
6830
  if (isSentryRequest) {
6755
6831
  return originalRequest.call(this, options);
6756
6832
  }
@@ -6764,7 +6840,7 @@ const _NetworkBreadcrumbs = class _NetworkBreadcrumbs {
6764
6840
  if (traceNetworkBody && requestData) {
6765
6841
  try {
6766
6842
  breadcrumbData["request_body"] = typeof requestData === "string" ? requestData : JSON.stringify(requestData);
6767
- } catch (e) {
6843
+ } catch (_e) {
6768
6844
  breadcrumbData["request_body"] = "[Cannot serialize request body]";
6769
6845
  }
6770
6846
  }
@@ -6777,7 +6853,7 @@ const _NetworkBreadcrumbs = class _NetworkBreadcrumbs {
6777
6853
  if (traceNetworkBody && res.data) {
6778
6854
  try {
6779
6855
  breadcrumbData["response_body"] = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
6780
- } catch (e) {
6856
+ } catch (_e) {
6781
6857
  breadcrumbData["response_body"] = "[Cannot serialize response body]";
6782
6858
  }
6783
6859
  }
@@ -6810,18 +6886,179 @@ const _NetworkBreadcrumbs = class _NetworkBreadcrumbs {
6810
6886
  };
6811
6887
  _NetworkBreadcrumbs.id = "NetworkBreadcrumbs";
6812
6888
  let NetworkBreadcrumbs = _NetworkBreadcrumbs;
6889
+ const PAGE_LIFECYCLE_METHODS = ["onLoad", "onShow", "onHide", "onUnload", "onReady"];
6890
+ const APP_LIFECYCLE_METHODS = ["onLaunch", "onShow", "onHide"];
6891
+ function isUserInteractionHandler(name) {
6892
+ if (PAGE_LIFECYCLE_METHODS.includes(name)) return false;
6893
+ if (name.startsWith("_")) return false;
6894
+ return /^(on|handle|bind)[A-Z]/.test(name) || /[Tt]ap$/.test(name) || /[Cc]lick$/.test(name) || /[Cc]hange$/.test(name) || /[Ss]ubmit$/.test(name) || /[Ss]croll$/.test(name) || /[Ii]nput$/.test(name);
6895
+ }
6896
+ const _PageBreadcrumbs = class _PageBreadcrumbs {
6897
+ constructor(options = {}) {
6898
+ this.name = _PageBreadcrumbs.id;
6899
+ this._options = __spreadValues({
6900
+ enableLifecycle: true,
6901
+ enableUserInteraction: true
6902
+ }, options);
6903
+ }
6904
+ setupOnce() {
6905
+ this._wrapPage();
6906
+ this._wrapApp();
6907
+ }
6908
+ /**
6909
+ * 包装全局 Page() 构造函数
6910
+ */
6911
+ _wrapPage() {
6912
+ const global2 = globalThis;
6913
+ if (typeof global2.Page !== "function") return;
6914
+ const originalPage = global2.Page;
6915
+ const options = this._options;
6916
+ global2.Page = function(pageOptions) {
6917
+ if (pageOptions && typeof pageOptions === "object") {
6918
+ if (options.enableLifecycle) {
6919
+ for (const method of PAGE_LIFECYCLE_METHODS) {
6920
+ if (typeof pageOptions[method] === "function") {
6921
+ const original = pageOptions[method];
6922
+ pageOptions[method] = function(...args) {
6923
+ const route = (this == null ? void 0 : this.route) || (this == null ? void 0 : this.__route__) || "unknown";
6924
+ addBreadcrumb({
6925
+ category: "page.lifecycle",
6926
+ message: `${method}: ${route}`,
6927
+ level: "info",
6928
+ data: {
6929
+ action: method,
6930
+ page: route
6931
+ }
6932
+ });
6933
+ return original.apply(this, args);
6934
+ };
6935
+ }
6936
+ }
6937
+ }
6938
+ if (options.enableUserInteraction) {
6939
+ for (const key of Object.keys(pageOptions)) {
6940
+ if (typeof pageOptions[key] === "function" && isUserInteractionHandler(key)) {
6941
+ const original = pageOptions[key];
6942
+ pageOptions[key] = function(event, ...rest) {
6943
+ const route = (this == null ? void 0 : this.route) || (this == null ? void 0 : this.__route__) || "unknown";
6944
+ const breadcrumbData = {
6945
+ handler: key,
6946
+ page: route
6947
+ };
6948
+ if (event && typeof event === "object") {
6949
+ if (event.target) {
6950
+ if (event.target.id) breadcrumbData["targetId"] = event.target.id;
6951
+ if (event.target.dataset) breadcrumbData["dataset"] = event.target.dataset;
6952
+ }
6953
+ if (event.type) breadcrumbData["eventType"] = event.type;
6954
+ }
6955
+ addBreadcrumb({
6956
+ category: "user.interaction",
6957
+ message: `${key} on ${route}`,
6958
+ level: "info",
6959
+ data: breadcrumbData
6960
+ });
6961
+ return original.apply(this, [event, ...rest]);
6962
+ };
6963
+ }
6964
+ }
6965
+ }
6966
+ }
6967
+ return originalPage(pageOptions);
6968
+ };
6969
+ }
6970
+ /**
6971
+ * 包装全局 App() 构造函数
6972
+ */
6973
+ _wrapApp() {
6974
+ const global2 = globalThis;
6975
+ if (typeof global2.App !== "function") return;
6976
+ const originalApp = global2.App;
6977
+ const options = this._options;
6978
+ global2.App = function(appOptions) {
6979
+ if (appOptions && typeof appOptions === "object" && options.enableLifecycle) {
6980
+ for (const method of APP_LIFECYCLE_METHODS) {
6981
+ if (typeof appOptions[method] === "function") {
6982
+ const original = appOptions[method];
6983
+ appOptions[method] = function(...args) {
6984
+ addBreadcrumb({
6985
+ category: "app.lifecycle",
6986
+ message: `App.${method}`,
6987
+ level: "info",
6988
+ data: {
6989
+ action: method
6990
+ }
6991
+ });
6992
+ return original.apply(this, args);
6993
+ };
6994
+ }
6995
+ }
6996
+ }
6997
+ return originalApp(appOptions);
6998
+ };
6999
+ }
7000
+ };
7001
+ _PageBreadcrumbs.id = "PageBreadcrumbs";
7002
+ let PageBreadcrumbs = _PageBreadcrumbs;
7003
+ const pageBreadcrumbsIntegration = (options) => {
7004
+ return new PageBreadcrumbs(options);
7005
+ };
7006
+ const CONSOLE_LEVELS = ["debug", "info", "warn", "error", "log"];
7007
+ const LEVEL_TO_SEVERITY = {
7008
+ debug: "debug",
7009
+ info: "info",
7010
+ log: "info",
7011
+ warn: "warning",
7012
+ error: "error"
7013
+ };
7014
+ const _ConsoleBreadcrumbs = class _ConsoleBreadcrumbs {
7015
+ constructor(options = {}) {
7016
+ this.name = _ConsoleBreadcrumbs.id;
7017
+ this._levels = options.levels || [...CONSOLE_LEVELS];
7018
+ }
7019
+ setupOnce() {
7020
+ for (const level of this._levels) {
7021
+ if (typeof console[level] !== "function") continue;
7022
+ const original = console[level];
7023
+ console[level] = function(...args) {
7024
+ addBreadcrumb({
7025
+ category: "console",
7026
+ level: LEVEL_TO_SEVERITY[level],
7027
+ message: args.map((a) => {
7028
+ if (typeof a === "string") return a;
7029
+ try {
7030
+ return JSON.stringify(a);
7031
+ } catch (_e) {
7032
+ return String(a);
7033
+ }
7034
+ }).join(" ")
7035
+ });
7036
+ return original.apply(console, args);
7037
+ };
7038
+ }
7039
+ }
7040
+ };
7041
+ _ConsoleBreadcrumbs.id = "ConsoleBreadcrumbs";
7042
+ let ConsoleBreadcrumbs = _ConsoleBreadcrumbs;
7043
+ const consoleBreadcrumbsIntegration = (options) => {
7044
+ return new ConsoleBreadcrumbs(options);
7045
+ };
6813
7046
  const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
6814
7047
  __proto__: null,
7048
+ ConsoleBreadcrumbs,
6815
7049
  Dedupe,
6816
7050
  GlobalHandlers,
6817
7051
  HttpContext,
6818
7052
  LinkedErrors,
6819
7053
  NetworkBreadcrumbs,
7054
+ PageBreadcrumbs,
6820
7055
  PerformanceIntegration,
6821
7056
  RewriteFrames,
6822
7057
  Router,
6823
7058
  System,
6824
7059
  TryCatch,
7060
+ consoleBreadcrumbsIntegration,
7061
+ pageBreadcrumbsIntegration,
6825
7062
  performanceIntegration
6826
7063
  }, Symbol.toStringTag, { value: "Module" }));
6827
7064
  const defaultIntegrations = [
@@ -6858,6 +7095,12 @@ function init(options = {}) {
6858
7095
  opts.integrations.push(new RewriteFrames());
6859
7096
  }
6860
7097
  opts.integrations.push(new NetworkBreadcrumbs({ traceNetworkBody: opts.traceNetworkBody }));
7098
+ if (opts.enableUserInteractionBreadcrumbs !== false) {
7099
+ opts.integrations.push(new PageBreadcrumbs());
7100
+ }
7101
+ if (opts.enableConsoleBreadcrumbs) {
7102
+ opts.integrations.push(new ConsoleBreadcrumbs());
7103
+ }
6861
7104
  setContext("miniapp", {
6862
7105
  platform: appName,
6863
7106
  environment: "miniapp"
@@ -6886,7 +7129,7 @@ function showReportDialog(_options = {}) {
6886
7129
  );
6887
7130
  }
6888
7131
  function wrap(fn) {
6889
- return (function(...args) {
7132
+ return function(...args) {
6890
7133
  return withScope(() => {
6891
7134
  try {
6892
7135
  return fn.apply(this, args);
@@ -6895,7 +7138,7 @@ function wrap(fn) {
6895
7138
  throw error2;
6896
7139
  }
6897
7140
  });
6898
- });
7141
+ };
6899
7142
  }
6900
7143
  function captureFeedback(params) {
6901
7144
  const client = getCurrentScope().getClient();