From 50916476c0ceb489c106873df7a319ad619a1dbe Mon Sep 17 00:00:00 2001 From: Catalin Irimie Date: Fri, 12 Jun 2026 19:13:25 +0300 Subject: [PATCH 1/3] docs(rust): add Rust error tracking installation guide Documents manual exception capture (capture_exception / capture_exception_with), panic autocapture via install_panic_hook, and stack trace configuration for the Rust SDK, moving the usage docs out of the posthog-rs README per PostHog/posthog-rs#130 review. Adds the installation page, the error tracking nav entry, and an error tracking section on the Rust library page. --- .../docs/error-tracking/installation/rust.mdx | 137 ++++++++++++++++++ contents/docs/libraries/rust/index.mdx | 30 ++++ src/navs/index.js | 4 + 3 files changed, 171 insertions(+) create mode 100644 contents/docs/error-tracking/installation/rust.mdx diff --git a/contents/docs/error-tracking/installation/rust.mdx b/contents/docs/error-tracking/installation/rust.mdx new file mode 100644 index 000000000000..85e7ec3cedb6 --- /dev/null +++ b/contents/docs/error-tracking/installation/rust.mdx @@ -0,0 +1,137 @@ +--- +title: Rust error tracking installation +platformLogo: rust +showStepsToc: true +--- + +import { Steps, Step } from 'components/Docs/Steps' +import { CalloutBox } from 'components/Docs/CalloutBox' + + + + + +Install the [PostHog Rust SDK](/docs/libraries/rust): + +```bash +cargo add posthog-rs +``` + +Error tracking ships enabled by default through the `error-tracking` feature. If you build with `default-features = false`, add it back explicitly: + +```toml +[dependencies] +posthog-rs = { version = "*", default-features = false, features = ["error-tracking"] } +``` + + + +The 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. + + + + + + + +```rust +let client = posthog_rs::client("").await; +``` + +The default client is async (Tokio). Building with `default-features = false` gives you a blocking client instead — the same methods without `.await`. + + + + + +`capture_exception` works with any `std::error::Error` and captures it personlessly — the exception type, message, and full `source()` chain are sent, with a stack trace recorded at the call site: + +```rust +let error = std::io::Error::new(std::io::ErrorKind::Other, "connection refused"); + +client.capture_exception(&error).await.unwrap(); +``` + +To associate the exception with a person or attach context, use `capture_exception_with`: + +```rust +use posthog_rs::CaptureExceptionOptions; + +client.capture_exception_with( + &error, + CaptureExceptionOptions::new() + .distinct_id("user_distinct_id") + .property("route", "/checkout").unwrap() + .group("company", "company_id") + .fingerprint("my-custom-fingerprint") + .level("warning"), +).await.unwrap(); +``` + +All options are optional: `distinct_id` links a person, `property` and `group` add context, `fingerprint` overrides [issue grouping](/docs/error-tracking/grouping-issues), and `level` sets the severity (defaults to `error`). + +If you use `anyhow`, pass the underlying error with `err.as_ref()`: + +```rust +let result: anyhow::Result<()> = do_work(); +if let Err(err) = result { + client.capture_exception(err.as_ref()).await.unwrap(); +} +``` + + + + + +Install the panic hook once near application startup to capture Rust panics automatically: + +```rust +posthog_rs::install_panic_hook("").unwrap(); +``` + +Panics are captured personlessly with the panic message, the panic site (file, line, and column), and a stack trace. The previously installed hook still runs afterwards, so default panic output and other integrations are unaffected. + +Panic capture is best-effort: hooks run before unwinding, so panics caught later by `catch_unwind` are still captured, while aborting processes may exit before delivery completes. + + + + + +Stack trace capture and in-app frame classification are configured per client through `ErrorTrackingOptionsBuilder`: + +```rust +use posthog_rs::{ClientOptionsBuilder, ErrorTrackingOptionsBuilder}; + +let options = ClientOptionsBuilder::default() + .api_key("".to_string()) + .error_tracking( + ErrorTrackingOptionsBuilder::default() + // Skip the stack walk entirely, e.g. for high-volume handled errors + .capture_stacktrace(false) + // Mark frames from a crate as library code rather than in-app + .in_app_exclude_paths(vec!["other_crate::".to_string()]) + .build() + .unwrap(), + ) + .build() + .unwrap(); + +let client = posthog_rs::client(options).await; +``` + +In-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. + + + + + +Trigger a test exception to confirm events are being sent to PostHog. You should see it appear in the [error tracking issues view](https://app.posthog.com/error_tracking). + +```rust +let error = std::io::Error::new(std::io::ErrorKind::Other, "This is a test exception from Rust"); +client.capture_exception(&error).await.unwrap(); +``` + + + + diff --git a/contents/docs/libraries/rust/index.mdx b/contents/docs/libraries/rust/index.mdx index 14752d4205db..609cda1a47c3 100644 --- a/contents/docs/libraries/rust/index.mdx +++ b/contents/docs/libraries/rust/index.mdx @@ -9,6 +9,7 @@ features: groupAnalytics: true surveys: false aiObservability: false + errorTracking: true --- ## Installation @@ -63,6 +64,35 @@ When local evaluation is enabled, flag definitions are fetched on initialization > **Note:** Local evaluation requires providing any person properties, groups, or group properties needed to evaluate the flag's release conditions, since PostHog can't fetch these automatically without a server request. +## Error tracking + +You can capture exceptions and panics with the Rust SDK. `capture_exception` accepts any `std::error::Error` and records a stack trace at the call site; `capture_exception_with` additionally links a person and attaches context: + +```rust +use posthog_rs::CaptureExceptionOptions; + +let error = std::io::Error::new(std::io::ErrorKind::Other, "connection refused"); + +// Captured personlessly +client.capture_exception(&error).await.unwrap(); + +// Associated with a person, with optional context +client.capture_exception_with( + &error, + CaptureExceptionOptions::new() + .distinct_id("user_distinct_id") + .property("route", "/checkout").unwrap(), +).await.unwrap(); +``` + +To capture panics automatically, install the panic hook once near application startup: + +```rust +posthog_rs::install_panic_hook("").unwrap(); +``` + +For the full setup guide, see the [Rust error tracking installation docs](/docs/error-tracking/installation/rust). + ## Observability The Rust SDK uses [`tracing`](https://docs.rs/tracing) for structured logging. Add a tracing subscriber to your application to see SDK logs: diff --git a/src/navs/index.js b/src/navs/index.js index a9ed1dd83e3a..3388cb2bcb4f 100644 --- a/src/navs/index.js +++ b/src/navs/index.js @@ -4888,6 +4888,10 @@ export const docsMenu = { name: 'PHP', url: '/docs/error-tracking/installation/php', }, + { + name: 'Rust', + url: '/docs/error-tracking/installation/rust', + }, { name: 'iOS', url: '/docs/error-tracking/installation/ios', From 81515007e13135be77facc273088f40f84a5de44 Mon Sep 17 00:00:00 2001 From: Catalin Irimie Date: Fri, 12 Jun 2026 19:41:34 +0300 Subject: [PATCH 2/3] docs(rust): include the API host in error tracking init examples EU Cloud and self-hosted projects would otherwise send captures to the default US endpoint; sibling installation pages all pass the host. --- contents/docs/error-tracking/installation/rust.mdx | 11 +++++++++-- contents/docs/libraries/rust/index.mdx | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/contents/docs/error-tracking/installation/rust.mdx b/contents/docs/error-tracking/installation/rust.mdx index 85e7ec3cedb6..697544ad73f0 100644 --- a/contents/docs/error-tracking/installation/rust.mdx +++ b/contents/docs/error-tracking/installation/rust.mdx @@ -35,7 +35,10 @@ The Rust SDK resolves stack traces in-process, so captured frames include file n ```rust -let client = posthog_rs::client("").await; +let client = posthog_rs::client(( + "", + "", +)).await; ``` The default client is async (Tokio). Building with `default-features = false` gives you a blocking client instead — the same methods without `.await`. @@ -86,7 +89,10 @@ if let Err(err) = result { Install the panic hook once near application startup to capture Rust panics automatically: ```rust -posthog_rs::install_panic_hook("").unwrap(); +posthog_rs::install_panic_hook(( + "", + "", +)).unwrap(); ``` Panics are captured personlessly with the panic message, the panic site (file, line, and column), and a stack trace. The previously installed hook still runs afterwards, so default panic output and other integrations are unaffected. @@ -104,6 +110,7 @@ use posthog_rs::{ClientOptionsBuilder, ErrorTrackingOptionsBuilder}; let options = ClientOptionsBuilder::default() .api_key("".to_string()) + .host("") .error_tracking( ErrorTrackingOptionsBuilder::default() // Skip the stack walk entirely, e.g. for high-volume handled errors diff --git a/contents/docs/libraries/rust/index.mdx b/contents/docs/libraries/rust/index.mdx index 609cda1a47c3..403ff55a6e64 100644 --- a/contents/docs/libraries/rust/index.mdx +++ b/contents/docs/libraries/rust/index.mdx @@ -88,7 +88,10 @@ client.capture_exception_with( To capture panics automatically, install the panic hook once near application startup: ```rust -posthog_rs::install_panic_hook("").unwrap(); +posthog_rs::install_panic_hook(( + "", + "", +)).unwrap(); ``` For the full setup guide, see the [Rust error tracking installation docs](/docs/error-tracking/installation/rust). From bc0e4124776c72bede8a5451663e77cbb212d575 Mon Sep 17 00:00:00 2001 From: Catalin Irimie Date: Tue, 16 Jun 2026 19:53:55 +0300 Subject: [PATCH 3/3] docs(rust): drop panic autocapture until it ships Panic autocapture is still in review (PostHog/posthog-rs#130) and unreleased. Ship the manual error tracking docs now; the panic hook section returns once it lands in a release. --- .../docs/error-tracking/installation/rust.mdx | 17 ----------------- contents/docs/libraries/rust/index.mdx | 11 +---------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/contents/docs/error-tracking/installation/rust.mdx b/contents/docs/error-tracking/installation/rust.mdx index 697544ad73f0..aacc3fd54632 100644 --- a/contents/docs/error-tracking/installation/rust.mdx +++ b/contents/docs/error-tracking/installation/rust.mdx @@ -84,23 +84,6 @@ if let Err(err) = result { - - -Install the panic hook once near application startup to capture Rust panics automatically: - -```rust -posthog_rs::install_panic_hook(( - "", - "", -)).unwrap(); -``` - -Panics are captured personlessly with the panic message, the panic site (file, line, and column), and a stack trace. The previously installed hook still runs afterwards, so default panic output and other integrations are unaffected. - -Panic capture is best-effort: hooks run before unwinding, so panics caught later by `catch_unwind` are still captured, while aborting processes may exit before delivery completes. - - - Stack trace capture and in-app frame classification are configured per client through `ErrorTrackingOptionsBuilder`: diff --git a/contents/docs/libraries/rust/index.mdx b/contents/docs/libraries/rust/index.mdx index 403ff55a6e64..3b74a2d1b7aa 100644 --- a/contents/docs/libraries/rust/index.mdx +++ b/contents/docs/libraries/rust/index.mdx @@ -66,7 +66,7 @@ When local evaluation is enabled, flag definitions are fetched on initialization ## Error tracking -You can capture exceptions and panics with the Rust SDK. `capture_exception` accepts any `std::error::Error` and records a stack trace at the call site; `capture_exception_with` additionally links a person and attaches context: +You can capture exceptions with the Rust SDK. `capture_exception` accepts any `std::error::Error` and records a stack trace at the call site; `capture_exception_with` additionally links a person and attaches context: ```rust use posthog_rs::CaptureExceptionOptions; @@ -85,15 +85,6 @@ client.capture_exception_with( ).await.unwrap(); ``` -To capture panics automatically, install the panic hook once near application startup: - -```rust -posthog_rs::install_panic_hook(( - "", - "", -)).unwrap(); -``` - For the full setup guide, see the [Rust error tracking installation docs](/docs/error-tracking/installation/rust). ## Observability