You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
Copy file name to clipboardExpand all lines: context/commandments.yaml
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -90,6 +90,17 @@ commandments:
90
90
- Avoid deprecated feature flag helpers such as `IsFeatureEnabled`, `GetFeatureFlag`, `GetFeatureFlagPayload`, and `Capture.SendFeatureFlags` in new code
91
91
- For error tracking, use `posthog.NewDefaultException(...)` for direct captures or wrap `log/slog` with `posthog.NewSlogCaptureHandler(...)` for automatic warning-and-above exception capture
92
92
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
+
93
104
dotnet:
94
105
- posthog-dotnet package names are `PostHog` for general .NET apps and `PostHog.AspNetCore` for ASP.NET Core apps
95
106
- Use environment variables, user secrets, or configuration providers for `ProjectToken`, `HostUrl`, and `PersonalApiKey`; never hardcode PostHog secrets
0 commit comments