React接入Sentry.js
// 需要安裝的庫
yarn add raven-js --save
yarn add raven-for-redux --save
// 在創(chuàng)建store的地方
import * as Raven from "raven-js";
import * as createRavenMiddleware from "raven-for-redux";
Raven.config("dns", {
release: `${版本號}`
}).install();
// 捕獲saga拋出的異常
const onError = (error: Error) => {
Raven.captureException(error);
}
// 修改saga的middleware
const sagaMiddleware = createSagaMiddleware({
onError
});
const composedEnhancers = compose(
applyMiddleware(
...
createRavenMiddleware(Raven, {
getUserContext(state){
// 設(shè)置用戶信息,用于上報識別
let userContext = [
"device_id": localStorage.getItem("device_id")
];
if(localStorage.getItem("uid")){
userContext["uid"] = localStorage.getItem("uid");
userContext["key"] = localStorage.getItem("key");
userContext["time"] = localStorage.getItem("time");
}
}
})
)
);
// 打開頁面時,需要設(shè)置設(shè)備標(biāo)識
localStorage.setItem("device_id", uuid);
// 在用戶登錄后,需要記錄uid key time
localStorage.setItem("uid", uid);
localStorage.setItem("key", key);
localStorage.setItem("time", time);
轉(zhuǎn)載于:https://www.cnblogs.com/unreal-feather/p/10324813.html
總結(jié)
以上是生活随笔為你收集整理的React接入Sentry.js的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 暮开头成语有哪些?
- 下一篇: ADC中宽带巴伦的使用