@sentry/node
4.6.3
我正在尝试将新的哨兵 SDK 集成到我们的无服务器架构中,我们在每个处理程序周围都有一个通用的 try-catch,它调用了 captureException。 简而言之,这就是我们的代码的样子(我省略了我们的业务逻辑和许多实用方法)。
Sentry.init({
dsn: process.env.sentryUrl,
environment: process.env.NODE_ENV,
// debugging issue where we only get an event once
beforeSend: (event, _) => { console.log(event.exception); return event }
});
async function wrapper(...) {
try {
handler(...)
} catch(error) {
Sentry.configureScope(scope => {
scope.setTag("test", "Hello, world")
})
const eventId = Sentry.captureException(error)
// debugging, log event id to see if captureException works
console.log(eventId)
const flushResult = await Sentry.flush(1000)
console.log(flushResult) // see if flush succeeded
}
}
我让处理程序总是抛出错误。 当我执行第一个请求时,一切都以 Sentry 结束。 在第二个请求中,什么也没有发生。 当我查看 CloudWatch 时,这就是我发现的。 为方便起见,我添加了注释。
/// the eventId from captureException
2019-02-26T13:47:22.584Z: 8cf83e38081a4672841a6f795ce8105a
/// the middleware defined in Sentry.init
2019-02-26T13:47:23.153Z: { values: [ { stacktrace: [Object], type: 'Error', value: 'This is an error' } ] }
/// result of Sentry.flush
2019-02-26T13:47:23.294Z: true
/// the eventId from captureException
2019-02-26T13:47:24.761Z fbc2c8b2a4d5447380a0f92dd87896f6
/// result of Sentry.flush
2019-02-26T13:47:24.963Z: true
如您所见,它从未在第二次请求中命中beforeSend
中间件,所以我想它根本没有发送到 Sentry。
我应该注意,当我执行Sentry.getCurrentHub().getClient().captureException(error)
,它每次都会向 Sentry 发送异常,但是Sentry.configureScope
配置的范围永远不会应用于该事件。
我曾尝试在本地重现此内容,但仅在部署在 AWS Lambda 上时才会发生。
它有可能会进行重复数据删除。
您可以在init
调用中使用debug: true
来查看发生了什么。
如果确实被重复数据删除,您可以使用以下方法删除此集成:
Sentry.init({
integrations: integrations => {
return integrations.filter(integration => integration.name !== 'Dedupe');
}
});
有趣的。 发现this寻找类似的问题。 删除重复数据删除为我修复了它。
关闭它,因为它不是一个错误。
此外,下一个主要版本将Dedupe
设为可选,这意味着默认情况下没有重复数据删除。
最有用的评论
它有可能会进行重复数据删除。
您可以在
init
调用中使用debug: true
来查看发生了什么。如果确实被重复数据删除,您可以使用以下方法删除此集成:
https://docs.sentry.io/platforms/node/default-integrations/