前端異常監(jiān)控框架Sentry

介紹

sentry是一個(gè)開(kāi)源的監(jiān)控系統(tǒng),能支持服務(wù)端與客戶端的監(jiān)控,還有個(gè)強(qiáng)大的后臺(tái)錯(cuò)誤分析、報(bào)警平臺(tái)。

搭建sentry:

官網(wǎng)推薦使用docker

依賴環(huán)境:docker,docker-compose

  1. git clone https://github.com/getsentry/onpremise.git
  2. 進(jìn)入onpremise文件夾,執(zhí)行./install.sh, 這個(gè)過(guò)程會(huì)建立管理賬號(hào)

這是sentry需要docker最小內(nèi)存2400M, 需要在docker里面設(shè)置內(nèi)存,只要大于2400M就沒(méi)這個(gè)問(wèn)題了。

3.啟動(dòng)sentry :docker-compose up -d

通過(guò)localhost:9000 可以訪問(wèn)sentry了。

img

通過(guò)剛剛設(shè)置的賬號(hào)和密碼可以進(jìn)入到后臺(tái)。

到這里, 我們sentry的后臺(tái)就已經(jīng)部署好了。

平臺(tái)地址

http://report.eyunying.com.cn:11205/auth/login/sentry/

vue項(xiàng)目接入

  1. 接入
yarn add @sentry/vue @sentry/tracing

main.js

import * as Sentry from "@sentry/vue";
import { Integrations } from "@sentry/tracing";
Sentry.init({
  Vue,
  dsn: "http://ca54b1ca19d14347844d19046c0ea302@report.eyunying.com.cn:11205/9",
  integrations: [
    new Integrations.BrowserTracing({
      routingInstrumentation: Sentry.vueRouterInstrumentation(router),
      tracingOrigins: ["localhost", "my-site-url.com", /^\//]
    })
  ],
  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for performance monitoring.
  // We recommend adjusting this value in production
  tracesSampleRate: 1.0
});

.sentryclirc

[defaults]
### 你的域名
url='http://report.eyunying.com.cn:11205'
### 組織團(tuán)隊(duì)名默認(rèn)是 sentry
org=sentry
### 項(xiàng)目名稱
project=demo

### 步驟1創(chuàng)建的
[auth]
# 本地
token=3dfb4982a8b1403ea8ea8aa1d4e36618b723587bdfa2496098c629468c0fb71c

[http]
keepalive=false
 
[dsym]
max_upload_size=209715200
 
[log]
level=debug
 

token 生成

image-20211115093756018
image-20211115093833880
  1. 配置webpack
yarn add @sentry/webpack-plugin     

vue.config.js

const SentryWebpackPlugin = require("@sentry/webpack-plugin");

在 plugins

new SentryWebpackPlugin({
  release: process.env.RELEASE_VERSION, //版本號(hào)
  include: path.join(__dirname, `.${process.env.VUE_APP_BASE}js/`), //需要上傳到sentry服務(wù)器的資源目錄,會(huì)自動(dòng)匹配js 以及map文件
  ignore: ["node_modules", "vue.config.js"], //忽略文件目錄,當(dāng)然我們?cè)趇nclude中制定了文件路徑,這個(gè)忽略目錄可以不加
  configFile: ".sentryclirc",
  urlPrefix: `~${process.env.VUE_APP_BASE}js` //  線上對(duì)應(yīng)的url資源的相對(duì)路徑 比如我的域名是 http://XXX  .com/,靜態(tài)資源都在 static文件夾里面,
})
  1. 釘釘報(bào)警
image-20211115094927696

報(bào)警規(guī)則

image-20211115095108803
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容