Skip to main content

Module PostHogPlugin

Module PostHogPlugin 

Source
Expand description

§PostHog Plugin

Debug-only PostHog analytics integration. Captures lifecycle events, IPC commands, and errors during dev runs; compile-time gated to cfg(debug_assertions) so release builds drop the entire stack.

Layout (one export per file, file name = identity):

  • Initialize::Fn - boot the global ingestion client.
  • CaptureEvent::Fn - generic event emitter with $app / $component standard props.
  • CaptureError::Fn - emit under land:mountain:error with tag + message.
  • CaptureIPC::Fn - emit under land:mountain:ipc:invoke with method name.
  • CaptureHandler::Fn - emit under land:mountain:handler:complete with feature + duration_ms + ok. Powers the Feature Parity dashboard’s Node-vs-Rust handler latency comparison.

Module-private helpers:

  • Constants - Authorize / Beam / Report / Brand baked from .env.Land.PostHog.
  • Client::CLIENT - OnceLock<posthog_rs::Client> singleton.
  • DistinctId::Fn - pinned-or-derived dev distinct id.
  • CaptureAllowed::Fn - debug_assertions && Report != off.

Modules§

CaptureAllowed 🔒
Capture gate. Combines the compile-time debug_assertions check with the master telemetry kill switch (Capture) and the per-pipe Report toggle, both baked at build time. Cheap early-exit consulted by every PostHog capture path.
CaptureError
Convenience wrapper that emits an error event under the land:mountain:error name with error_tag + error_message. The Errors & Reliability dashboard rolls these up alongside Cocoon / Sky errors via a single event LIKE 'land:%:error' clause.
CaptureEvent
Capture a named event with optional properties. Stamps the standard Mountain identity ($app, $app_version, $build_mode, $component) on every event before merging caller props.
CaptureHandler
Capture a land:mountain:handler:complete event for one IPC handler invocation. Feature is the Mountain-side route key (e.g. file:read, extensions:getInstalled); DurationMs measures the handler body only (Tauri-frame overhead excluded); Ok reports whether the handler returned Ok(_).
CaptureIPC
Convenience wrapper for IPC dispatch instrumentation. Emits land:mountain:ipc:invoke with the wire method name. Pair with CaptureHandler::Fn to also stamp land:mountain:handler:complete with duration_ms once the handler returns.
Client 🔒
Module-private singleton holding the PostHog ingestion client. Populated once by Initialize::Fn; every Capture*::Fn reads through this static.
Constants 🔒
Build-time PostHog credentials baked from .env.Land.PostHog via cargo:rustc-env. env! always resolves at compile time so even a clean checkout builds without a populated .env.
DistinctId 🔒
Machine-stable distinct ID for the dev session. When the Brand env var is populated, it wins - same value across every process in the same dev run. Otherwise falls back to land-dev-<USER>.
HydrateRuntimeEnvironment
Hydrate the running process’s environment from the compile-baked Constants so child processes spawned later (Cocoon Node, Sky webview) see the same telemetry config Mountain itself was built with - even when the user runs the bare binary without sourcing .env.Land.PostHog.
Initialize
Bring up the global PostHog client and emit land:mountain:session:start. Must be called once during boot; re-entrancy is safe because the underlying OnceLock::set returns Err on subsequent attempts.