pub struct RatePolicy { /* private fields */ }Expand description
Per-kind rate sampler with deterministic, paired-event-safe decisions.
Unspecified kinds default to default_rate (initially 1.0, i.e.
always sample). Configured kinds use the supplied rate in [0, 1],
clamped to that range. Rates outside the unit interval are treated
as the nearest valid value.
Sampling is computed by hashing the correlator with std::hash’s
default hasher and comparing the bottom 32 bits, scaled to [0, 1),
against the configured rate. Because event kind is deliberately not part
of the bucket hash, paired emissions (e.g. tool.invoked and
tool.completed sharing an internal call id) use the same bucket and are
either both kept or both dropped when configured with the same rate.
Implementations§
Source§impl RatePolicy
impl RatePolicy
Sourcepub fn new() -> Self
pub fn new() -> Self
Build a policy that keeps every event (default_rate = 1.0)
until rates are configured per-kind via with_rate.
Sourcepub fn with_default_rate(self, rate: f64) -> Self
pub fn with_default_rate(self, rate: f64) -> Self
Override the rate applied to event kinds that have no explicit entry. Useful when downsampling is the rule and full sampling is the exception.
Trait Implementations§
Source§impl Clone for RatePolicy
impl Clone for RatePolicy
Source§fn clone(&self) -> RatePolicy
fn clone(&self) -> RatePolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more