Rust
On this page, we get you up and running with Sentry's Rust SDK.
If you don't already have an account and Sentry project established, head over to sentry.io, then return to this page.
Using a framework? Take a look at our specific guides to get started.
Install
To add Sentry to your Rust project, just add a new dependency to your Cargo.toml
:
Cargo.toml
[dependencies]
sentry = "0.34.0"
Configure
The most convenient way to use this library is the sentry::init
function, which starts a Sentry client with a default set of integrations, and binds it to the current Hub.
The sentry::init
function returns a guard that, when dropped, will flush Events that were not yet sent to the Sentry service. It has a two second deadline for this, so shutdown of applications might slightly delay as a result. Keeping the guard around or sending events will not work.
main.rs
let _guard = sentry::init(("https://examplePublicKey@o0.ingest.sentry.io/0", sentry::ClientOptions {
release: sentry::release_name!(),
..Default::default()
}));
Important: Note your DSN. The DSN (Data Source Name) tells the SDK where to send events. If you forget it, view Settings -> Projects -> Client Keys (DSN) in sentry.io.
Verify Setup
The quickest way to verify Sentry in your Rust application is to cause a panic:
main.rs
fn main() {
let _guard = sentry::init(("https://examplePublicKey@o0.ingest.sentry.io/0", sentry::ClientOptions {
release: sentry::release_name!(),
..Default::default()
}));
// Sentry will capture this
panic!("Everything is on fire!");
}
Integrations
Integrations extend the functionality of the SDK for some common frameworks and libraries.
A list of integrations and their feature flags can be found in the integration API docs.
More Information
- Package:
- cargo:sentry
- Version:
- 0.34.0
- Repository:
- https://github.com/getsentry/sentry-rust