Skip to main content

LogSampler

Struct LogSampler 

Source
pub struct LogSampler { /* private fields */ }
Expand description

A 1-in-N gate for high-volume log lines. Construct once per high-volume site (or share via Arc) and call LogSampler::should_emit at the log point:

use brainos_observe::LogSampler;

let sampler = LogSampler::one_in(100);
for i in 0..250 {
    if sampler.should_emit() {
        // ~1 in 100 of these run; the other 99 are skipped.
        let _ = i;
    }
}

Implementations§

Source§

impl LogSampler

Source

pub fn one_in(n: u32) -> Self

Emit 1 in n calls. n <= 1 disables sampling (every call emits).

Source

pub fn unsampled() -> Self

A sampler that emits on every call — the explicit “sampling off” form.

Source

pub fn should_emit(&self) -> bool

Whether this call should emit its log line. Returns true on the 1st call and every one_in_n-th call thereafter, so a freshly built sampler always logs its first occurrence (you never lose the first instance of a newly-hot site).

Source

pub fn rate(&self) -> u64

The configured rate (post-clamp); 1 means unsampled.

Trait Implementations§

Source§

impl Debug for LogSampler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.