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
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. - 5
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