码迷,mamicode.com
首页 > Web开发 > 详细

React接入Sentry.js

时间:2019-01-26 21:01:09      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:uuid   text   ice   ...   yar   context   修改   设备   from   

// 需要安装的库
yarn add raven-js --save
yarn add raven-for-redux --save

// 在创建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){
// 设置用户信息,用于上报识别
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");
}
}
})
)
);

// 打开页面时,需要设置设备标识
localStorage.setItem("device_id", uuid);

// 在用户登录后,需要记录uid key time
localStorage.setItem("uid", uid);
localStorage.setItem("key", key);
localStorage.setItem("time", time);

React接入Sentry.js

标签:uuid   text   ice   ...   yar   context   修改   设备   from   

原文地址:https://www.cnblogs.com/unreal-feather/p/10324813.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!