@sentry/node
4.6.3
I'm trying to integrate the new sentry SDK into our serverless architecture, we have a general try-catch around every handler, that calls captureException. In a nutshell this is what our code looks like (I left out our business logic and a lot of utility methods).
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
}
}
I made the handler always throw an error. When I do the first request, everything ends up in Sentry just fine. On the second request, nothing happens. When I look in CloudWatch, this is what I find. I have added comments for convenience.
/// 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
As you can see, it never hits the beforeSend
middleware on the second request, so I guess it's never sent to Sentry at all.
I should note that when I do Sentry.getCurrentHub().getClient().captureException(error)
, it does send the exception to Sentry every time, but the scope configured in Sentry.configureScope
is never applied to the event.
I have tried reproducing this locally, but it only happens when deployed on AWS Lambda.
There's a chance that it's getting de-duplicated.
You can use debug: true
in your init
call to see what's going on.
If it indeed is getting deduped, you can remove this integration using:
Sentry.init({
integrations: integrations => {
return integrations.filter(integration => integration.name !== 'Dedupe');
}
});
Interesting. Found this looking for a similar issue. The remove dedupe fixed it for me.
Closing this since it's not a bug.
Additionally the next major version makes Dedupe
optional, which means there is no deduping by default.
Most helpful comment
There's a chance that it's getting de-duplicated.
You can use
debug: true
in yourinit
call to see what's going on.If it indeed is getting deduped, you can remove this integration using:
https://docs.sentry.io/platforms/node/default-integrations/