SDK not clearing buffer for CLI application

I am using @sentry/node within a CLI application. When using simple code like the following I do not get any messages/errors sent off in scenarios where the application exits quickly (like printing help information).

Sentry.captureMessage('Hello, world!');
Sentry.captureException(new Error('Testing Stuff'));

I have been able to get the errors to report by adding setTimeouts to the code, but that was to just verify I have the right configuration. Is there a way to guarantee, or invoke, that the buffer gets cleared of queued messages?

Hey,

I think what you are looking for is close.

let client = Sentry.getCurrentHub().getClient();
if (client) {
  client.close(2000).then(function() {
    process.exit();
  });
}

Hope this helps :slight_smile: