client
client
¶
PostHog client wrapper.
A thin adapter over the official posthog SDK that:
- Initialises lazily and only if analytics is enabled.
- Pipes every capture through :mod:redaction and :mod:events for
PII stripping and structural validation.
- Fails silently — analytics must never break the host application.
The underlying SDK handles batching, async send on a background thread, retries, and silent failure on network errors. We layer "never crash the app" on top by wrapping every call in try/except.
Classes¶
AnalyticsClient
¶
AnalyticsClient(config: AnalyticsConfig, anon_id: str | None = None)
Send anonymized usage events to PostHog.
Construct once at server / CLI startup, share for the process
lifetime, call :meth:shutdown on exit to flush pending events.
Source code in src/openjarvis/analytics/client.py
Functions¶
capture
¶
Send one event. Unknown events are silently dropped.
Runs through redaction → event-spec validation → SDK capture. Failures at any stage are swallowed; analytics is best-effort.
Source code in src/openjarvis/analytics/client.py
flush
¶
shutdown
¶
Flush and close the SDK. Call once on process exit.