关闭和排空

了解如果应用程序意外关闭时,SDK 的默认行为。

大多数 SDK 的默认行为是异步在后台通过网络发送事件。这意味着如果应用程序意外关闭,某些事件可能会丢失。SDK 提供了应对这种情况的机制。

The close method optionally takes a timeout in milliseconds and returns a promise that resolves when all pending events are flushed, or the timeout kicks in.

Note that you can call this method on SIGTERM to gracefully shut down a service or container.

Copied
Sentry.close(2000).then(function () {
  process.exit();
});

After a call to close, the current client cannot be used anymore. It's important to only call close immediately before shutting down the application.

Alternatively, the flush method drains the event queue while keeping the client enabled for continued use.