opentelemetry_spanprocessor_any/sdk/trace/id_generator/
mod.rs1pub(super) mod aws;
3
4use crate::trace::{SpanId, TraceId};
5use rand::{rngs, Rng};
6use std::cell::RefCell;
7
8#[derive(Clone, Debug, Default)]
11pub struct IdGenerator {
12 _private: (),
13}
14
15impl crate::trace::IdGenerator for IdGenerator {
16 fn new_trace_id(&self) -> TraceId {
18 CURRENT_RNG.with(|rng| TraceId::from(rng.borrow_mut().gen::<[u8; 16]>()))
19 }
20
21 fn new_span_id(&self) -> SpanId {
23 CURRENT_RNG.with(|rng| SpanId::from(rng.borrow_mut().gen::<[u8; 8]>()))
24 }
25}
26
27thread_local! {
28 static CURRENT_RNG: RefCell<rngs::ThreadRng> = RefCell::new(rngs::ThreadRng::default());
30}