Rust product analytics installation

Install the posthog-rs crate by adding it to your Cargo.toml.

Cargo.toml
[dependencies]
posthog-rs = "0.3.5"

Next, set up the client with your PostHog project key.

Rust
let client = posthog_rs::client(env!("<ph_project_api_key>"));

Blocking client

Our Rust SDK supports both blocking and async clients. The async client is the default and is recommended for most use cases.

If you need to use a synchronous client instead – like we do in our CLI –, you can opt into it by disabling the asynchronous feature on your Cargo.toml file.

toml
[dependencies]
posthog-rs = { version = "0.3.5", default-features = false }

In blocking mode, calls to capture and related methods will block until the PostHog event capture API returns – generally this is on the order of tens of milliseconds, but you may want to thread::spawn a background thread when you send an event.

Community questions

Was this page useful?

Questions about this page? or post a community question.