Shutdown and Draining
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.
When the Rust SDK initializes a guard is returned from the init
function. The destructor will automatically wait shutdown_timeout
seconds. This means you just need to hold on to the guard and make sure it disposes on shutdown. Alternatively the client can be closed:
Copied
use std::time::Duration;
if let Some(client) = sentry::Hub::current().client() {
client.close(Some(Duration::from_secs(2)));
}
After a call to close
, the client cannot be used anymore. It's important to only call close
immediately before shutting down the application.
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").
- Package:
- cargo:sentry
- Version:
- 0.32.3
- Repository:
- https://github.com/getsentry/sentry-rust