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