CommonLibrary/Telemetry/IsAllowed.rs
1//! Compile-time + runtime gates. `cfg!(debug_assertions)` strips both
2//! pipes from release builds; `Capture` is the master kill, `Report` /
3//! `Emit` are per-pipe toggles. Cached after first read so the
4//! hot path is one atomic load.
5
6use std::sync::OnceLock;
7
8use crate::Telemetry::Configuration;
9
10static CACHED:OnceLock<Configuration::Configuration> = OnceLock::new();
11
12fn Get() -> &'static Configuration::Configuration { CACHED.get_or_init(Configuration::Fn) }
13
14pub fn PostHog() -> bool {
15 if !cfg!(debug_assertions) {
16 return false;
17 }
18
19 let C = Get();
20
21 C.Capture && C.Report && !C.Key.is_empty()
22}
23
24pub fn OTLP() -> bool {
25 if !cfg!(debug_assertions) {
26 return false;
27 }
28
29 let C = Get();
30
31 C.Capture && C.Emit
32}
33
34pub fn Cached() -> &'static Configuration::Configuration { Get() }