1. 登錄sentry后臺管理系統(tǒng)妙真,沒有注冊一個
這是一個已經搭建好的后臺
http://172.31.1.22:8081/auth/login/sentry/
2.配置SDK价说,創(chuàng)建一個新項目,選擇語言或框架
創(chuàng)建成功后會出現(xiàn)這個頁面
其中的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允許您包裝任何立即執(zhí)行的函數(shù)。 在幕后裹匙,Raven只是將你的代碼包裝在try ... catch塊中瑞凑,以便在重新拋出之前記錄異常。
var doIt = function() {
// doing cool stuff
}
setTimeout(Raven.wrap(doIt), 1000)
Raven.wrap以與Raven.context類似的方式包裝函數(shù)概页,但它不是執(zhí)行函數(shù)籽御,而是返回另一個函數(shù)。 這在傳遞回調時特別有用惰匙。
Capturing Messages
Raven.captureMessage('Broken!')
captureMessage技掏,captureException,context和wrap函數(shù)都允許將附加數(shù)據傳遞到錯誤上项鬼。
詳情請查看:https://docs.sentry.io/clients/javascript/usage/
5.sourcemap
生成token
后臺管理系統(tǒng)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
創(chuàng)建一個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