sentry使用教程

1. 登錄sentry后臺(tái)管理系統(tǒng),沒有注冊(cè)一個(gè)

這是一個(gè)已經(jīng)搭建好的后臺(tái)
http://172.31.1.22:8081/auth/login/sentry/

image.png

2.配置SDK,創(chuàng)建一個(gè)新項(xiàng)目,選擇語言或框架

image.png

創(chuàng)建成功后會(huì)出現(xiàn)這個(gè)頁面
image.png

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

參考: https://docs.sentry.io/quickstart/#pick-a-client-integration

3.客戶端配置

很簡(jiǎn)單,在入口文件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ù),而是返回另一個(gè)函數(shù)。 這在傳遞回調(diào)時(shí)特別有用。

Capturing Messages

Raven.captureMessage('Broken!')

captureMessage,captureException,context和wrap函數(shù)都允許將附加數(shù)據(jù)傳遞到錯(cuò)誤上。
詳情請(qǐng)查看:https://docs.sentry.io/clients/javascript/usage/

5.sourcemap

生成token

后臺(tái)管理系統(tǒng)Account > API> Create New Token


image.png

生成的token.png

安裝sentry-cli,下面的命令適用于OS X 或 Linux

curl -sL https://sentry.io/get-cli/ | bash
檢查是否正確安裝
sentry-cli --help

建立一個(gè)配置文件.sentryclirc,輸入以下內(nèi)容,放到當(dāng)前目錄下

[defaults]
url=http://172.31.1.22:8081/
org=sentry
project=h5-log

organization和project可以在settings里面查看


settings.png

進(jìn)行身份驗(yàn)證

sentry-cli login
然后在Enter your token輸入上一步生成的token,它會(huì)自動(dòng)把token添加到.sentryclirc
就如下面
[auth]
token=c88b9c2c80e6415296415ecc745f65de7c8ea2a966d54d0db18dad91c43e75b1

創(chuàng)建一個(gè)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文件訪問的路徑

查看文件是否上傳成功


文件上傳.png

sourcemap解析成功.png

sourcemap解析不成功.png

刪除或升級(jí)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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容