1. 登录sentry后台管理系统,没有注册一个
这是一个已经搭建好的后台
http://172.31.1.22:8081/auth/login/sentry/

2.配置SDK,创建一个新项目,选择语言或框架

创建成功后会出现这个页面

其中的sentry DSN配置Raven.js要用到,也可以在 [Project Name] -> Project Settings -> Client Keys (DSN)->DSN (Public)找到DSN

参考: https://docs.sentry.io/quickstart/#pick-a-client-integration
3.客户端配置
很简单,在入口文件index.html头部引入raven.min.js,并且配置Raven。不需要使用raven 的vue插件。
<script src="https://cdn.ravenjs.com/3.26.4/raven.min.js" crossorigin="anonymous"></script>
<script>Raven.config('https://<key>@sentry.io/<project>').install();</script>
4.raven使用
try … catch
try {
doSomething(a[0])
} catch(e) {
Raven.captureException(e)
}
context/wrap
Raven.context(function() {
doSomething(a[0])
})
Raven.context允许您包装任何立即执行的函数。 在幕后,Raven只是将你的代码包装在try ... catch块中,以便在重新抛出之前记录异常。
var doIt = function() {
// doing cool stuff
}
setTimeout(Raven.wrap(doIt), 1000)
Raven.wrap以与Raven.context类似的方式包装函数,但它不是执行函数,而是返回另一个函数。 这在传递回调时特别有用。
Capturing Messages
Raven.captureMessage('Broken!')
captureMessage,captureException,context和wrap函数都允许将附加数据传递到错误上。
详情请查看:https://docs.sentry.io/clients/javascript/usage/
5.sourcemap
生成token
后台管理系统Account > API> Create New Token


安装sentry-cli,下面的命令适用于OS X 或 Linux
curl -sL https://sentry.io/get-cli/ | bash
检查是否正确安装
sentry-cli --help
建立一个配置文件.sentryclirc,输入以下内容,放到当前目录下
[defaults]
url=http://172.31.1.22:8081/
org=sentry
project=h5-log
organization和project可以在settings里面查看

进行身份验证
sentry-cli login
然后在Enter your token输入上一步生成的token,它会自动把token添加到.sentryclirc
就如下面
[auth]
token=c88b9c2c80e6415296415ecc745f65de7c8ea2a966d54d0db18dad91c43e75b1
创建一个release
sentry-cli releases new 1
上传sourcemaps文件
sentry-cli releases files VERSION upload-sourcemaps --url-prefix https://mydomain.invalid/static /path/to/sourcemaps
比如sentry-cli releases files 1 upload-sourcemaps --url-prefix http://172.31.11.245:9000/src/js sourcemap
--url-prefix为js文件访问的路径
查看文件是否上传成功



删除或升级sentry-cli
sentry-cli update
sentry-cli uninstall
删除文件
sentry-cli releases files VERSION delete NAME_OF_FILE
sentry-cli releases files VERSION delete --all
参考:https://docs.sentry.io/learn/cli/installation/#automatic-installation
https://docs.sentry.io/clients/javascript/sourcemaps/
https://docs.sentry.io/learn/cli/releases/#managing-release-artifacts
网友评论