skip to content
Posts · November 2026

Integrating Sentry into Tauri 2 without losing the local crash log


LumenPod is a Tauri 2 media library. If the Rust process panicked, the explanation went to stderr. Someone could send me the app’s diagnostic bundle and I’d see a Rust log that stopped just before the line I needed.

When I added Sentry, I still wanted that line locally, even if the user had turned off crash reporting. I also had to decide how much of a panic belonged in a bundle someone might share. An error during an import can include the full path to their video.

Give the client the same lifetime as the app

Our Cargo workspace pins sentry to 0.42.0 and tauri-plugin-sentry to 0.5.0. The plugin takes the Rust client and handles the webview integration. Our Tauri capability includes sentry:default. Plugin API and dependencies

If a setup helper calls sentry::init and keeps the returned guard in a local variable, it drops the guard as soon as setup finishes. Our helper returns the guard to the function that runs Tauri’s event loop. With the other plugins omitted, the wiring looks like this:

pub fn run() {
let sentry_client = telemetry::init();
let mut builder = tauri::Builder::default();
if let Some(client) = sentry_client.as_ref() {
builder = builder.plugin(tauri_plugin_sentry::init(client));
}
builder
.run(tauri::generate_context!())
.expect("error while running Tauri");
}

telemetry::init() is our own helper. It returns Option<sentry::ClientInitGuard>, so the guard stays in scope throughout the event loop. A missing or blank DSN yields None. That build still starts and installs the local panic logger. When a DSN is present, we set a release with sentry::release_name!(), distinguish development from production, and attach stack traces.

Chain the panic hook

Rust has one active panic hook for the process. Once Sentry has installed its hook, calling set_hook with a standalone logger would displace it. Our logger saves the installed hook so it can call it after writing the local record. In abbreviated form:

let previous = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
if let Some(location) = info.location() {
let file = std::path::Path::new(location.file())
.file_name()
.and_then(|name| name.to_str())
.unwrap_or("unknown");
tracing::error!(event = "panic", file, line = location.line(), "panicked");
}
previous(info);
}));

Our full hook writes two records. The ordinary Rust log gets the source basename, line and thread name. A separate private log gets the panic payload and stays out of the diagnostic bundle. We keep just the basename because a dependency’s compiled source location can contain the home directory of the person who built the app.

Calling previous(info) also preserves the default handler in builds without Sentry.

A DSN tells the app where to send an event. The user controls whether crash events may leave the app. Our Rust-side consent flag starts as denied, and a Tauri command updates it independently of analytics consent. The Sentry before_send callback reads that flag for each error event:

if !consent::crash_granted() {
return None;
}

For events that pass, we clear the user, request and server-name fields. We also inspect exception text, breadcrumb messages and data, log parameters, and extra values. An error can say “import failed” and still carry every input filename in an array inside a breadcrumb.

Our scrubber walks those nested values and replaces a whole string with [redacted] when it recognizes a path pattern such as a home-directory path or a file URL. That heuristic can discard useful text and miss unfamiliar formats. Keeping filenames out of structured telemetry at the call site saves us from depending entirely on the filter.

The app also enables automatic session tracking and separately initializes a native minidump handler on non-iOS builds when a client exists. To find out what leaves the app when reporting is off, I would check session traffic and minidumps separately from error events.

Make the report useful after redaction

If an import fails, I still want to find the operation that led up to it. Our tracing context already has a trace ID, span ID and function name. When that context changes, a callback copies those values onto the Sentry scope. When it clears, the callback removes the corresponding tags and extras. Otherwise a later error could carry the previous operation’s ID.

If someone shares a diagnostic bundle after a failed import, I can copy the trace ID from Sentry and search their log for the same operation without knowing the filename.

What I would check in a release build

  • Leave the DSN blank and trigger a controlled panic in a disposable build. Look for the source location in the Rust log.
  • Turn crash reporting off and watch outbound traffic while capturing a synthetic error. Check session updates and native crashes separately.
  • Turn reporting on and put a fictional file path inside a test error’s breadcrumb data. Open the event in Sentry and check the redacted value, release and trace ID.
  • Put a distinctive fictional filename in a panic payload and export the diagnostic bundle. Search the bundle for both the filename and the panic location. Only the location should turn up.

I used AI to help draft and edit this write-up of our Tauri integration.