Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .sampo/changesets/ancient-iceseeker-ahti.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
cargo/posthog-rs: minor
---

Add tracing-subscriber integration for capturing tracing events as PostHog events
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ os_info = "3.14"
sha1 = "0.11"
regex = "1.10"
tracing = "0.1"
tracing-subscriber = { version = "0.3", optional = true, default-features = false, features = ["registry", "std"] }
tokio = { version = "1", features = [
"rt",
"sync",
Expand Down Expand Up @@ -54,6 +55,7 @@ async-client = ["tokio"]
capture-v1 = ["brotli", "zstd"]
test-harness = []
error-tracking = ["dep:backtrace", "dep:findshlibs"]
tracing-subscriber = ["dep:tracing-subscriber"]

[workspace]
members = [".", "compliance/adapter"]
23 changes: 23 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ cargo run --example feature_flags --features async-client
```

Shows:

- Boolean feature flag checks
- A/B test variants (multivariate flags)
- Property-based targeting
Expand All @@ -35,6 +36,7 @@ cargo run --example local_evaluation --features async-client
```

Shows:

- Performance comparison (API vs local evaluation)
- Setting up local evaluation with polling
- Batch flag evaluation
Expand All @@ -50,6 +52,7 @@ cargo run --example advanced_config --features async-client
```

Shows:

- Basic client setup (US region)
- EU region configuration (GDPR compliance)
- Self-hosted instance configuration
Expand All @@ -67,6 +70,7 @@ cargo run --example error_tracking
```

Shows:

- Capturing a Rust error as a PostHog Error Tracking event
- Attaching a distinct ID
- Adding custom exception properties
Expand Down Expand Up @@ -123,11 +127,30 @@ Custom HTTP clients are separate from TLS crypto-provider selection. The
`tls-no-provider` feature proposed in #245 is on `v1`, not this `main` branch;
changing the provider does not change the reqwest client types.

### 6. Tracing

Captures selected `tracing` events as PostHog events:

```bash
cargo run --example tracing --features tracing-subscriber

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Include the documented tracing example — the README points to an example target absent from this PR; add it or replace this command with an available quickstart. Reproduction: reproduced — cargo run --example tracing --features tracing-subscriber failed because no example target named tracing exists.

```

Shows:

- Capturing tracing events as PostHog events
- Filtering events with `tracing-subscriber`
- Configuring event names, identity, and shared properties
- Flushing events before shutdown

The `tracing-subscriber` feature is optional. The integration supports both
async and blocking clients.

## Key Concepts

### Feature Flag Types

1. **Boolean Flags**: Simple on/off toggles

```rust
FlagValue::Boolean(true) // enabled
FlagValue::Boolean(false) // disabled
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ mod feature_flag_evaluations;
mod feature_flags;
mod global;
mod local_evaluation;
#[cfg(feature = "tracing-subscriber")]
mod tracing_layer;

// Public interface - any change to this is breaking!
// Client
Expand All @@ -112,6 +114,8 @@ pub use client::ClientOptions;
pub use client::ClientOptionsBuilder;
pub use client::ClientOptionsBuilderError;
pub use client::{CaptureFailure, FlagsFailure, LocalEvaluationFailure, PostHogError};
#[cfg(feature = "tracing-subscriber")]
pub use tracing_layer::{EventNamer, PostHogLayer};

// Endpoints
pub use endpoints::{
Expand Down
Loading