pub struct ChancePredicate<P: EnabledPredicate> { /* private fields */ }Expand description
Predicate wrapper that probabilistically denies root spans before
they get to the inner predicate. Root spans (the ones whose
Attributes carry tracing::span::Attributes::is_root() —
typically tracing::span!(parent: None, …)) are gated by a
runtime-tunable percentage; descendants and events pass straight
through to the inner predicate.
Because the chance is read with a Relaxed load of an
AtomicU64 holding f64::to_bits of the percentage, updates
from a ChanceHandle are picked up by the next root-span
roll without needing a wake — the inner subscriber’s existing
rebuild_interest_cache invalidation isn’t required either,
since the dice are rerolled per span instance via
EnabledPredicate::new_span_enabled, not at
callsite-registration time.
Implementations§
Source§impl<P: EnabledPredicate> ChancePredicate<P>
impl<P: EnabledPredicate> ChancePredicate<P>
Sourcepub fn new(inner: P, chance_pct: f64) -> Self
pub fn new(inner: P, chance_pct: f64) -> Self
Construct with an initial chance percentage [0.0, 100.0].
Out-of-range inputs are silently clamped. Use 100.0 for
“always pass to inner”.
Sourcepub fn handle(&self) -> ChanceHandle
pub fn handle(&self) -> ChanceHandle
Cheap-to-clone handle for changing the chance percentage at runtime — typically held by an admin RPC.