sentry浣跨敤瀹炶返

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sentry浣跨敤瀹炶返相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/ruby' title='ruby'>ruby   OLE   fgets   瀹樻柟   get   erro   nts   ons   tag   

1.鍓嶈█

鐩墠鎴戜富瑕佽礋璐g殑鏄叕鍙哥殑钀ラ攢娲诲姩绫婚」鐩紝鍩烘湰閮芥槸鐩存帴闈㈠悜鐢ㄦ埛绔殑锛屽苟涓擩S涔熸病鏈夊鍚庣涓€鏍锋湁瀹屽杽鐨勬棩蹇楃郴缁燂紝鍥犳绾夸笂鐨勫悇绉峛ug閮介潪甯搁毦浠ヨ繀閫熷畾浣嶃€傚湪鍔犲叆閿欒鏃ュ織鏀堕泦鍓嶏紝姣忔鎶ュ憡bug閮借鍔崇儲鐢ㄦ埛鍗忓姪寮€鍙戜汉鍛樿繘琛宐ug瀹氫綅锛岃繖涓€鏂归潰瀵圭敤鎴锋瀬涓嶅弸濂斤紝鍚屾椂涔熷姞澶т簡Bug瀹氫綅鐨勯毦搴︼紱鍥犳鎴戜滑闇€瑕佷竴涓伐鍏锋潵甯垜浠敹闆嗛敊璇俊鎭紝濡傛帴鍙f姤閿欙紝dom鎶ラ敊浠ュ強璇硶閿欒绛夌瓑銆備笅闈㈡垜灏变粙缁嶄竴涓媠entry杩欎釜宸ュ叿濡備綍鍦ㄩ」鐩腑浣跨敤銆?/p>

2.sentry浠嬬粛

Sentry 鏄竴涓疄鏃朵簨浠舵棩蹇楄褰曞拰姹囬泦鐨勫钩鍙般€傚叾涓撴敞浜庨敊璇洃鎺т互鍙婃彁鍙栦竴鍒囦簨鍚庡鐞嗘墍闇€淇℃伅鑰屼笉渚濊禆浜庨夯鐑︾殑鐢ㄦ埛鍙嶉銆傚畠鍒嗕负瀹㈡埛绔拰鏈嶅姟绔紝瀹㈡埛绔?鐩墠瀹㈡埛绔湁Python, PHP,C#, Ruby绛夊绉嶈瑷€)灏卞祵鍏ュ湪浣犵殑搴旂敤绋嬪簭涓棿锛岀▼搴忓嚭鐜板紓甯稿氨鍚戞湇鍔$鍙戦€佹秷鎭紝鏈嶅姟绔皢娑堟伅璁板綍鍒版暟鎹簱涓苟鎻愪緵涓€涓獁eb椤垫柟渚挎煡鐪嬨€係entry鐢眕ython缂栧啓锛屾簮鐮佸紑鏀撅紝鎬ц兘鍗撹秺锛屾槗浜庢墿灞曪紝鐩墠钁楀悕鐨勭敤鎴锋湁Disqus, Path, mozilla, Pinterest绛夈€?/p>

3.濡備綍鍦ㄩ」鐩腑浣跨敤sentry

3.1 瀹夎

涓轰簡鍦╲ue椤圭洰涓娇鐢╯entry,浣犻渶瑕佸悓鏃朵娇鐢≧aven.js(Senrty鐨勬祻瑙堝櫒JsSDK)鍜孯aven.js Vue鎻掍欢銆俁aven.js灏嗚嚜鍔ㄦ姤鍛婃墍鏈夋湭琚崟鑾风殑寮傚父锛岃繘涓€姝ヤ簡瑙aven.js鐨勭敤璇峰弬鑰?a href="https://link.jianshu.com?t=https%3A%2F%2Fdocs.sentry.io%2Fclients%2Fjavascript%2Fusage%2F" rel="nofollow" target="_blank">Raven.js銆俁aven.js Vue鎻掍欢灏嗕細鑷姩鎹曟崏鎶涘嚭閿欒鐨勬椿鍔ㄧ粍浠剁姸鎬佷互鍙婂悕绉般€?br> 浣跨敤npm瀹夎:

npm install raven-js --save

 

鐒跺悗鍦╩ain.js閲屽悓鏃跺紩鍏aven.js鍜孯aven.js Vue plugin

import Vue from 鈥榲ue鈥?span style="color: rgba(0, 0, 0, 1)">;
import Raven from 鈥榬aven-js鈥?span style="color: rgba(0, 0, 0, 1)">;
import RavenVue from 鈥榬aven-js/plugins/vue鈥?span style="color: rgba(0, 0, 0, 1)">;

Raven
    .config(鈥榟ttps://08dc77f2b5dd42e490be150ad705ddd@sentry.io/123456鈥?span style="color: rgba(0, 0, 0, 1)">)
    .addPlugin(RavenVue, Vue)
    .install()

 

3.2 鍦╯entry涓婃柊寤鸿嚜宸辩殑椤圭洰

鍦?a href="https://link.jianshu.com?t=https%3A%2F%2Fsentry.io%2F" rel="nofollow" target="_blank">Sentry涓婃柊寤轰竴涓处鍙凤紝鍐嶆柊寤轰竴涓粍缁囷紝涓€涓粍缁囧彲浠ラ個璇峰浜哄弬涓庡埌鍏朵腑鏉ャ€傜劧鍚庡垱寤轰竴涓柊鐨勯」鐩紝閫変腑JavaScript椤圭洰銆傚乏涓嬭濉啓椤圭洰鍚嶇劧鍚庡垱寤洪」鐩€?br>

 
鎶€鏈浘鐗? src=
 

鍒涘缓瀹屾垚涔嬪悗锛屾垜浠緱鍒颁簡涓€涓猄entry DSN(鍦ㄥ垵濮嬪寲鐨勬椂鍊欎細鐢ㄥ埌),鐒跺悗灏嗗緱鍒扮殑Sentry DSN鏇挎崲鍒颁笂闈onfig閲岀殑鍐呭銆傝嚦姝わ紝sentry灏卞畬鎴愪簡涓庨」鐩殑鏁村悎锛屼箣鍚庡氨鍙互鎹曡幏寮傚父骞跺彂閫佸埌sentry锛屾垜浠彲浠ュ湪sentry鐩戞帶web椤?https://sentry.io/缁勭粐鍚?椤圭洰鍚?)鐪嬪埌鍏蜂綋鐨勫紓甯镐俊鎭€?br>
 
鎶€鏈浘鐗? src=

 

3.3 鍏充簬DSN

鍦⊿entry瀹屾垚涓€涓」鐩殑璁剧疆鍚庯紝鎮ㄥ皢鑾峰緱涓€涓垜浠О涔嬩负DSN鎴栨暟鎹簮鍚嶇О鐨勫€?瀹冪湅璧锋潵寰堝儚涓€涓爣鍑嗙殑URL锛屼絾瀹冨疄闄呬笂鍙槸Sentry SDK鎵€闇€鐨勯厤缃殑鏍囪瘑.瀹冪敱鍑犱釜閮ㄥ垎缁勬垚锛屽寘鎷崗璁紝鍏叡瀵嗛挜鍜屽瘑閽ワ紝鏈嶅姟鍣ㄥ湴鍧€鍜岄」鐩爣璇嗙銆?/p>

鈥榹PROTOCOL}://{PUBLIC_KEY}:{SECRET_KEY}@{HOST}/{PATH}{PROJECT_ID}鈥?/pre>

 

瀹冪敱5閮ㄥ垎缁勬垚锛?br> 1. 浣跨敤鐨勫崗璁? http鎴杊ttps;
2. 楠岃瘉sdk鐨勫叕閽ュ拰瀵嗛挜;
3. 鐩爣sentry鏈嶅姟鍣?
4. 楠岃瘉鐢ㄦ埛缁戝畾鐨勯」鐩甶d.

鐢熸垚濂紻SN鍚庯紝灏嗗叾濉炲叆鍒板垵濮嬪寲鐨勯厤缃腑锛?/p>

import Raven from 鈥榬aven-js鈥?span style="color: rgba(0, 0, 0, 1)">
Raven.config(鈥榟ttps://08dc77f2b5dd42e490be150ad70527dd:38dded13008c4afca16c650854b73ce0@sentry.io/272180鈥?

 

3.4 濡備綍浣跨敤

1.鏈€绠€鍗曠殑鏂瑰紡鏄富鍔ㄨЕ鍙戯細

try {
    doSomething(a[0])
} catch(e) {
    Raven.captureException(e)
}

 

2.window.onerror鎹曟崏寮傚父

window.onerror = function (e) {
    Raven.captureException(e)
}

 

3.鍦╲ue閲屽彲浠ヤ娇鐢╒ue.config.errorHandler 閽╁瓙鏉ユ崟鎹?/p>

Vue.config.errorHandler = (err, vm, info) => {
  Raven.captureException(err)
}

 

4.瀵逛簬鎺ュ彛鎶ラ敊锛屽彲浠ュ湪鍏ㄥ眬鎷︽埅閲屽疄鐜?/p>

request.interceptors.response.use(null, error => {
      axiosHelper.error(error)
      Raven.captureException(error)
      return Promise.reject(error)
    })

 

4.浣跨敤杩囩▼涓彲鑳介亣鍒扮殑闂

1.閲囬泦鍒扮殑淇℃伅涓嶅叏锛屾病鏈夋垜浠兂瑕佺殑鐢ㄦ埛淇℃伅锛屽鐢ㄦ埛guid鍜宲hone
瑙e喅鏂规锛氭枃妗i噷鏈夋彁渚涙柟娉晄etUserContext(),椤惧悕鎬濅箟璇ユ柟娉曟槸璁剧疆鍏ㄥ眬涓婁笅鏂囷紝鍥犳鎴戜滑鍙互鍦ㄦ嬁鍒扮敤鎴蜂俊鎭悗鎵ц涓€娆¤鏂规硶銆?/p>

request.interceptors.response.use(null, error => {
      axiosHelper.error(error)
      Raven.setUserContext({
        phone: token.Phone || 鈥樷€?span style="color: rgba(0, 0, 0, 1)">,
        guid: token.CustomerGuid || 鈥樷€?span style="color: rgba(0, 0, 0, 1)">
      })
      Raven.captureException(error)
      return Promise.reject(error)
    })

 

2.褰撳紓甯镐俊鎭繃澶氭椂锛屽湪鐩戞帶鍚庡彴娌℃湁鏈夋晥鐨勭瓫閫夋潯浠讹紝瀵艰嚧鎴戣鐪嬫寚瀹氱殑寮傚父淇℃伅浠€涔堝洶闅?br> 瑙e喅鏂规锛氭煡璇㈡枃妗e彂鐜版湁鏂板鏍囩鐨勬柟娉曪紝鏍囩鍙互甯姪鎴戜滑鏉ョ瓫閫夊紓甯镐俊鎭€?/p>

Raven.setTagsContext({
   phone: token.Phone || 鈥樻湭鐧诲綍鈥?span style="color: rgba(0, 0, 0, 1)">
})

 

3.鐢变簬绾夸笂鐨勪唬鐮侀兘鏄帇缂╄繃鐨勶紝鎵€浠ユ姤閿欐椂寰堥毦瀹氫綅鍒板叿浣撶殑鍝竴琛屼唬鐮佸嚭閿欍€?br> 瑙e喅鏂规锛?涓婁紶sourcemap,sentry浼氳嚜鍔ㄥ尮閰嶆簮鐮?涓婁紶sourcemap鏂囨。)銆?br> 瀹樻柟鎻愪緵浜嗗嚑绉嶄笂浼爏ourcemap鐨勬柟娉曪紝鍏蜂綋璇锋煡鐪嬫枃妗c€?br> 鎴戦€夋嫨鐨勬槸鎵嬪姩涓婁紶鐨勬柟寮忥紝閫氳繃瀹樻柟鎻愪緵鐨勫伐鍏穝entry-cli,棣栧厛鐢熸垚涓€涓増鏈彿骞跺湪sentry鍒濆鍖栫殑鏃跺€欓厤缃増鏈彿锛?/p>

Raven.config(鈥榟ttps://08dc77f2b5dd42e490be150ad70527dd@sentry.io/272180鈥?span style="color: rgba(0, 0, 0, 1)">, {
  autoBreadcrumbs: {
    xhr: true,
    console: true
  },
  release: 鈥榝irst鈥?span style="color: rgba(0, 0, 0, 1)">
})
  .addPlugin(RavenVue, Vue)
  .install()

 

鐒跺悗閫氳繃sentry-cli灏?.map.js鏂囦欢涓婁紶鑷硈entry鏈嶅姟鍣紝涔嬪悗灏卞彲浠ュ湪鐩戞帶骞冲彴鐪嬪埌鍏蜂綋鐨勯敊璇簡銆?/p>

5.鎼缓鑷繁鐨剆entry鏈嶅姟

鐢变簬瀹樻柟鎻愪緵鐨勫厤璐规湇鍔℃湁涓€瀹氭鏁扮殑闄愬埗锛岃揪鍒颁竴瀹氶檺鍒跺悗鎯宠鍐嶄娇鐢ㄥ氨闇€瑕佹敹璐逛簡锛屼絾鏄痵entry鏄紑婧愰」鐩墍浠ユ垜浠彲浠ュ湪鏈湴鎼缓鑷繁鐨勬湇鍔★紝瀹樻柟椤垫彁渚涗簡鍏蜂綋鐨勬搷浣滄楠ゃ€?br> Sentry鐨勬惌寤轰富瑕佹湁涓ょ

瀹樻柟鐨勬帹鑽愭槸浣跨敤Docker鏉ヨ繘琛岄儴缃?鍦ㄥ疄闄呯敓浜т腑,docker鏇翠负绠€娲佹槗鎺?涓嬮潰鎴戜滑灏辨潵璁茶docker閮ㄧ讲鏈湴Sentry鐨勬楠?br> 1.瀹夎docker
鏈汉浣跨敤鐨刴ac绯荤粺銆傜洿鎺ヤ粠Docker瀹樼綉涓嬭浇銆?瀹樻柟涓嬭浇鍦板潃

 
鎶€鏈浘鐗? src=

鍙互鐪嬪埌docker鍜宒ocker-compose 宸茬粡鍦ㄨ繍琛屼簡銆?br> 2.鎼缓鏈嶅姟
棣栧厛浠巊ithub涓婃媺鍘籹entry鐨刣ocker閰嶇疆鏂囦欢

 

git clone https://github.com/getsentry/onpremise.git

 

鎺ョ潃閫氳繃鍛戒护鐢熸垚瀵嗛挜

docker-compose run --rm web config generate-secret-key

 

 
鎶€鏈浘鐗? src=

绾㈢嚎鐢诲嚭鐨勫氨鏄敓鎴愬ソ鐨勫瘑閽ワ紝鐒跺悗灏嗗叾澶嶅埗鍒癲ocker-compose.yml鏂囦欢涓細


 
鎶€鏈浘鐗? src=

娉ㄦ剰灏嗗墠闈㈢殑娉ㄩ噴鈥?鈥樺彿鍘绘帀銆?br> 鐒跺悗鏇存柊閰嶇疆锛屽垱寤虹鐞嗗憳鐢ㄦ埛锛?/p>

docker-compose run --rm web upgrade

 

杩囩▼涓細璁╂垜浠~鍐欓偖绠卞拰瀵嗙爜
鐒跺悗鍐嶄慨鏀筪ocker-compose.yml 鏂囦欢锛屼负鍏朵腑鐨剋eb瀹瑰櫒娣诲姞volumes鍗?璁╅厤缃枃浠剁敓鏁堛€?/p>

 
鎶€鏈浘鐗? src=

鏈€鍚庯紝寮€鍚墍鐢ㄥ鍣細

docker-comose up -d

 

鑷虫澶у姛鍛婃垚锛佹鏃惰闂?a href="https://link.jianshu.com?t=http%3A%2F%2Flocalhost%3A9000" rel="nofollow" target="_blank">http://localhost:9000鍗冲彲鐧诲綍鏈湴鐩戞帶骞冲彴銆?br> 鍚庣画鎿嶄綔濡傚墠鏂囨彁鍒扮殑涓€鑷淬€?/p>

6.鎬荤粨

sentry鏄竴娆鹃潪甯稿己澶х殑宸ュ叿锛岄櫎浜嗕笂闈粙缁嶇殑鍩烘湰鍔熻兘澶栵紝鎹曡幏鍒伴敊璇俊鎭悗杩樹細浠ラ偖浠剁殑鏂瑰紡鍛婄煡锛岄櫎姝や箣澶栧畠杩樺彲浠ヤ笌github,jira绛夎繘琛屾暣鍚堣揪鍒颁护浜烘剰鍚戜笉鍒扮殑鏁堟灉銆傚畠涔熸彁渚涗簡寮哄ぇapi渚涘紑鍙戣€呮潵瀹屽杽鏇村姞璇︾粏鐨勯敊璇噰闆嗭紝骞朵互鍥捐〃鐨勫舰寮忓睍鐜版暟鎹紝甯姪寮€鍙戣€呮洿濂界殑鍒嗘瀽闂銆?br> 鎬讳箣鍦ㄩ」鐩腑浣跨敤sentry涔嬪悗锛岃兘蹇€熺殑瀹氫綅闂鎵€鍦紝鐭ラ亾闂鎵€鍦ㄤ箣鍚庤В鍐宠捣鏉ヤ篃鏄粈涔堟柟渚跨殑銆?/p>



浣滆€咃細max_wwwwww
閾炬帴锛歨ttps://www.jianshu.com/p/66e00077fac3
鏉ユ簮锛氱畝涔?br>钁椾綔鏉冨綊浣滆€呮墍鏈夈€傚晢涓氳浆杞借鑱旂郴浣滆€呰幏寰楁巿鏉冿紝闈炲晢涓氳浆杞借娉ㄦ槑鍑哄銆?/div>
 













以上是关于sentry浣跨敤瀹炶返的主要内容,如果未能解决你的问题,请参考以下文章

MySQL涔嬪垵浣跨敤

Mybatis 浠g爜瀹炶返

娲炲療婕忔礊绠$悊骞冲彴瀹炶返

鏈€鎶€鏈?| API缃戝叧鏈嶅姟鐔旀柇闄嶇骇瀹炶返

Spring Boot 2.0娣卞害瀹炶返涔嬫牳蹇冩妧鏈瘒

k8s瀹炶返18:helm閮ㄧ讲瀹夎grafana閰嶇疆娴嬭瘯