异常监控之 sentry 实践
最后更新于
npm i -g @sentry/cli
sentry-cli -V // 检查版本sentry-cli loginvi /Users/sjh/.sentryclircsentry-cli infosentry-cli projects listsentry-cli releases files staging@1.0.1 delete --allsentry-cli releases -o 组织 -p 项目 new staging@1.0.1
# 这里的 staging@1.0.1 就是我们指定的版本号.
# -o -p可以通过页面左上角可以看到。现在我们可以通过创建多个版本号来进行异常分类。 同时,也可以通过页面中"Releases"查看是否创建成功
# 安装raven - js
npm install raven - js--save
# 回到前端项目中, 在config添加对应的release, 指定版本后, 每次上报的异常就会分类到该版本下。
import Raven from 'raven-js';
Raven.config(DSN, {
release: 'staging@1.0.1'
}).install()sentry-cli releases -o 组织 -p 项目 delete staging@1.0.1
# 注意 删除某个release时需要将其下的异常处理掉,并将该版本的sourcemap文件清空
# 完成上面两步可能还要等待2小时才能删除,不然会报错:该版本还有其它依赖。
import * as Sentry from '@sentry/browser';
d;
Sentry.init({
dsn: 'https://3ab8eff44adc41bdb4b7b3abeb9af39e@o209216.ingest.sentry.io/5304337',
integrations: [new VueIntegration({
Vue,
attachProps: true
})],
});
Vue.prototype.Sentry = Sentry // 在捕获错误的界面需要用到Sentry configureWebpack: {
plugins: [
new SentryCliPlugin({
include: "../game-developer-web/src/main/webapp/resources/dist", // 作用的文件夹(打包好的文件夹)
release: process.env.RELEASE_VERSION, // 版本号
configFile: "sentry.properties",
ignore: ['node_modules'],
urlPrefix: "../game-developer-web/src/main/webapp/resources/dist" // 线上项目的文件夹名
})
]
}import * as serviceWorker from './serviceWorker';
import * as Sentry from '@sentry/browser';
Sentry.init({
release: 'test004',
dsn: "https://b0e87f818a464f319892f9c0eeb5e39e@o209216.ingest.sentry.io/5303156",
release: 'test004',
beforeSend(event, hint) {
// Check if it is an exception, and if so, show the report dialog
if (event.exception) {
Sentry.showReportDialog({
eventId: event.event_id
});
}
return event;
}
});