client
diapason.analytics.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.
AnalyticsClient
¶
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.
capture(event_name, properties=None)
¶
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.
flush()
¶
Force-flush queued events. Safe to call repeatedly.
shutdown()
¶
Flush and close the SDK. Call once on process exit.