Reputation: 51
In Node.js 8 I'm not able to capture error on sentry if I am using process.exit(0) at the end of my code. Otherwise its working fine
const Sentry = require('@sentry/node');
Sentry.init({ dsn: 'https://c3f5****************[email protected]/1288850' });
try{
throw new Error('test-error');
}
catch(e){
const Eid = Sentry.captureException(e);
console.log(Eid);
}
process.exit(0);
Upvotes: 0
Views: 1535
Reputation: 845
Close Sentry connection before exit like this:
const Sentry = require('@sentry/node');
Sentry.init({ dsn: 'https://c3f5****************[email protected]/1288850'});
try{
throw new Error('test-error');
}
catch(e){
const Eid = Sentry.captureException(e);
console.log(Eid);
}
Sentry.close().then(() => process.exit(0));
Now all the pending Sentry logs will be reported before exit.
Upvotes: 0
Reputation: 814
Sentry.captureException(e) is asynchronous, so process.exit(0) is terminating the process before Sentry.captureException is able to run.
Upvotes: 5