Skip to main content

CommonLibrary/Telemetry/
Configuration.rs

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