Skip to main content

Module Telemetry

Module Telemetry 

Source
Expand description

§Telemetry - shared dual-pipe (PostHog + OTLP) for every Rust Element

Single source of truth for the sidecar telemetry surface. Mountain keeps its own compile-time-baked Binary/Build/PostHogPlugin/* (the build.rs cargo:rustc-env route guarantees release builds drop every byte). All other Rust elements (Air, Echo, Rest, Grove, Mist, SideCar) read configuration at runtime through this module:

use CommonLibrary::Telemetry::{Initialize, Tier};
Initialize::Fn(Tier::Air);   // call once during boot

All capture functions are no-ops in release builds (cfg!(debug_assertions)) and short-circuit on Capture=false / per-pipe toggles at runtime.

§Layout (one export per file)

  • Tier::Tier - enum identifying the calling sidecar
  • Configuration::Fn - runtime env read
  • IsAllowed::PostHog, IsAllowed::OTLP - gates
  • Client::CLIENT - OnceLock<posthog_rs::Client>
  • DistinctId::Fn - stable per-machine identity
  • CaptureEvent::Fn, CaptureError::Fn, CaptureSession::Fn - PostHog
  • EmitOTLPSpan::Fn - raw HTTP OTLP exporter
  • Initialize::Fn - Tier-tagged boot

Modules§

CaptureError
Emit land:<tier>:error with error_tag + error_message. The Errors & Reliability dashboard rolls these up across Mountain / Cocoon / Sky / sidecars via event LIKE 'land:%:error'.
CaptureEvent
Emit a named PostHog event. Stamps the calling Tier plus the standard Land identity ($app, $app_version, $build_mode, $component, $tier) so dashboards can pivot by tier without caller changes.
CaptureSession
Emit land:<tier>:session:start with pid / OS / arch. Called once by Initialize::Fn so the Boot & Startup Performance dashboard sees one start event per sidecar process.
Client
Process-wide PostHog client singleton. Populated once by Initialize::Fn; every Capture*::Fn reads through this static. Sidecars share one client per process, like Mountain’s Binary/Build/PostHogPlugin/Client.
Configuration
Runtime read of .env.Land.PostHog. Sidecars don’t have their own build.rs env-bake (Mountain does, for compile-time tree-shake) - they read at boot via std::env::var. Mountain’s HydrateRuntime Environment::Fn populates these into the spawned process’s env so sidecars launched as Mountain children pick them up automatically.
DistinctId
Stable distinct ID for the dev session. Mirrors Mountain’s Binary/Build/PostHogPlugin/DistinctId so a single dev run merges into one PostHog person across every sidecar.
EmitOTLPSpan
Fire-and-forget OTLP span exporter. Lifted from Mountain’s IPC/DevLog/EmitOTLPSpan so Air / Echo / Rest / Grove / Mist / SideCar all share the same raw HTTP path. Single failed POST flips OTLP_AVAILABLE to false so a missing collector doesn’t tax every emit. Release builds compile out via cfg!(debug_assertions).
Initialize
Sidecar boot. Idempotent: subsequent calls are no-ops because OnceLock::set returns Err. Pass the Tier so every emitted event is tagged correctly without per-call boilerplate.
IsAllowed
Compile-time + runtime gates. cfg!(debug_assertions) strips both pipes from release builds; Capture is the master kill, Report / OTLPEnabled are per-pipe toggles. Cached after first read so the hot path is one atomic load.
Tier
Identifier for the calling Element. Tags every emitted event so the Errors & Reliability dashboard can pivot by $tier.
Traceparent
W3C traceparent header builder + parser. Used by every emit / RPC site that crosses a tier boundary (Mountain → Sky tauri events, Mountain → Cocoon gRPC, Sky → Mountain TauriInvoke, Cocoon → Mountain gRPC). The format is the standard version-traceid-parentid-flags from https://www.w3.org/TR/trace-context/.