Skip to main content

CommonLibrary/Telemetry/
IsAllowed.rs

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