Rust error tracking installation
- 1
Install the Rust SDK
RequiredInstall the PostHog Rust SDK:
TerminalError tracking ships enabled by default through the
error-trackingfeature. If you build withdefault-features = false, add it back explicitly:tomlSource context not yet supportedThe Rust SDK resolves stack traces in-process, so captured frames include file names, line numbers, and function names without any symbol uploads. Source context (displaying the surrounding lines of code in the error tracking UI) is not yet supported.
- 2
Initialize the client
RequiredRustThe default client is async (Tokio). Building with
default-features = falsegives you a blocking client instead — the same methods without.await. - 3
Capture exceptions
Requiredcapture_exceptionworks with anystd::error::Errorand captures it personlessly — the exception type, message, and fullsource()chain are sent, with a stack trace recorded at the call site:RustTo associate the exception with a person or attach context, use
capture_exception_with:RustAll options are optional:
distinct_idlinks a person,propertyandgroupadd context,fingerprintoverrides issue grouping, andlevelsets the severity (defaults toerror).If you use
anyhow, pass the underlying error witherr.as_ref():Rust - 4
Capture panics
OptionalPanic autocapture is opt-in and uses the process-global client. Enable
capture_panicsand initialize the global client withinit_global; the SDK then installs a process-widestd::panichook:RustEach panic is captured as a personless
$exceptioncarrying the panic message, the panic-site location, and a call-site stack trace (subject tocapture_stacktrace). The previously installed hook still runs afterwards.Because a panic hook is process-global, panic autocapture pairs with the global client — there is no per-
Clientpanic API. Capture routes through the SDK's background worker, so it needs no async runtime, and the flush is bounded to a short timeout (2s) so a slow or unreachable PostHog can't freeze the crashing process. Delivery is best-effort: under sustained backpressure the event may not be sent before the process exits. - 5
Configure stack traces
OptionalStack trace capture and in-app frame classification are configured per client through
ErrorTrackingOptionsBuilder:RustIn-app patterns match both file paths and function symbols, so crate prefixes like
"my_crate::"and path fragments like"/service/"both work. By default, frames from the cargo registry, the standard library, and vendored or target paths are classified as library code. - 6
Verify error tracking
RecommendedTrigger a test exception to confirm events are being sent to PostHog. You should see it appear in the error tracking issues view.
Rust