sentry-miniapp 1.11.0 → 1.11.2
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 +81 -0
- package/README.md +81 -0
- package/dist/sentry-miniapp.cjs.js +6 -6
- package/dist/sentry-miniapp.cjs.js.map +1 -1
- package/dist/sentry-miniapp.esm.js +381 -396
- package/dist/sentry-miniapp.esm.js.map +1 -1
- package/dist/sentry-miniapp.umd.js +6 -6
- package/dist/sentry-miniapp.umd.js.map +1 -1
- package/dist/types/crossPlatform.d.ts +10 -5
- package/dist/types/crossPlatform.d.ts.map +1 -1
- package/dist/types/integrations/minigame.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -2
package/README.en.md
CHANGED
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|

|
|
8
8
|
[](https://docs.sentry.io/platforms/#sdks-supported-by-our-community)
|
|
9
9
|
[](./LICENSE)
|
|
10
|
+
[](https://sentry-miniapp.pages.dev/)
|
|
10
11
|
|
|
11
12
|
[简体中文](./README.md) | English
|
|
12
13
|
|
|
14
|
+
> **📖 Documentation**: [https://sentry-miniapp.pages.dev/](https://sentry-miniapp.pages.dev/) — getting started, capability matrix, FAQ, Source Map setup, and examples, with nav and search. (Chinese for now)
|
|
15
|
+
|
|
13
16
|
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
17
|
|
|
15
18
|
> **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.
|
|
@@ -403,6 +406,84 @@ export default Sentry;
|
|
|
403
406
|
|
|
404
407
|
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.
|
|
405
408
|
|
|
409
|
+
### 4. Are network requests included with error events?
|
|
410
|
+
|
|
411
|
+
**Yes, and it's on by default.** The SDK enables `NetworkBreadcrumbs` out of the box, which patches `wx.request` / `my.httpRequest` and records each request as a `category: xhr` breadcrumb. Those breadcrumbs ride along with the **next captured error event** (same as `@sentry/browser`), so you'll see the request trail leading up to the error in the event's **Breadcrumbs** section.
|
|
412
|
+
|
|
413
|
+
- **Fields by default:** `url` / `method` / `status_code` / `duration`; failed requests are `error` level, slow ones (>3s) are `warning`.
|
|
414
|
+
- **Bodies are NOT included by default.** Enable `traceNetworkBody: true` to capture request/response bodies (with built-in sensitive-field scrubbing; use `denyBodyUrls` to exclude specific URLs):
|
|
415
|
+
|
|
416
|
+
```js
|
|
417
|
+
Sentry.init({ dsn: '...', traceNetworkBody: true });
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
- **No extra config for uni-app / Taro:** `uni.request` / `Taro.request` ultimately call the patched global `wx.request`, so they're captured too.
|
|
421
|
+
|
|
422
|
+
If an error has no network breadcrumb, it's usually one of:
|
|
423
|
+
|
|
424
|
+
1. **No request happened before the error fired** (e.g. calling `captureException` right on page load). To verify, make a request first and trigger the error in its callback:
|
|
425
|
+
|
|
426
|
+
```js
|
|
427
|
+
wx.request({
|
|
428
|
+
url: 'https://httpbin.org/get',
|
|
429
|
+
success() {
|
|
430
|
+
Sentry.captureException(new Error('net test'));
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
You should then see a `category: xhr` breadcrumb on the event.
|
|
436
|
+
|
|
437
|
+
2. **`Sentry.init` ran after the request.** The patch is installed during `init`, so requests fired before `init` aren't captured. Always call `Sentry.init` before `App()` / any business request.
|
|
438
|
+
|
|
439
|
+
### 5. Errors in uni-app (Vue) components aren't reported / reporting rate is very low?
|
|
440
|
+
|
|
441
|
+
With **uni-app** (Vue under the hood) you may hit "`sampleRate` is 1 but only an occasional error shows up". The reason: **Vue catches errors thrown inside components (render / lifecycle / watchers / methods invoked from `@click`) with its own error handler — by default it only logs to console and does NOT bubble them to `wx.onError`**, so the SDK never sees them. Only errors that escape Vue (e.g. `setTimeout` callbacks, unhandled promises, hard crashes) get through, which is why reporting looks sporadic.
|
|
442
|
+
|
|
443
|
+
Wire Vue's `errorHandler` to Sentry so component errors are reported:
|
|
444
|
+
|
|
445
|
+
**uni-app Vue3 (`main.js` / `main.ts`, the current default):**
|
|
446
|
+
|
|
447
|
+
```js
|
|
448
|
+
import Sentry from '@/utils/sentry'; // your sentry-miniapp init wrapper
|
|
449
|
+
import { createSSRApp } from 'vue';
|
|
450
|
+
import App from './App.vue';
|
|
451
|
+
|
|
452
|
+
export function createApp() {
|
|
453
|
+
const app = createSSRApp(App);
|
|
454
|
+
app.config.errorHandler = (err, instance, info) => {
|
|
455
|
+
Sentry.captureException(err, { extra: { lifecycleHook: info } });
|
|
456
|
+
console.error(err);
|
|
457
|
+
};
|
|
458
|
+
return { app };
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
**Vue2 (older uni-app):**
|
|
463
|
+
|
|
464
|
+
```js
|
|
465
|
+
Vue.config.errorHandler = (err, vm, info) => {
|
|
466
|
+
Sentry.captureException(err);
|
|
467
|
+
console.error(err);
|
|
468
|
+
};
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
> **Taro is not Vue.** Taro defaults to **React** (and also supports Vue). With **Vue**, wire `errorHandler` the same way; with **React**, React does not silently swallow component errors like Vue (an uncaught render error propagates upward), but you can add an **Error Boundary** to forward render errors to Sentry with richer context:
|
|
472
|
+
>
|
|
473
|
+
> ```jsx
|
|
474
|
+
> class SentryBoundary extends React.Component {
|
|
475
|
+
> componentDidCatch(error, info) {
|
|
476
|
+
> Sentry.captureException(error, { extra: info });
|
|
477
|
+
> }
|
|
478
|
+
> render() {
|
|
479
|
+
> return this.props.children;
|
|
480
|
+
> }
|
|
481
|
+
> }
|
|
482
|
+
> // Wrap your root: <SentryBoundary><App /></SentryBoundary>
|
|
483
|
+
> ```
|
|
484
|
+
|
|
485
|
+
This also improves delivery: once `errorHandler` / the boundary catches the error the app keeps running, so the in-flight report request completes (a hard crash would otherwise kill it).
|
|
486
|
+
|
|
406
487
|
---
|
|
407
488
|
|
|
408
489
|
## Documentation
|
package/README.md
CHANGED
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|

|
|
8
8
|
[](https://docs.sentry.io/platforms/#sdks-supported-by-our-community)
|
|
9
9
|
[](./LICENSE)
|
|
10
|
+
[](https://sentry-miniapp.pages.dev/)
|
|
10
11
|
|
|
11
12
|
简体中文 | [English](./README.en.md)
|
|
12
13
|
|
|
14
|
+
> **📖 文档站**:[https://sentry-miniapp.pages.dev/](https://sentry-miniapp.pages.dev/) —— 快速接入、能力矩阵、FAQ、Source Map 配置、示例索引,带导航与搜索。
|
|
15
|
+
|
|
13
16
|
一个基于 `@sentry/core` 核心构建的**小程序监控 SDK**,提供**异常监控**、**性能监控**、离线缓存、分布式追踪等能力。支持微信、支付宝、字节跳动、百度、QQ、钉钉、快手等多端小程序,以及微信 / 抖音等**小游戏**,并兼容 Taro / uni-app 等跨端框架。
|
|
14
17
|
|
|
15
18
|
> **📰 最新文章**:[《我给 Sentry 提了个 PR,后来 sentry-miniapp 进了官方文档》](https://juejin.cn/post/7636106283963760681) — sentry-miniapp 已被收录进 Sentry 官方文档的 community-supported SDK 列表,这篇文章记录这件事的来龙去脉。觉得有用请帮忙点个 ⭐ Star,让更多小程序团队找到它。
|
|
@@ -418,6 +421,84 @@ export default Sentry;
|
|
|
418
421
|
|
|
419
422
|
两端上报同一个 Sentry DSN,可以在同一个 Project 里聚合查看错误。Taro 用户可以用类似的 `process.env.TARO_ENV === 'h5'` 判断分端引入。
|
|
420
423
|
|
|
424
|
+
### 4. 网络请求会随错误事件一起上报吗?
|
|
425
|
+
|
|
426
|
+
**会,且默认开启。** SDK 默认启用 `NetworkBreadcrumbs`,自动劫持 `wx.request` / `my.httpRequest`,把每个网络请求记成 `category: xhr` 的面包屑,随**下一个被捕获的错误事件**一起上报(与 `@sentry/browser` 默认行为一致)。在 Sentry 错误详情的 **Breadcrumbs** 区即可看到出错前的请求链路。
|
|
427
|
+
|
|
428
|
+
- **默认带的字段**:`url` / `method` / `status_code` / `duration`;失败请求标 `error` 级、慢请求(>3s)标 `warning` 级。
|
|
429
|
+
- **默认不带请求 / 响应体**。需要 body 时开启 `traceNetworkBody: true`(内置常见敏感字段脱敏,可用 `denyBodyUrls` 排除指定 URL):
|
|
430
|
+
|
|
431
|
+
```js
|
|
432
|
+
Sentry.init({ dsn: '...', traceNetworkBody: true });
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
- **uni-app / Taro 无需额外配置**:`uni.request` / `Taro.request` 最终都会走到被包裹的全局 `wx.request`,照常记录。
|
|
436
|
+
|
|
437
|
+
如果错误里没有网络面包屑,多半是这两点之一:
|
|
438
|
+
|
|
439
|
+
1. **错误触发前没发过请求**(比如一进页面就手动 `captureException`,自然没有请求面包屑)。验证方式:先发一个请求,在回调里再触发错误——
|
|
440
|
+
|
|
441
|
+
```js
|
|
442
|
+
wx.request({
|
|
443
|
+
url: 'https://httpbin.org/get',
|
|
444
|
+
success() {
|
|
445
|
+
Sentry.captureException(new Error('net test'));
|
|
446
|
+
},
|
|
447
|
+
});
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
到事件 Breadcrumbs 里应能看到 `category: xhr` 那条。
|
|
451
|
+
|
|
452
|
+
2. **`Sentry.init` 晚于请求执行**:面包屑包裹在 `init` 时装上,`init` 之前发出的请求抓不到。务必让 `Sentry.init` 在 `App()` / 任何业务请求**之前**执行。
|
|
453
|
+
|
|
454
|
+
### 5. uni-app(Vue)组件内的错误没上报 / 上报率很低?
|
|
455
|
+
|
|
456
|
+
如果你用 **uni-app**(底层是 Vue),可能遇到「`sampleRate` 设成 1,却只偶尔上报一条」的情况。原因:**Vue 会用自己的错误处理接住组件内(render / 生命周期 / watch / 模板 `@click` 调用的方法)抛出的错误,默认只打印 console,不会再冒泡到 `wx.onError`**,于是 SDK 捕获不到。能上来的只剩「逃逸出 Vue」的那部分(`setTimeout` 回调、未处理 promise、硬崩溃),所以看起来只偶尔上报。
|
|
457
|
+
|
|
458
|
+
把 Vue 的 `errorHandler` 接到 Sentry,组件内错误就会上报:
|
|
459
|
+
|
|
460
|
+
**uni-app Vue3(`main.js` / `main.ts`,现在默认):**
|
|
461
|
+
|
|
462
|
+
```js
|
|
463
|
+
import Sentry from '@/utils/sentry'; // 你封装的 sentry-miniapp 初始化
|
|
464
|
+
import { createSSRApp } from 'vue';
|
|
465
|
+
import App from './App.vue';
|
|
466
|
+
|
|
467
|
+
export function createApp() {
|
|
468
|
+
const app = createSSRApp(App);
|
|
469
|
+
app.config.errorHandler = (err, instance, info) => {
|
|
470
|
+
Sentry.captureException(err, { extra: { lifecycleHook: info } });
|
|
471
|
+
console.error(err);
|
|
472
|
+
};
|
|
473
|
+
return { app };
|
|
474
|
+
}
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
**Vue2(uni-app 旧版):**
|
|
478
|
+
|
|
479
|
+
```js
|
|
480
|
+
Vue.config.errorHandler = (err, vm, info) => {
|
|
481
|
+
Sentry.captureException(err);
|
|
482
|
+
console.error(err);
|
|
483
|
+
};
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
> **Taro 不是 Vue。** Taro 默认用 **React**(也支持 Vue)。用 **Vue** 时同理接 `errorHandler`;用 **React** 时,React 不会像 Vue 那样静默吞掉组件错误(未捕获的渲染错误会向上抛),但你可以加一个**错误边界(Error Boundary)**把渲染错误更完整地转给 Sentry:
|
|
487
|
+
>
|
|
488
|
+
> ```jsx
|
|
489
|
+
> class SentryBoundary extends React.Component {
|
|
490
|
+
> componentDidCatch(error, info) {
|
|
491
|
+
> Sentry.captureException(error, { extra: info });
|
|
492
|
+
> }
|
|
493
|
+
> render() {
|
|
494
|
+
> return this.props.children;
|
|
495
|
+
> }
|
|
496
|
+
> }
|
|
497
|
+
> // 用它包住根组件:<SentryBoundary><App /></SentryBoundary>
|
|
498
|
+
> ```
|
|
499
|
+
|
|
500
|
+
接上之后还顺带提升送达率——`errorHandler` / 错误边界接住后应用不崩,上报请求能正常发完(硬崩溃会把还在飞的上报请求一起带走)。
|
|
501
|
+
|
|
421
502
|
---
|
|
422
503
|
|
|
423
504
|
## 📖 文档导航
|