获取更多动态,关注公众号:黑客下午茶

Shutdown and Draining

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

The Python SDK automatically drains on shutdown unless the AtExitIntegration is removed or the shutdown_timeout config key is set to 0. To manually drain the client provides a close method:

Copied
from sentry_sdk import Hub

client = Hub.current.client
if client is not None:
    client.close(timeout=2.0)

After a call to close, the 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.

You can edit this page on GitHub.