tracing-prof 0.3.0

Experimental library for profiling tracing spans.
Documentation
//! Customization of sampling behavior.

use tracing_subscriber::registry::{LookupSpan, SpanRef};

#[cfg(feature = "sampler-probabilistic")]
pub mod probabilistic;

/// A trait that allows customizing which spans are sampled.
pub trait HeadSampler {
    /// Whether sampling is enabled.
    ///
    /// This serves as a compile-time optimization to
    /// skip sampling logic when not needed.
    const ENABLED: bool = true;

    /// Determines whether the span and its children should be sampled.
    fn should_sample<S>(&self, span: &SpanRef<S>) -> bool
    where
        S: for<'a> LookupSpan<'a>;
}

/// A default sampler that samples all spans.
#[derive(Debug, Clone, Copy)]
pub struct AlwaysSample;

impl HeadSampler for AlwaysSample {
    const ENABLED: bool = false;

    #[inline]
    fn should_sample<S>(&self, _span: &SpanRef<S>) -> bool
    where
        S: for<'a> LookupSpan<'a>,
    {
        true
    }
}