Skip to main content

CommonLibrary/Telemetry/
Configuration.rs

1#![allow(non_snake_case)]
2
3//! Runtime read of `.env.Land.PostHog`. Sidecars don't have their own
4//! `build.rs` env-bake (Mountain does, for compile-time tree-shake) -
5//! they read at boot via `std::env::var`. Mountain's `HydrateRuntime
6//! Environment::Fn` populates these into the spawned process's env so
7//! sidecars launched as Mountain children pick them up automatically.
8
9pub struct Configuration {
10	pub Key:String,
11	pub Host:String,
12	pub Brand:String,
13	pub Report:bool,
14	pub Capture:bool,
15	pub OTLPEndpoint:String,
16	pub OTLPEnabled:bool,
17}
18
19fn ReadString(Key:&str, Fallback:&str) -> String {
20	std::env::var(Key)
21		.ok()
22		.filter(|V| !V.is_empty())
23		.unwrap_or_else(|| Fallback.to_string())
24}
25
26fn ReadBool(Key:&str, Fallback:bool) -> bool {
27	match std::env::var(Key).ok().map(|V| V.to_lowercase()) {
28		Some(V) => !matches!(V.as_str(), "false" | "0" | "off"),
29		None => Fallback,
30	}
31}
32
33pub fn Fn() -> Configuration {
34	Configuration {
35		Key:ReadString("Authorize", ""),
36		Host:ReadString("Beam", "https://eu.i.posthog.com"),
37		Brand:ReadString("Brand", ""),
38		Report:ReadBool("Report", true),
39		Capture:ReadBool("Capture", true),
40		OTLPEndpoint:ReadString("OTLPEndpoint", "http://127.0.0.1:4318"),
41		OTLPEnabled:ReadBool("OTLPEnabled", true),
42	}
43}