错误监控工具-Sentry

1. 安装依赖

Vue安装:

npm i @sentry/browser
npm i @sentry/integrations

React安装:

npm i @sentry/react

2. 申请权限

Sentry中配置项目基本信息后,可以得到如下地址明确项目错误信息的上报地址:

https://<key>@report.url.cn/sentry/<project>

3、项目接入sentry

Vue接入:

// /src/index.js
import * as Sentry from '@sentry/browser';
import * as Integrations from '@sentry/integrations';
const RELEASE_VERSION = require('../package.json').version
Sentry.init({
   dsn: "", // 步骤2所得到的地址
   integrations: [
       new Integrations.Vue({
           Vue,
           attachProps: true,
      }),
       new Integrations.RewriteFrames(),
  ],
   release: RELEASE_VERSION, // 版本号
});

React接入:

4、上传sourcemap

4.1 安装依赖

4.2 配置.sentryclirc文件

根目录下创建.sentryclirc文件:

4.3 配置webpack - vue2.0 + react

4.4 配置webpack - vue3.0

4.5 其他

webpack-sentry-plugin 可以在上传后删除打包后的sourcemap,可以节省后面上传打包后文件的过滤sourcemap的操作。

根目录创建 sentry.config.js

webpack配置:

如果你对内容有任何疑问,欢迎提交 ❕issues✉️ email

最后更新于

这有帮助吗?