Skip to main content

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
21	let C = Get();
22
23	C.Capture && C.Report && !C.Key.is_empty()
24}
25
26pub fn OTLP() -> bool {
27	if !cfg!(debug_assertions) {
28		return false;
29	}
30
31	let C = Get();
32
33	C.Capture && C.OTLPEnabled
34}
35
36pub fn Cached() -> &'static Configuration::Configuration { Get() }