Shutdown and Draining
Learn more about the default behavior of our SDK if the application shuts down unexpectedly.
The default behavior of most SDKs is to send out events over the network asynchronously in the background. This means that some events might be lost if the application shuts down unexpectedly. The SDKs provide mechanisms to cope with this.
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.
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").