Skip to content

Commit 5bc6aa6

Browse files
sarahxsandersclaude
andcommitted
feat(integration): add rust as a full example-based variant
Add a Rust integration variant anchored on a real example app (example-apps/rust): an Axum service that builds one posthog-rs client per process, configures it from the environment, identifies users via a $set property, captures events, evaluates feature flags with the current evaluate_flags snapshot API, captures exceptions, and calls flush() + shutdown() on graceful shutdown (capture is fire-and-forget). Ships a full example rather than docs-only so the wizard has a concrete shape to match. Adds rust commandments (including honest limitations: no alias/surveys/session-replay) and skips the Rust target/ build dir when flattening the example. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 73b2584 commit 5bc6aa6

9 files changed

Lines changed: 3037 additions & 0 deletions

File tree

context/commandments.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ commandments:
9090
- Avoid deprecated feature flag helpers such as `IsFeatureEnabled`, `GetFeatureFlag`, `GetFeatureFlagPayload`, and `Capture.SendFeatureFlags` in new code
9191
- For error tracking, use `posthog.NewDefaultException(...)` for direct captures or wrap `log/slog` with `posthog.NewSlogCaptureHandler(...)` for automatic warning-and-above exception capture
9292

93+
rust:
94+
- posthog-rs is the Rust SDK crate; add it with `cargo add posthog-rs` and construct the client with `posthog_rs::client(options).await`
95+
- Create one client per process and share it (for example an `Arc` in your app state or a `OnceCell`); do not build a new client per request or task
96+
- Configure the project token and host from environment variables via `ClientOptions` (the `(api_key, host)` tuple); never hardcode PostHog secrets
97+
- Because `capture` is fire-and-forget, always call `client.flush().await` and `client.shutdown().await` during graceful shutdown so queued events are delivered before exit
98+
- Server-side captures must set a stable `distinct_id` on `Event::new(event, distinct_id)` that matches frontend identify calls; avoid anonymous or literal IDs for business events
99+
- The SDK has no `identify` or `alias` helper; set person properties by inserting a `$set` property on an event
100+
- For feature flags, call `client.evaluate_flags(distinct_id, EvaluateFlagsOptions::default()).await` once per user/request, then read values from the returned snapshot with `is_enabled(...)`
101+
- For error tracking, use `client.capture_exception_with(&err, CaptureExceptionOptions::new()...)`; the `error-tracking` feature is enabled by default in recent versions
102+
- The Rust SDK has no surveys or session replay support; do not promise or scaffold those features
103+
93104
dotnet:
94105
- posthog-dotnet package names are `PostHog` for general .NET apps and `PostHog.AspNetCore` for ASP.NET Core apps
95106
- Use environment variables, user secrets, or configuration providers for `ProjectToken`, `HostUrl`, and `PersonalApiKey`; never hardcode PostHog secrets

context/skills/integration/config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,15 @@ variants:
244244
docs_urls:
245245
- https://posthog.com/docs/libraries/go.md
246246

247+
- id: rust
248+
framework: rust
249+
example_paths: example-apps/rust
250+
display_name: Rust
251+
description: PostHog integration for Rust applications using the posthog-rs SDK
252+
tags: [rust]
253+
docs_urls:
254+
- https://posthog.com/docs/libraries/rust.md
255+
247256
- id: swift
248257
framework: swift
249258
example_paths:

context/skip-patterns.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ global:
131131
- bin/
132132
- obj/
133133

134+
# Rust
135+
- target/
136+
134137
# PHP General
135138
- vendor
136139
- .phpunit.result.cache

example-apps/rust/.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copy this file to `.env` and fill in your values, then export them
2+
# (e.g. `export $(grep -v '^#' .env | xargs)`) before running the app.
3+
4+
# Your PostHog project token (from Project settings).
5+
POSTHOG_PROJECT_TOKEN=your_posthog_project_token
6+
7+
# PostHog host. Defaults to https://us.i.posthog.com when unset.
8+
POSTHOG_HOST=https://us.i.posthog.com

example-apps/rust/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
.env

0 commit comments

Comments
 (0)