1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::api;
use rand::{rngs, Rng};
use std::cell::RefCell;
#[derive(Clone, Debug, Default)]
pub struct IdGenerator {
_private: (),
}
impl api::IdGenerator for IdGenerator {
fn new_trace_id(&self) -> api::TraceId {
CURRENT_RNG.with(|rng| api::TraceId::from_u128(rng.borrow_mut().gen()))
}
fn new_span_id(&self) -> api::SpanId {
CURRENT_RNG.with(|rng| api::SpanId::from_u64(rng.borrow_mut().gen()))
}
}
thread_local! {
static CURRENT_RNG: RefCell<rngs::ThreadRng> = RefCell::new(rngs::ThreadRng::default());
}