Skip to main content

TraceIdRatioSampler

Struct TraceIdRatioSampler 

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

基于 trace_id 比例的确定性采样器。

使用 trace_id 的哈希值与阈值比较,保证同一 trace_id 在所有节点上 做出相同的采样决策(无需共享状态)。

比例范围为 0.0..=1.0:

  • 0.0:不采样任何 trace
  • 1.0:采样所有 trace
  • 0.5:采样约 50% 的 trace

Implementations§

Source§

impl TraceIdRatioSampler

Source

pub fn new(ratio: f64) -> Self

创建比例采样器

§Panics

当 ratio 不在 [0.0, 1.0] 范围内时 panic。

Source

pub fn ratio(&self) -> f64

采样比例

Source

pub fn total_decisions(&self) -> u64

总采样决策次数

Source

pub fn sampled_count(&self) -> u64

被采样的次数

Source

pub fn actual_rate(&self) -> f64

实际采样率(sampled / total),总次数为 0 时返回 0.0

Trait Implementations§

Source§

impl Sampler for TraceIdRatioSampler

Source§

fn should_sample( &self, trace_id: &str, _parent_sampled: Option<bool>, ) -> SamplingDecision

做出采样决策 Read more
Source§

fn name(&self) -> &'static str

采样器名称(用于可观测性)

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.