我有一个带有redux的react-native应用。我想在Sentry记录错误时获取带有数据的PUT请求。我是Sentry的新手,可以在App.js中使用它:
Sentry.init({
dsn: ...,
enableInExpoDevelopment: true,
debug: true,
beforeSend(event) {
try {
fetchMyData(data)
Sentry.withScope(function(scope) {
Sentry.captureMessage('Error');
});
return event;
}
catch (e) {
return e;
}
},
});
[它可以正常工作,并且请求在大多数时间都是成功的,但是beforeSend被称为多个时间,并且在Sentry中,事件循环:Put Request-> captureMessage-> Put Request-> captureMessage…,依此类推。
Sentry记录时还有另一种方法来调用该方法吗?仅在调用beforeSend时定义数据。为什么会有这个循环?
谢谢!
我认为这是您想要的:
Sentry.init({
dsn: 'http://bla.com/12',
debug: true,
beforeSend(event) {
try {
// fetchMyData(data)
// Sentry.withScope(function(scope) {
// Sentry.captureMessage('Error');
// });
const client = new Sentry.ReactNativeClient({dsn: 'http://bla.com/12'});
client.captureMessage('test');
return event;
}
catch (e) {
return e;
}
},
});
您需要创建一个新的Client
才能从beforeSend
发送这些事件。如果您在Sentry.captureMessage
中调用beforeSend
,那么如果不检查特定事件,则会创建一个无限循环。