sentry-miniapp 1.2.0 → 1.3.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.
package/README.md CHANGED
@@ -22,6 +22,7 @@
22
22
  - **📱 真正的多端支持**:内置 API 抹平引擎,一套代码无缝兼容**微信、支付宝、字节、百度、QQ、钉钉、快手**等主流小程序平台。
23
23
  - **🎯 全自动异常捕获**:无需侵入业务代码,自动监听并上报生命周期异常(`onError`、`onUnhandledRejection`、`onPageNotFound`、`onMemoryWarning`)。
24
24
  - **🍞 丰富的上下文面包屑**:自动记录设备信息、用户点击/触摸操作、网络请求(XHR/Fetch)、以及页面路由导航路径。
25
+ - **🗺️ 内置 SourceMap 路径抹平**:自动处理微信、支付宝、字节等多端小程序的虚拟堆栈路径,配合 sentry-cli 极简实现 SourceMap 解析。
25
26
  - **📡 弱网离线缓存机制**:专为小程序网络环境设计,断网或发送失败时自动缓存 Event 到本地 Storage,网络恢复后静默重试上报,确保数据不丢失。
26
27
  - **⚡ 深度性能监控**:集成小程序 Performance API,全面采集导航性能(FCP/LCP)、渲染性能、资源加载耗时及用户自定义性能标记。
27
28
  - **�️ 智能降噪与过滤**:内置强大的错误去重和采样率控制机制,避免日志风暴。
@@ -71,6 +72,9 @@ Sentry.init({
71
72
  // --- 离线缓存与可靠性 ---
72
73
  enableOfflineCache: true, // 开启断网离线缓存与重试机制 (默认开启)
73
74
 
75
+ // --- SourceMap 支持 ---
76
+ enableSourceMap: true, // 开启自动将堆栈的虚拟路径转为统一格式,配合上传 sourcemap 时的 --url-prefix "app:///"
77
+
74
78
  // --- 性能与采样率 ---
75
79
  sampleRate: 1.0, // 异常上报采样率 (0.0 - 1.0)
76
80
 
@@ -147,6 +151,27 @@ Sentry.measurePerformance('fetch-user-data', 'api-request-start', 'api-request-e
147
151
 
148
152
  ---
149
153
 
154
+ ## 🗺️ Source Map 支持与配置
155
+
156
+ 在小程序中,报错堆栈的路径通常是各种虚拟路径(如 `appservice/pages/index.js`),这导致直接上传的 Source Map 无法被 Sentry 正确解析。
157
+
158
+ SDK 内部已经为您解决了这个痛点:
159
+ 只要在 `Sentry.init` 时开启了 `enableSourceMap: true`(默认开启),SDK 会在报错时自动拦截并抹平各平台的虚拟路径,统一替换为标准前缀 `app:///`。
160
+
161
+ 您**只需要在打包上传 Source Map 时,确保配置的 `url-prefix` 为 `app:///` 即可**。
162
+
163
+ **使用 sentry-cli 上传示例:**
164
+
165
+ ```bash
166
+ sentry-cli releases files "your-project-release-id" upload-sourcemaps ./dist \
167
+ --url-prefix "app:///" \
168
+ --ext .js --ext .map
169
+ ```
170
+
171
+ *(注:在微信开发者工具上传代码时,请**务必关闭**工具自带的“ES6转ES5”和“代码压缩”功能,将这些工作交给 Webpack/Vite 等构建工具,以防行列号错位。)*
172
+
173
+ ---
174
+
150
175
  ## ❓ 常见问题 (FAQ)
151
176
 
152
177
  ### 1. 初始化后无法自动上报异常,必须在 `onError` 中手动调 API 吗?
@@ -4938,7 +4938,7 @@ function addBreadcrumb(breadcrumb, hint) {
4938
4938
  }
4939
4939
  isolationScope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs);
4940
4940
  }
4941
- const SDK_VERSION = "1.2.0";
4941
+ const SDK_VERSION = "1.3.0";
4942
4942
  const SDK_NAME = "sentry.javascript.miniapp";
4943
4943
  const getSDK = () => {
4944
4944
  let currentSdk = {
@@ -6665,6 +6665,47 @@ let PerformanceIntegration = _PerformanceIntegration;
6665
6665
  const performanceIntegration = (options) => {
6666
6666
  return () => new PerformanceIntegration(options);
6667
6667
  };
6668
+ const _RewriteFrames = class _RewriteFrames {
6669
+ constructor(options = {}) {
6670
+ this.name = _RewriteFrames.id;
6671
+ this._prefix = options.prefix || "app:///";
6672
+ }
6673
+ /**
6674
+ * @inheritDoc
6675
+ */
6676
+ setupOnce() {
6677
+ }
6678
+ /**
6679
+ * @inheritDoc
6680
+ */
6681
+ processEvent(event) {
6682
+ if (event.exception && event.exception.values) {
6683
+ event.exception.values.forEach((exception) => {
6684
+ if (exception.stacktrace && exception.stacktrace.frames) {
6685
+ exception.stacktrace.frames.forEach((frame) => {
6686
+ if (frame.filename) {
6687
+ frame.filename = this._normalizeFilename(frame.filename);
6688
+ }
6689
+ });
6690
+ }
6691
+ });
6692
+ }
6693
+ return event;
6694
+ }
6695
+ /**
6696
+ * Normalizes a filename from various miniapp platforms
6697
+ */
6698
+ _normalizeFilename(filename) {
6699
+ let normalized = filename;
6700
+ normalized = normalized.replace(/^(appservice|app-service|WAService)\//i, "").replace(/^https?:\/\/[^/]+\//i, "").replace(/^[a-z]+:\/\//i, "").replace(/^\//, "");
6701
+ if (normalized.startsWith(this._prefix)) {
6702
+ return normalized;
6703
+ }
6704
+ return `${this._prefix}${normalized}`;
6705
+ }
6706
+ };
6707
+ _RewriteFrames.id = "RewriteFrames";
6708
+ let RewriteFrames = _RewriteFrames;
6668
6709
  const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
6669
6710
  __proto__: null,
6670
6711
  Dedupe,
@@ -6672,6 +6713,7 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
6672
6713
  HttpContext,
6673
6714
  LinkedErrors,
6674
6715
  PerformanceIntegration,
6716
+ RewriteFrames,
6675
6717
  Router,
6676
6718
  System,
6677
6719
  TryCatch,
@@ -6707,6 +6749,9 @@ function init(options = {}) {
6707
6749
  stackParser: () => [],
6708
6750
  transport: options.transport
6709
6751
  });
6752
+ if (opts.enableSourceMap !== false) {
6753
+ opts.integrations.push(new RewriteFrames());
6754
+ }
6710
6755
  setContext("miniapp", {
6711
6756
  platform: appName,
6712
6757
  environment: "miniapp"