{"id":26452951,"url":"https://github.com/lizhiyao/sentry-miniapp","last_synced_at":"2025-05-14T19:08:58.959Z","repository":{"id":35059777,"uuid":"201064663","full_name":"lizhiyao/sentry-miniapp","owner":"lizhiyao","description":"Sentry 小程序/小游戏 SDK：用于小程序/小游戏平台的 Sentry SDK（目前支持微信、字节跳动、支付宝、钉钉、QQ、百度小程序，微信、QQ 小游戏）","archived":false,"fork":false,"pushed_at":"2025-02-22T08:52:16.000Z","size":7912,"stargazers_count":615,"open_issues_count":16,"forks_count":137,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-09T06:11:50.346Z","etag":null,"topics":["crash-report","error-handling","raven","raven-js","sentry","sentry-client","sentry-javascript","sentry-miniapp","sentry-myapp","sentry-sdk","sentry-service","sentry-ttapp","sentry-weapp","typescript","weapp"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/sentry-miniapp","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lizhiyao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-07T14:16:04.000Z","updated_at":"2025-05-08T03:57:29.000Z","dependencies_parsed_at":"2025-03-18T18:44:16.368Z","dependency_job_id":"806935e9-e711-4846-acf6-29c99cea790c","html_url":"https://github.com/lizhiyao/sentry-miniapp","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lizhiyao%2Fsentry-miniapp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lizhiyao%2Fsentry-miniapp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lizhiyao%2Fsentry-miniapp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lizhiyao%2Fsentry-miniapp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lizhiyao","download_url":"https://codeload.github.com/lizhiyao/sentry-miniapp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254209859,"owners_count":22032897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crash-report","error-handling","raven","raven-js","sentry","sentry-client","sentry-javascript","sentry-miniapp","sentry-myapp","sentry-sdk","sentry-service","sentry-ttapp","sentry-weapp","typescript","weapp"],"created_at":"2025-03-18T18:40:18.763Z","updated_at":"2025-05-14T19:08:56.947Z","avatar_url":"https://github.com/lizhiyao.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sentry 小程序 SDK\n\n![npm version](https://img.shields.io/npm/v/sentry-miniapp)\n![npm download](https://img.shields.io/npm/dm/sentry-miniapp)\n![github forks](https://img.shields.io/github/forks/lizhiyao/sentry-miniapp?style=social)\n![github stars](https://img.shields.io/github/stars/lizhiyao/sentry-miniapp?style=social)\n![github watchers](https://img.shields.io/github/watchers/lizhiyao/sentry-miniapp?style=social)\n![github license](https://img.shields.io/github/license/lizhiyao/sentry-miniapp)\n\n用于小程序平台的 Sentry SDK\n\n## 功能特点\n\n- [x] 基于 [sentry-javascript 最新的基础模块](https://www.yuque.com/lizhiyao/dxy/zevhf1#0GMCN) 封装\n- [x] 遵守[官方统一的 API 设计文档](https://www.yuque.com/lizhiyao/dxy/gc3b9r#vQdTs)，使用方式和官方保持一致\n- [x] 使用 [TypeScript](https://www.typescriptlang.org/) 进行编写\n- [x] 包含 Sentry SDK（如：[@sentry/browser](https://github.com/getsentry/sentry-javascript/tree/master/packages/browser)）的所有基础功能\n- [x] 支持 `ES6`、`CommonJS` 两种模块系统（支持小程序原生开发方式、使用小程序框架开发方式两种开发模式下使用）\n- [x] 默认监听并上报小程序的 onError、onUnhandledRejection、onPageNotFound、onMemoryWarning 事件返回的信息（各事件支持程度与对应各小程序官方保持一致）\n- [x] 默认上报运行小程序的设备、操作系统、应用版本信息\n- [x] 支持微信小程序\n- [x] 支持微信小游戏\n- [x] 支持字节跳动小程序\n- [x] 支持支付宝小程序\n- [x] 支持钉钉小程序\n- [x] 支持百度小程序\n- [x] 支持在 [Taro](https://taro.aotu.io/) 等第三方小程序框架中使用\n- [x] 默认上报异常发生时的路由栈\n- [ ] 完善的代码测试\n\n## 用法\n\n支持两种使用方式：\n\n- 直接引用\n- 通过 npm 方式使用（推荐）\n\n### 注意\n\n1. 无论选择哪种使用方式，都需要开启「微信开发者工具 - 设置 - 项目设置 - 增强编译」功能\n2. 使用前需要确保有可用的 `Sentry Service`，比如：使用 [官方 Sentry Service](https://sentry.io/welcome/) 服务 或[自己搭建 Sentry Service](https://docs.sentry.io/server/)。如果想直接将异常信息上报到 \u003chttps://sentry.io/\u003e，由于其没有备案，可以先将异常信息上报给自己已备案域名下的服务端接口，由服务端进行请求转发。\n3. 在小程序管理后台配置 `Sentry Service` 对应的 `request` 合法域名\n\n### 直接引用\n\n1. 微信小程序和微信小游戏下载 [sentry-miniapp.wx.min.js](https://github.com/lizhiyao/sentry-miniapp/blob/master/examples/weapp/vendor/sentry-miniapp.wx.min.js)；字节跳动小程序下载 [sentry-miniapp.tt.min.js](https://github.com/lizhiyao/sentry-miniapp/blob/master/examples/ttapp/vendor/sentry-miniapp.tt.min.js)；支付宝小程序下载 [sentry-miniapp.my.min.js](https://github.com/lizhiyao/sentry-miniapp/blob/master/examples/myapp/vendor/sentry-miniapp.my.min.js)，钉钉小程序下载 [sentry-miniapp.dd.min.js](https://github.com/lizhiyao/sentry-miniapp/blob/master/examples/ddapp/vendor/sentry-miniapp.dd.min.js)\n2. 参照 `/examples` 中各项目使用方式，将 `sentry-miniapp.xx.min.js` 放入项目的合适目录中，比如放入 `vendor` 文件夹\n3. 参照 `/examples/app.js` 代码，进行 `Sentry` 的初始化\n4. 对于提供了微信、字节跳动小程序 `sentry-miniapp` 会自动上报 `xx.onError()` 捕获的异常，对于支付宝小程序需要应用开发者在 `App.onError()` 中主动进行异常上报。详情可见 `/docs/cross-platform.md`。\n\n### npm 方式\n\n注意：目前字节跳动小程序不支持 npm 方式。\n\n1. 安装依赖\n\n   ```bash\n   npm install sentry-miniapp --save\n   # 或者\n   yarn add sentry-miniapp\n   ```\n\n2. 使用「微信开发者工具 - 工具 - 构建 npm」进行构建，详情可参考[npm 支持](https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html)\n\n3. 在 `app.js` 中引用并初始化 `Sentry`，根据实际需求设置上报到 Sentry 的元信息\n\n   ```js\n   import * as Sentry from \"sentry-miniapp\";\n\n   // init Sentry\n   // init options: https://github.com/getsentry/sentry-javascript/blob/master/packages/types/src/options.ts\n   Sentry.init({\n     dsn: \"__DSN__\",\n     // ...\n   });\n\n   // Set user information, as well as tags and further extras\n   Sentry.configureScope((scope) =\u003e {\n     scope.setExtra(\"battery\", 0.7);\n     scope.setTag(\"user_mode\", \"admin\");\n     scope.setUser({ id: \"4711\" });\n     // scope.clear();\n   });\n\n   // Add a breadcrumb for future events\n   Sentry.addBreadcrumb({\n     message: \"My Breadcrumb\",\n     // ...\n   });\n\n   // Capture exceptions, messages or manual events\n   Sentry.captureException(new Error(\"Good bye\"));\n   Sentry.captureMessage(\"Hello, world!\");\n   Sentry.captureEvent({\n     message: \"Manual\",\n     stacktrace: [\n       // ...\n     ],\n   });\n   ```\n\n## 开发\n\n### 知识储备\n\n开发前请仔细阅读下面内容：\n\n- [sentry-javascript README 中文版](https://www.yuque.com/lizhiyao/dxydance/sentry-javascript-readme-cn)\n- [Sentry 开发指南](https://www.yuque.com/lizhiyao/dxydance/sentry-develop-guide)\n- [sentry-javascript 源码阅读](https://www.yuque.com/lizhiyao/dxydance/sentry-javascript-src)\n\n#### sentry-core 设计图\n\n![Dashboard](docs/sentry-core.png)\n\n#### sentry-hub 设计图\n\n![Dashboard](docs/sentry-hub.png)\n\n#### sentry-miniapp 设计图\n\n![Dashboard](docs/sentry-miniapp.png)\n\n### 相关命令\n\n```bash\n# 根据 package.json 中的版本号更新 SDK 源码中的版本号\nnpm run version\n\n# 构建供小程序直接引用的 sentry-miniapp.xx.min.js；在本地可直接使用开发者工具打开 examples 下具体项目进行调试\nnpm run build:dist\n\n# 构建供微信小程序直接引用的 sentry-miniapp.wx.min.js\nnpm run build:wx\n\n# 构建供支付宝小程序直接引用的 sentry-miniapp.my.min.js\nnpm run build:my\n\n# 构建供钉钉小程序直接引用的 sentry-miniapp.dd.min.js\nnpm run build:dd\n\n# 构建供字节跳动小程序直接引用的 sentry-miniapp.tt.min.js\nnpm run build:tt\n\n# 构建供百度小程序直接引用的 sentry-miniapp.swan.min.js\nnpm run build:swan\n\n# 构建用于发布到 npm 的 dist 资源\nnpm run build\n\n# 构建用于发布到 npm 的 esm 资源\nnpm run build:esm\n\n# 发布到 npm\nnpm publish --registry=https://registry.npmjs.org/\n```\n\n## 效果图\n\n![Dashboard](docs/screenshot/sentry-admin.png)\n![Error00](docs/screenshot/sentry-error-00.png)\n![Error01](docs/screenshot/sentry-error-01.png)\n![Error02](docs/screenshot/sentry-error-02.png)\n\n## 谁在使用 sentry-miniapp\n\n### 微信小程序\n\n- 丁香医生\n- 丁香医生医生端\n- 丁香人才\n- 丁香家\n\n### 支付宝小程序\n\n- 丁香医生\n\n### 字节跳动小程序\n\n- 丁香医生\n\n## 参考资料\n\n- [sentry-javascript](https://github.com/getsentry/sentry-javascript)\n- [Sentry Getting Started](https://docs.sentry.io/error-reporting/quickstart/?platform=browsernpm)\n- [Sentry JavaScript SDKs](http://getsentry.github.io/sentry-javascript/)\n- [Sentry TypeScript Configuration](https://github.com/getsentry/sentry-javascript/tree/master/packages/typescript)\n- [wx.request](https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html)\n- [小程序 App](https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.html)\n- [wx.onError、App.onError 疑惑及如何捕获 Promise 异常？](https://developers.weixin.qq.com/community/develop/doc/000c8cf5794770272709f38a756000)\n- [shields.io](https://shields.io/)\n- [字节跳动小程序文档](https://developer.toutiao.com/docs/framework/)\n- [支付宝小程序文档](https://docs.alipay.com/mini/developer)\n- [tt.onError 的疑问](http://forum.microapp.bytedance.com/topic/2806/tt-onerror-%E7%96%91%E9%97%AE)\n\n## 其他小程序异常监控产品\n\n- [Fundebug](https://www.fundebug.com/)\n- [FrontJS](https://www.frontjs.com/home/tour)\n- [Bugout](https://bugout.testin.cn/)\n\n## 贡献\n\n欢迎通过 `issue`、`pull request`等方式贡献 `sentry-miniapp`。\n\n## 联系作者\n\nPS. 由于微信群二维码有时效性限制，想入群的同学还可以加作者微信（添加时请备注 sentry-miniapp），由作者邀请入群\n\n### sentry-miniapp 微信交流群\n\n\u003cimg src=\"docs/qrcode/sentry-miniapp.jpeg\" alt=\"微信交流群二维码\" width=\"300\" height=\"400\" /\u003e\n\n### 作者微信二维码\n\n\u003cimg src=\"docs/qrcode/zhiyao.jpeg\" alt=\"作者微信二维码\" width=\"300\" height=\"300\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flizhiyao%2Fsentry-miniapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flizhiyao%2Fsentry-miniapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flizhiyao%2Fsentry-miniapp/lists"}