Native Crash Reporting for axumNEW
Learn how to capture native crashes, such as segmentation faults, from your Rust application as minidumps.
The SDK reports panics automatically, but some crashes aren't panics. For example, a segmentation fault in unsafe code or in a C library called through FFI kills your process without running Rust's panic handling. The minidump integration captures these native crashes as minidumps and sends them to Sentry.
A Word on Data Privacy
Minidumps are memory dumps of the process at the moment it crashes. As such, they might contain sensitive information on the target system, such as environment variables, local pathnames or maybe even in-memory representations of input fields, including passwords. Sentry does not store these memory dumps by default. Once processed, they are removed immediately, and all sensitive information is stripped from the resulting issues.
You can configure Sentry to store minidumps as attachments.
- Sentry Rust SDK version
0.49.3or later. - Linux, macOS, or Windows. On other targets, the
minidumpfeature has no effect.
Enable the minidump feature in your Cargo.toml:
Cargo.toml[dependencies]
sentry = { version = "0.49.5", features = ["minidump"] }
[dependencies]
sentry = { version = "0.49.5", features = ["minidump"] }
Then, add the MinidumpIntegration when you initialize the SDK at the start of main:
main.rsuse sentry::integrations::minidump::MinidumpIntegration;
fn main() {
let _guard = sentry::init(
sentry::ClientOptions::new()
.dsn("___PUBLIC_DSN___")
.add_integration(MinidumpIntegration::new()),
);
// Your app code goes here.
}
use sentry::integrations::minidump::MinidumpIntegration;
fn main() {
let _guard = sentry::init(
sentry::ClientOptions::new()
.dsn("___PUBLIC_DSN___")
.add_integration(MinidumpIntegration::new()),
);
// Your app code goes here.
}
When you call sentry::init, the integration starts a separate crash reporter process by running your app's binary a second time. If your app crashes, the crash reporter writes a minidump and sends it to Sentry as a fatal event, with the minidump attached. The crash reporter uses the same client options as your app, so options such as release and environment also apply to crash events.
Because the crash reporter runs your binary:
- Any code before
sentry::initruns in both processes. - In the crash reporter process,
sentry::initnever returns, so code after it only runs in your app. - Only one crash reporter runs per process. Calling
sentry::initagain doesn't start another one.
If you need to run code before sentry::init, use is_crash_reporter_process to skip work that should only happen in your app:
main.rsuse sentry::integrations::minidump::MinidumpIntegration;
fn main() {
let minidump = MinidumpIntegration::new();
if !minidump.is_crash_reporter_process() {
// App-only setup, for example, writing a PID file.
}
let _guard = sentry::init(
sentry::ClientOptions::new()
.dsn("___PUBLIC_DSN___")
.add_integration(minidump),
);
}
use sentry::integrations::minidump::MinidumpIntegration;
fn main() {
let minidump = MinidumpIntegration::new();
if !minidump.is_crash_reporter_process() {
// App-only setup, for example, writing a PID file.
}
let _guard = sentry::init(
sentry::ClientOptions::new()
.dsn("___PUBLIC_DSN___")
.add_integration(minidump),
);
}
The crash reporter can't read your app's scope, so data you set with functions like sentry::configure_scope isn't included in crash events. To add the user, tags, extra data, or breadcrumbs to crash events, send them to the crash reporter through the integration after you initialize the SDK:
main.rsuse sentry::integrations::minidump::MinidumpIntegration;
fn main() {
let _guard = sentry::init(/* ... as above ... */);
sentry::with_integration(|minidump: &MinidumpIntegration, _| {
minidump.set_user(Some(sentry::User {
id: Some("42".into()),
..Default::default()
}));
minidump.set_tag("my_tag".into(), Some("my_value".into()));
});
}
use sentry::integrations::minidump::MinidumpIntegration;
fn main() {
let _guard = sentry::init(/* ... as above ... */);
sentry::with_integration(|minidump: &MinidumpIntegration, _| {
minidump.set_user(Some(sentry::User {
id: Some("42".into()),
..Default::default()
}));
minidump.set_tag("my_tag".into(), Some("my_value".into()));
});
}
To show function names and source locations in crash stack traces, Sentry needs your app's debug information files. Follow the steps in Source Context to create and upload them. To learn more, see Debug Information Files.
To configure the minidump directory, upload timeout, crash reporter process name, and more, see the sentry-minidump API docs.
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").