sentry-miniapp 1.8.1 → 1.9.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.en.md CHANGED
@@ -5,6 +5,7 @@
5
5
  [![github forks](https://img.shields.io/github/forks/lizhiyao/sentry-miniapp?style=social)](https://github.com/lizhiyao/sentry-miniapp/network/members)
6
6
  [![github stars](https://img.shields.io/github/stars/lizhiyao/sentry-miniapp?style=social)](https://github.com/lizhiyao/sentry-miniapp/stargazers)
7
7
  ![test coverage](https://img.shields.io/badge/test%20coverage-100%25-brightgreen.svg)
8
+ [![Sentry Community SDK](https://img.shields.io/badge/Sentry-Community%20SDK-362d59?logo=sentry)](https://docs.sentry.io/platforms/#sdks-supported-by-our-community)
8
9
  [![license](https://img.shields.io/github/license/lizhiyao/sentry-miniapp)](./LICENSE)
9
10
 
10
11
  [简体中文](./README.md) | English
@@ -13,7 +14,7 @@ A **mini program monitoring SDK** built on `@sentry/core`, providing **error mon
13
14
 
14
15
  > **What are Mini Programs?** Mini programs (小程序) are lightweight apps that run inside super-apps like WeChat, Alipay, and ByteDance/Douyin. They form a massive ecosystem in China with **hundreds of millions of daily active users**, but have no direct equivalent in the Western tech stack. Think of them as a hybrid between PWAs and native apps, but hosted within a platform's sandbox.
15
16
 
16
- > **📰 Featured Article (Chinese)**: [《我把 Sentry 接进了 7 端小程序:从异常捕获、Breadcrumb 到 Source Map 定位》](https://juejin.cn/post/7621871037853843465) — multi-platform integration, Breadcrumb context, offline buffering, and Source Map workflow walked through end-to-end. If you find this project useful, please consider giving it a ⭐ Star.
17
+ > **📰 Featured Article (Chinese)**: [《我给 Sentry 提了个 PR,后来 sentry-miniapp 进了官方文档》](https://juejin.cn/post/7636106283963760681) — How sentry-miniapp got listed in Sentry's official community-supported SDKs documentation. If you find this project useful, please consider giving it a ⭐ Star.
17
18
 
18
19
  <details>
19
20
  <summary><b>🆕 What's New: v1.3 → v1.8 (click to expand)</b></summary>
@@ -38,7 +39,7 @@ See [CHANGELOG.md](./CHANGELOG.md) for full details.
38
39
  - **Modern Architecture**: Built on the latest Sentry JavaScript V10 SDK core modules.
39
40
  - **True Multi-Platform Support**: Built-in API abstraction engine — one codebase seamlessly supports **WeChat, Alipay, ByteDance, Baidu, QQ, DingTalk, and Kuaishou** mini program platforms.
40
41
  - **Automatic Exception Capture**: No business code intrusion required. Automatically hooks into lifecycle error listeners (`onError`, `onUnhandledRejection`, `onPageNotFound`, `onMemoryWarning`).
41
- - **Rich Context Breadcrumbs**: Automatically records device info, user tap/touch interactions, network requests (XHR/Fetch), and page navigation paths.
42
+ - **Rich Context Breadcrumbs**: Automatically records device info, user tap/touch interactions, network requests (XHR/Fetch), and page lifecycle events.
42
43
  - **Built-in SourceMap Path Normalization**: Handles virtual stack paths across WeChat, Alipay, ByteDance and other platforms. Works with sentry-cli for seamless SourceMap resolution.
43
44
  - **Offline Caching for Weak Networks**: Designed for mini program network conditions. Automatically caches events to local storage on network failure, silently retries when connectivity is restored.
44
45
  - **Deep Performance Monitoring**: Integrates mini program Performance API for navigation timing (FCP/LCP), render performance, resource loading, and custom performance marks.
@@ -57,8 +58,6 @@ See [CHANGELOG.md](./CHANGELOG.md) for full details.
57
58
  npm install sentry-miniapp
58
59
  ```
59
60
 
60
- > **Note:** Starting from `v1.1.0`, the build strategy has been optimized (dependencies are inlined), so there is **no need** to install `@sentry/core` separately.
61
-
62
61
  *Tip: If you don't use npm, you can also copy `examples/wxapp/lib/sentry-miniapp.js` from this repository directly into your mini program project.*
63
62
 
64
63
  ---
@@ -95,11 +94,10 @@ Sentry.init({
95
94
  release: 'my-project-name@1.0.0',
96
95
 
97
96
  // --- Mini Program Configuration ---
98
- platform: 'wechat', // Current platform (wechat | alipay | bytedance | dd | swan, etc.)
99
- enableSystemInfo: true, // Auto-collect system and device info
97
+ platform: 'wechat', // Optional event platform label; runtime platform is auto-detected
100
98
  enableUserInteractionBreadcrumbs: true, // Auto-record user tap events
101
- enableNavigationBreadcrumbs: true, // Auto-record page navigation
102
- traceNetworkBody: true, // Record request/response bodies in breadcrumbs (default: false)
99
+ enableConsoleBreadcrumbs: false, // Record console output as breadcrumbs (default: false)
100
+ traceNetworkBody: false, // Record request/response bodies in breadcrumbs (default: false)
103
101
 
104
102
  // --- Offline Cache & Reliability ---
105
103
  enableOfflineCache: true, // Enable offline caching with retry (default: true)
@@ -118,15 +116,6 @@ Sentry.init({
118
116
  // --- Session & Network Monitoring ---
119
117
  enableAutoSessionTracking: true, // Auto session lifecycle management (default: true)
120
118
  enableNetworkStatusMonitoring: true, // Real-time network status monitoring (default: true)
121
-
122
- // Optional: Performance monitoring
123
- integrations: [
124
- Sentry.performanceIntegration({
125
- enableNavigation: true, // Navigation timing
126
- enableRender: true, // Render timing
127
- enableResource: true, // Resource loading timing
128
- }),
129
- ]
130
119
  });
131
120
 
132
121
  App({
@@ -136,6 +125,8 @@ App({
136
125
  });
137
126
  ```
138
127
 
128
+ Default integrations already include automatic exception capture, performance monitoring, SourceMap path normalization, network breadcrumbs, session tracking, and network status monitoring. Only pass `integrations` when you intentionally want to take over the full integration list, because it replaces the defaults.
129
+
139
130
  ---
140
131
 
141
132
  ## Advanced Usage
@@ -322,6 +313,41 @@ If errors are not being reported, check:
322
313
 
323
314
  **Not currently.** Sentry's official Replay feature relies on standard browser DOM (via rrweb recording). Mini programs use a dual-thread architecture without standard DOM access. We recommend using **Breadcrumbs** combined with **custom logging** to reconstruct user action sequences.
324
315
 
316
+ ### 3. How do I monitor the H5 build of a uni-app / Taro project?
317
+
318
+ `sentry-miniapp` **only adapts mini program platforms** and does not implement browser-native signals (`window.onerror`, `fetch` / `XHR` interception, `PerformanceObserver`, etc.). For the H5 build, use Sentry's official [`@sentry/browser`](https://docs.sentry.io/platforms/javascript/) directly — full feature coverage, maintained upstream.
319
+
320
+ > When this SDK is initialized in a browser environment, it logs a warning suggesting you switch to `@sentry/browser`.
321
+
322
+ Recommended pattern: split SDKs by platform via **uni-app conditional compilation**:
323
+
324
+ ```ts
325
+ // utils/sentry.ts
326
+ let Sentry: any;
327
+
328
+ // #ifdef H5
329
+ Sentry = require('@sentry/browser');
330
+ Sentry.init({
331
+ dsn: 'YOUR_DSN',
332
+ environment: 'production',
333
+ tracesSampleRate: 0.2,
334
+ });
335
+ // #endif
336
+
337
+ // #ifdef MP-WEIXIN || MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-QQ || MP-KUAISHOU || MP-DINGTALK
338
+ Sentry = require('sentry-miniapp');
339
+ Sentry.init({
340
+ dsn: 'YOUR_DSN',
341
+ environment: 'production',
342
+ tracesSampleRate: 0.2,
343
+ });
344
+ // #endif
345
+
346
+ export default Sentry;
347
+ ```
348
+
349
+ Both sides report to the same Sentry DSN so all errors land in a single project. For Taro, use `process.env.TARO_ENV === 'h5'` to branch similarly.
350
+
325
351
  ---
326
352
 
327
353
  ## Documentation
package/README.md CHANGED
@@ -5,13 +5,14 @@
5
5
  [![github forks](https://img.shields.io/github/forks/lizhiyao/sentry-miniapp?style=social)](https://github.com/lizhiyao/sentry-miniapp/network/members)
6
6
  [![github stars](https://img.shields.io/github/stars/lizhiyao/sentry-miniapp?style=social)](https://github.com/lizhiyao/sentry-miniapp/stargazers)
7
7
  ![test coverage](https://img.shields.io/badge/test%20coverage-100%25-brightgreen.svg)
8
+ [![Sentry Community SDK](https://img.shields.io/badge/Sentry-Community%20SDK-362d59?logo=sentry)](https://docs.sentry.io/platforms/#sdks-supported-by-our-community)
8
9
  [![license](https://img.shields.io/github/license/lizhiyao/sentry-miniapp)](./LICENSE)
9
10
 
10
11
  简体中文 | [English](./README.en.md)
11
12
 
12
13
  一个基于 `@sentry/core` 核心构建的**小程序监控 SDK**,提供**异常监控**、**性能监控**、离线缓存、分布式追踪等能力。支持微信、支付宝、字节跳动、百度、QQ、钉钉、快手等多端小程序及 Taro / uni-app 等跨端框架。
13
14
 
14
- > **📰 最新文章**:[《我把 Sentry 接进了 7 端小程序:从异常捕获、Breadcrumb 到 Source Map 定位》](https://juejin.cn/post/7621871037853843465) — 多端统一接入、Breadcrumb 上下文、弱网兜底、Source Map 实战,一篇串完整套方案。觉得有用请帮忙点个 ⭐ Star,让更多小程序团队找到它。
15
+ > **📰 最新文章**:[《我给 Sentry 提了个 PR,后来 sentry-miniapp 进了官方文档》](https://juejin.cn/post/7636106283963760681) — sentry-miniapp 已被收录进 Sentry 官方文档的 community-supported SDK 列表,这篇文章记录这件事的来龙去脉。觉得有用请帮忙点个 ⭐ Star,让更多小程序团队找到它。
15
16
 
16
17
  <details>
17
18
  <summary><b>🆕 v1.3 → v1.8 What's New(点击展开)</b></summary>
@@ -36,11 +37,11 @@
36
37
  - **🚀 现代架构**:基于最新的 Sentry JavaScript V10 SDK 核心模块构建。
37
38
  - **📱 真正的多端支持**:内置 API 抹平引擎,一套代码无缝兼容**微信、支付宝、字节、百度、QQ、钉钉、快手**等主流小程序平台。
38
39
  - **🎯 全自动异常捕获**:无需侵入业务代码,自动监听并上报生命周期异常(`onError`、`onUnhandledRejection`、`onPageNotFound`、`onMemoryWarning`)。
39
- - **🍞 丰富的上下文面包屑**:自动记录设备信息、用户点击/触摸操作、网络请求(XHR/Fetch)、以及页面路由导航路径。
40
+ - **🍞 丰富的上下文面包屑**:自动记录设备信息、用户点击/触摸操作、网络请求(XHR/Fetch)以及页面生命周期。
40
41
  - **🗺️ 内置 SourceMap 路径抹平**:自动处理微信、支付宝、字节等多端小程序的虚拟堆栈路径,配合 sentry-cli 极简实现 SourceMap 解析。
41
42
  - **📡 弱网离线缓存机制**:专为小程序网络环境设计,断网或发送失败时自动缓存 Event 到本地 Storage,网络恢复后静默重试上报,确保数据不丢失。
42
43
  - **⚡ 深度性能监控**:集成小程序 Performance API,全面采集导航性能(FCP/LCP)、渲染性能、资源加载耗时及用户自定义性能标记。
43
- - **�️ 智能降噪与过滤**:内置强大的错误去重和采样率控制机制,避免日志风暴。
44
+ - **🛡️ 智能降噪与过滤**:内置强大的错误去重和采样率控制机制,避免日志风暴。
44
45
  - **🔧 跨端框架友好**:完美支持在 Taro、uni-app 等第三方多端编译框架中集成使用。
45
46
  - **🔗 分布式追踪**:自动在网络请求中注入 `sentry-trace` / `baggage` 头,串联小程序与后端服务的完整调用链。
46
47
  - **📊 Session 健康监控**:自动管理会话生命周期,在 Sentry Release Health 面板展示崩溃率和会话健康数据。
@@ -57,8 +58,6 @@
57
58
  npm install sentry-miniapp
58
59
  ```
59
60
 
60
- > **注意:** `v1.1.0` 及以上版本已优化构建策略(内联依赖),**无需**再额外安装 `@sentry/core`。
61
-
62
61
  *提示:如果您不使用 npm,也可以直接将项目仓库中 `examples/wxapp/lib/sentry-miniapp.js` 文件复制到小程序项目中引入。*
63
62
 
64
63
  ---
@@ -95,11 +94,10 @@ Sentry.init({
95
94
  release: 'my-project-name@1.0.0', // 版本号,建议与 sourcemap 配合使用
96
95
 
97
96
  // --- 小程序特性配置 ---
98
- platform: 'wechat', // 当前平台 (wechat | alipay | bytedance | dd | swan 等)
99
- enableSystemInfo: true, // 自动采集系统与设备信息
97
+ platform: 'wechat', // 可选:用于标识事件平台;SDK 会自动识别运行时平台
100
98
  enableUserInteractionBreadcrumbs: true, // 自动记录用户点击行为
101
- enableNavigationBreadcrumbs: true, // 自动记录页面路由跳转
102
- traceNetworkBody: true, // [新增] 是否在面包屑中记录网络请求的请求体和响应体 (默认 false)
99
+ enableConsoleBreadcrumbs: false, // 是否记录 console 输出为面包屑(默认 false)
100
+ traceNetworkBody: false, // 是否在面包屑中记录网络请求/响应体(默认 false,按需开启)
103
101
 
104
102
  // --- 离线缓存与可靠性 ---
105
103
  enableOfflineCache: true, // 开启断网离线缓存与重试机制 (默认开启)
@@ -112,21 +110,12 @@ Sentry.init({
112
110
  sampleRate: 1.0, // 异常上报采样率 (0.0 - 1.0)
113
111
 
114
112
  // --- 分布式追踪 ---
115
- enableTracePropagation: true, // [新增] 自动在请求头中注入 sentry-trace/baggage(默认 true)
116
- tracePropagationTargets: ['api.example.com'], // [新增] 仅对指定域名注入追踪头(为空则全部注入)
113
+ enableTracePropagation: true, // 自动在请求头中注入 sentry-trace/baggage(默认 true)
114
+ tracePropagationTargets: ['api.example.com'], // 仅对指定域名注入追踪头(为空则全部注入)
117
115
 
118
116
  // --- Session 与网络监控 ---
119
- enableAutoSessionTracking: true, // [新增] 自动管理 Session 生命周期(默认 true)
120
- enableNetworkStatusMonitoring: true, // [新增] 实时监控网络状态变化(默认 true)
121
-
122
- // 可选:性能监控配置
123
- integrations: [
124
- Sentry.performanceIntegration({
125
- enableNavigation: true, // 导航耗时监控
126
- enableRender: true, // 渲染耗时监控
127
- enableResource: true, // 资源加载耗时
128
- }),
129
- ]
117
+ enableAutoSessionTracking: true, // 自动管理 Session 生命周期(默认 true)
118
+ enableNetworkStatusMonitoring: true, // 实时监控网络状态变化(默认 true)
130
119
  });
131
120
 
132
121
  // 初始化完成后,再调用 App
@@ -137,6 +126,8 @@ App({
137
126
  });
138
127
  ```
139
128
 
129
+ 默认集成已经包含自动异常捕获、性能监控、Source Map 路径归一化、网络面包屑、Session 和网络状态监控。只有在需要完全接管集成列表时才传入 `integrations`,否则会覆盖默认集成。
130
+
140
131
  ---
141
132
 
142
133
  ## 📚 常用进阶用法
@@ -225,8 +216,8 @@ SDK 内置了多端堆栈路径归一化能力(`enableSourceMap: true`,默
225
216
  **快速上传示例:**
226
217
 
227
218
  ```bash
228
- sentry-cli releases files my-miniapp@1.0.0 upload-sourcemaps ./dist \
229
- --url-prefix app:///” \
219
+ sentry-cli releases files "my-miniapp@1.0.0" upload-sourcemaps ./dist \
220
+ --url-prefix "app:///" \
230
221
  --ext js --ext map
231
222
  ```
232
223
 
@@ -337,6 +328,41 @@ App({
337
328
  目前 **不支持** `Sentry.replayIntegration()`。
338
329
  Sentry 官方的 Replay 功能强依赖于浏览器标准 DOM 环境(通过 rrweb 录制)。小程序采用双线程架构且没有开放标准 DOM 接口,无法直接复用。建议通过完善**Breadcrumbs(面包屑路径)**结合**自定义日志**来还原用户操作现场。
339
330
 
331
+ ### 3. uni-app / Taro 项目的 H5 端如何监控?
332
+
333
+ `sentry-miniapp` **仅适配各小程序平台**,不内置浏览器原生信号(`window.onerror`、`fetch` / `XHR` 拦截、`PerformanceObserver` 等)。H5 端请直接使用 Sentry 官方的 [`@sentry/browser`](https://docs.sentry.io/platforms/javascript/),能力完整、长期由官方维护。
334
+
335
+ > SDK 在 H5 环境下被错误初始化时,会输出引导提示,提醒切换到 `@sentry/browser`。
336
+
337
+ 推荐通过 **uni-app 条件编译**按端引入:
338
+
339
+ ```ts
340
+ // utils/sentry.ts
341
+ let Sentry: any;
342
+
343
+ // #ifdef H5
344
+ Sentry = require('@sentry/browser');
345
+ Sentry.init({
346
+ dsn: 'YOUR_DSN',
347
+ environment: 'production',
348
+ tracesSampleRate: 0.2,
349
+ });
350
+ // #endif
351
+
352
+ // #ifdef MP-WEIXIN || MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-QQ || MP-KUAISHOU || MP-DINGTALK
353
+ Sentry = require('sentry-miniapp');
354
+ Sentry.init({
355
+ dsn: 'YOUR_DSN',
356
+ environment: 'production',
357
+ tracesSampleRate: 0.2,
358
+ });
359
+ // #endif
360
+
361
+ export default Sentry;
362
+ ```
363
+
364
+ 两端上报同一个 Sentry DSN,可以在同一个 Project 里聚合查看错误。Taro 用户可以用类似的 `process.env.TARO_ENV === 'h5'` 判断分端引入。
365
+
340
366
  ---
341
367
 
342
368
  ## 📖 文档导航