sentry-miniapp 1.8.2 → 1.10.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
@@ -10,7 +10,7 @@
10
10
 
11
11
  [简体中文](./README.md) | English
12
12
 
13
- A **mini program monitoring SDK** built on `@sentry/core`, providing **error monitoring**, **performance monitoring**, offline caching, and distributed tracing. Supports WeChat, Alipay, ByteDance, Baidu, QQ, DingTalk, Kuaishou mini programs and cross-platform frameworks (Taro / uni-app).
13
+ A **mini program monitoring SDK** built on `@sentry/core`, providing **error monitoring**, **performance monitoring**, offline caching, and distributed tracing. Supports WeChat, Alipay, ByteDance, Baidu, QQ, DingTalk, Kuaishou mini programs, **WeChat / Douyin mini games**, and cross-platform frameworks (Taro / uni-app).
14
14
 
15
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.
16
16
 
@@ -38,6 +38,7 @@ See [CHANGELOG.md](./CHANGELOG.md) for full details.
38
38
 
39
39
  - **Modern Architecture**: Built on the latest Sentry JavaScript V10 SDK core modules.
40
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.
41
+ - **Mini Game Support**: Auto-detects mini-game environments — error / network / device monitoring works out of the box, plus mini-game-specific **cold-start first-frame timing** and **frame-rate / jank (FPS) monitoring** (see "Mini Game Support" below).
41
42
  - **Automatic Exception Capture**: No business code intrusion required. Automatically hooks into lifecycle error listeners (`onError`, `onUnhandledRejection`, `onPageNotFound`, `onMemoryWarning`).
42
43
  - **Rich Context Breadcrumbs**: Automatically records device info, user tap/touch interactions, network requests (XHR/Fetch), and page lifecycle events.
43
44
  - **Built-in SourceMap Path Normalization**: Handles virtual stack paths across WeChat, Alipay, ByteDance and other platforms. Works with sentry-cli for seamless SourceMap resolution.
@@ -298,6 +299,43 @@ App({
298
299
 
299
300
  ---
300
301
 
302
+ ## Mini Game Support
303
+
304
+ `sentry-miniapp` also works in **mini games** (WeChat / ByteDance mini games, etc.). Mini games have no `App()`/`Page()`/page routing, but expose platform APIs like `wx.onError`, `wx.request`, `wx.getDeviceInfo`, and `wx.getPerformance`. Most SDK capabilities work out of the box, plus mini-game-specific cold-start and frame-rate monitoring.
305
+
306
+ **Initialization is identical to mini programs** — the SDK auto-detects the mini-game environment and enables the relevant features:
307
+
308
+ ```js
309
+ import * as Sentry from 'sentry-miniapp';
310
+
311
+ Sentry.init({
312
+ dsn: 'YOUR_DSN',
313
+ // Enabled by default in mini-game environments; set to false to disable:
314
+ // enableMinigameLifecycle: true, // cold-start first-frame timing + launch scene + onShow/onHide breadcrumbs
315
+ // enableMinigameFrameRate: true, // FPS / jank monitoring
316
+
317
+ // Fine-tune frame-rate monitoring (FPS warning threshold, jank threshold, report interval, etc.):
318
+ // minigameFrameRateOptions: { fpsWarningThreshold: 45 },
319
+ });
320
+ ```
321
+
322
+ ### Capability matrix
323
+
324
+ | Capability | Mini Game | Notes |
325
+ |------------|:---------:|-------|
326
+ | Exception / unhandled rejection capture | ✅ | `wx.onError` / `wx.onUnhandledRejection` |
327
+ | API request monitoring (count / duration / status) | ✅ | wraps `wx.request` |
328
+ | Network status monitoring | ✅ | `wx.onNetworkStatusChange` |
329
+ | Device info / context breadcrumbs | ✅ | `wx.getDeviceInfo` etc. |
330
+ | Resource load timing | ✅ | `wx.getPerformance()` |
331
+ | **Cold-start first-frame timing + launch scene** | ✅ New | `MinigameIntegration` (first `requestAnimationFrame` ≈ first frame) |
332
+ | **Frame rate / jank monitoring** | ✅ New | `MinigameFrameRateIntegration` (RAF FPS sampling, long frames → jank, periodic `minigame.framerate` context) |
333
+ | Page lifecycle / tap breadcrumbs | ➖ | No pages in mini games — auto-skipped; use `onShow/onHide` breadcrumbs or manual `addBreadcrumb` |
334
+
335
+ > These two integrations are enabled by default only in mini-game environments. In particular, **frame-rate monitoring relies on a global `requestAnimationFrame`**: mini games have one (bound to the real render loop), whereas mini programs use a dual-thread architecture whose logic layer has no global `requestAnimationFrame` — so even if enabled there, it safely no-ops (it cannot measure page render frame rate).
336
+
337
+ ---
338
+
301
339
  ## FAQ
302
340
 
303
341
  ### 1. Do I need to manually report errors in `onError`?
@@ -313,6 +351,41 @@ If errors are not being reported, check:
313
351
 
314
352
  **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.
315
353
 
354
+ ### 3. How do I monitor the H5 build of a uni-app / Taro project?
355
+
356
+ `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.
357
+
358
+ > When this SDK is initialized in a browser environment, it logs a warning suggesting you switch to `@sentry/browser`.
359
+
360
+ Recommended pattern: split SDKs by platform via **uni-app conditional compilation**:
361
+
362
+ ```ts
363
+ // utils/sentry.ts
364
+ let Sentry: any;
365
+
366
+ // #ifdef H5
367
+ Sentry = require('@sentry/browser');
368
+ Sentry.init({
369
+ dsn: 'YOUR_DSN',
370
+ environment: 'production',
371
+ tracesSampleRate: 0.2,
372
+ });
373
+ // #endif
374
+
375
+ // #ifdef MP-WEIXIN || MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-QQ || MP-KUAISHOU || MP-DINGTALK
376
+ Sentry = require('sentry-miniapp');
377
+ Sentry.init({
378
+ dsn: 'YOUR_DSN',
379
+ environment: 'production',
380
+ tracesSampleRate: 0.2,
381
+ });
382
+ // #endif
383
+
384
+ export default Sentry;
385
+ ```
386
+
387
+ 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.
388
+
316
389
  ---
317
390
 
318
391
  ## Documentation
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  简体中文 | [English](./README.en.md)
12
12
 
13
- 一个基于 `@sentry/core` 核心构建的**小程序监控 SDK**,提供**异常监控**、**性能监控**、离线缓存、分布式追踪等能力。支持微信、支付宝、字节跳动、百度、QQ、钉钉、快手等多端小程序及 Taro / uni-app 等跨端框架。
13
+ 一个基于 `@sentry/core` 核心构建的**小程序监控 SDK**,提供**异常监控**、**性能监控**、离线缓存、分布式追踪等能力。支持微信、支付宝、字节跳动、百度、QQ、钉钉、快手等多端小程序,以及微信 / 抖音等**小游戏**,并兼容 Taro / uni-app 等跨端框架。
14
14
 
15
15
  > **📰 最新文章**:[《我给 Sentry 提了个 PR,后来 sentry-miniapp 进了官方文档》](https://juejin.cn/post/7636106283963760681) — sentry-miniapp 已被收录进 Sentry 官方文档的 community-supported SDK 列表,这篇文章记录这件事的来龙去脉。觉得有用请帮忙点个 ⭐ Star,让更多小程序团队找到它。
16
16
 
@@ -36,6 +36,7 @@
36
36
 
37
37
  - **🚀 现代架构**:基于最新的 Sentry JavaScript V10 SDK 核心模块构建。
38
38
  - **📱 真正的多端支持**:内置 API 抹平引擎,一套代码无缝兼容**微信、支付宝、字节、百度、QQ、钉钉、快手**等主流小程序平台。
39
+ - **🎮 小游戏支持**:自动识别小游戏环境,异常 / 网络 / 设备监控开箱即用,并提供小游戏专属的**冷启动首帧耗时**与**帧率 / 卡顿(FPS / jank)监控**(详见下文「小游戏支持」)。
39
40
  - **🎯 全自动异常捕获**:无需侵入业务代码,自动监听并上报生命周期异常(`onError`、`onUnhandledRejection`、`onPageNotFound`、`onMemoryWarning`)。
40
41
  - **🍞 丰富的上下文面包屑**:自动记录设备信息、用户点击/触摸操作、网络请求(XHR/Fetch)以及页面生命周期。
41
42
  - **🗺️ 内置 SourceMap 路径抹平**:自动处理微信、支付宝、字节等多端小程序的虚拟堆栈路径,配合 sentry-cli 极简实现 SourceMap 解析。
@@ -311,6 +312,43 @@ App({
311
312
 
312
313
  ---
313
314
 
315
+ ## 🎮 小游戏支持
316
+
317
+ `sentry-miniapp` 同样适用于**小游戏**(微信小游戏 / 抖音小游戏等)。小游戏没有 `App()`/`Page()`/页面路由,但具备 `wx.onError`、`wx.request`、`wx.getDeviceInfo`、`wx.getPerformance` 等平台能力,因此 SDK 的大部分能力开箱即用,并额外提供小游戏专属的冷启动与帧率监控。
318
+
319
+ **初始化与小程序完全一致**,SDK 会自动检测小游戏环境并启用对应能力:
320
+
321
+ ```js
322
+ import * as Sentry from 'sentry-miniapp';
323
+
324
+ Sentry.init({
325
+ dsn: 'YOUR_DSN',
326
+ // 小游戏环境下,以下两项默认即为开启,可显式关闭:
327
+ // enableMinigameLifecycle: true, // 冷启动首帧耗时 + 启动场景 + onShow/onHide 面包屑
328
+ // enableMinigameFrameRate: true, // 帧率(FPS)/卡顿(jank)监控
329
+
330
+ // 帧率监控细调(FPS 告警阈值、卡顿阈值、上报间隔等):
331
+ // minigameFrameRateOptions: { fpsWarningThreshold: 45 },
332
+ });
333
+ ```
334
+
335
+ ### 能力矩阵
336
+
337
+ | 能力 | 小游戏 | 说明 |
338
+ |------|:------:|------|
339
+ | 异常 / 未处理 Promise 捕获 | ✅ | `wx.onError` / `wx.onUnhandledRejection` |
340
+ | API 请求监控(请求数 / 耗时 / 状态码) | ✅ | 包裹 `wx.request` |
341
+ | 网络状态监控 | ✅ | `wx.onNetworkStatusChange` |
342
+ | 设备信息 / 上下文面包屑 | ✅ | `wx.getDeviceInfo` 等 |
343
+ | 资源加载耗时 | ✅ | `wx.getPerformance()` |
344
+ | **冷启动首帧耗时 + 启动场景** | ✅ 新增 | `MinigameIntegration`(首个 `requestAnimationFrame` 近似首帧) |
345
+ | **帧率 / 卡顿监控** | ✅ 新增 | `MinigameFrameRateIntegration`(RAF 采样 FPS,长帧记 jank,周期上报 `minigame.framerate` 上下文) |
346
+ | 页面生命周期 / 点击面包屑 | ➖ | 小游戏无页面,自动跳过;行为追踪请用 `onShow/onHide` 面包屑或手动 `addBreadcrumb` |
347
+
348
+ > 上述两个集成仅在小游戏环境默认启用。其中**帧率监控依赖全局 `requestAnimationFrame`**:小游戏有(绑定真实渲染帧),而小程序为双线程架构、逻辑层没有全局 `requestAnimationFrame`,因此在小程序中即使开启也会安全 no-op(无法测量页面渲染帧率)。
349
+
350
+ ---
351
+
314
352
  ## ❓ 常见问题 (FAQ)
315
353
 
316
354
  ### 1. 初始化后无法自动上报异常,必须在 `onError` 中手动调 API 吗?
@@ -328,6 +366,41 @@ App({
328
366
  目前 **不支持** `Sentry.replayIntegration()`。
329
367
  Sentry 官方的 Replay 功能强依赖于浏览器标准 DOM 环境(通过 rrweb 录制)。小程序采用双线程架构且没有开放标准 DOM 接口,无法直接复用。建议通过完善**Breadcrumbs(面包屑路径)**结合**自定义日志**来还原用户操作现场。
330
368
 
369
+ ### 3. uni-app / Taro 项目的 H5 端如何监控?
370
+
371
+ `sentry-miniapp` **仅适配各小程序平台**,不内置浏览器原生信号(`window.onerror`、`fetch` / `XHR` 拦截、`PerformanceObserver` 等)。H5 端请直接使用 Sentry 官方的 [`@sentry/browser`](https://docs.sentry.io/platforms/javascript/),能力完整、长期由官方维护。
372
+
373
+ > SDK 在 H5 环境下被错误初始化时,会输出引导提示,提醒切换到 `@sentry/browser`。
374
+
375
+ 推荐通过 **uni-app 条件编译**按端引入:
376
+
377
+ ```ts
378
+ // utils/sentry.ts
379
+ let Sentry: any;
380
+
381
+ // #ifdef H5
382
+ Sentry = require('@sentry/browser');
383
+ Sentry.init({
384
+ dsn: 'YOUR_DSN',
385
+ environment: 'production',
386
+ tracesSampleRate: 0.2,
387
+ });
388
+ // #endif
389
+
390
+ // #ifdef MP-WEIXIN || MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-QQ || MP-KUAISHOU || MP-DINGTALK
391
+ Sentry = require('sentry-miniapp');
392
+ Sentry.init({
393
+ dsn: 'YOUR_DSN',
394
+ environment: 'production',
395
+ tracesSampleRate: 0.2,
396
+ });
397
+ // #endif
398
+
399
+ export default Sentry;
400
+ ```
401
+
402
+ 两端上报同一个 Sentry DSN,可以在同一个 Project 里聚合查看错误。Taro 用户可以用类似的 `process.env.TARO_ENV === 'h5'` 判断分端引入。
403
+
331
404
  ---
332
405
 
333
406
  ## 📖 文档导航