unable to report errors more than once when handlers wrapped with "withSentry"
demsey2 opened this issue · 2 comments
At this stage, I am not sure if the issue is with this library or @sentry/node
so I have a lambda with the following code
import withSentry from "serverless-sentry-lib";
export const handler = withSentry(async (event: S3Event, context: Context) => {
throw new Error('test');
});
so if I call that lambda (no instance/cold start), it will report the error, but when I try again and the same lambda instance is called then the error is not reported. I thought it might be because is the same message but I tried
throw new Error(`test with dynamic error ${Date.now()}`);
and no luck with that
then I just added Sentry.init
export const handler = withSentry(async (event: S3Event, context: Context) => {
Sentry.init({ dsn: process.env.SENTRY_DSN });
throw new Error('test');
});
and this is reporting errors as many times as I call that lambda
my dependencies
"serverless-sentry": "^2.0.2",
"serverless-sentry-lib": "^2.0.1",
"@sentry/node": "^5.18.1",
when I try to call
let client = Sentry.getCurrentHub().getClient();
console.log(client.getOptions());
I got
{
dsn: '...',
release: '984ec86',
environment: 'dev',
defaultIntegrations: [
InboundFilters { _options: {}, name: 'InboundFilters' },
FunctionToString { name: 'FunctionToString' },
Console { name: 'Console' },
Http { name: 'Http', _breadcrumbs: true, _tracing: false },
OnUncaughtException {
_options: {},
name: 'OnUncaughtException',
handler: [Function]
},
OnUnhandledRejection {
_options: [Object],
name: 'OnUnhandledRejection'
},
LinkedErrors { name: 'LinkedErrors', _key: 'cause', _limit: 5 }
],
enabled: false
}
that flag enabled: false doesn't exist when I call lambda first time
Interesting bug report. Thanks! This will certainly need some additional investigation.
I've just published 2.1.0 that should address this issue. I'm not perfectly sure if this is actually a Sentry issue, but when the Lambda finishes we now call flush
instead of close
to keep the Sentry instance intact. This should fix the problem.