@@ -66,13 +66,14 @@ pub struct SpanId(u64);
6666/// dependencies. On the other hand, if an upstream process has chosen to sample this trace, then
6767/// the downstream samplers are expected to respect that decision and also sample the trace.
6868/// Otherwise, the full trace would not be able to be reconstructed reliably.
69- #[ derive( Debug , PartialEq , Eq , Hash , Clone , Copy ) ]
69+ #[ derive( Debug , PartialEq , Eq , Hash , Clone , Copy , Default ) ]
7070#[ cfg_attr( feature = "serde1" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
7171#[ repr( u8 ) ]
7272pub enum SamplingDecision {
7373 /// The associated span was sampled by its creating process. Child spans must also be sampled.
7474 Sampled ,
7575 /// The associated span was not sampled by its creating process.
76+ #[ default]
7677 Unsampled ,
7778}
7879
@@ -81,7 +82,7 @@ impl Context {
8182 pub ( crate ) fn new_child ( & self ) -> Self {
8283 Self {
8384 trace_id : self . trace_id ,
84- span_id : SpanId :: random ( & mut rand:: thread_rng ( ) ) ,
85+ span_id : SpanId :: random ( & mut rand:: rng ( ) ) ,
8586 sampling_decision : self . sampling_decision ,
8687 }
8788 }
@@ -91,7 +92,7 @@ impl TraceId {
9192 /// Returns a random trace ID that can be assumed to be globally unique if `rng` generates
9293 /// actually-random numbers.
9394 pub fn random < R : Rng > ( rng : & mut R ) -> Self {
94- TraceId ( rng. r#gen :: < NonZeroU128 > ( ) . get ( ) )
95+ TraceId ( rng. random :: < NonZeroU128 > ( ) . get ( ) )
9596 }
9697
9798 /// Returns true iff the trace ID is 0.
@@ -103,7 +104,7 @@ impl TraceId {
103104impl SpanId {
104105 /// Returns a random span ID that can be assumed to be unique within a single trace.
105106 pub fn random < R : Rng > ( rng : & mut R ) -> Self {
106- SpanId ( rng. r#gen :: < NonZeroU64 > ( ) . get ( ) )
107+ SpanId ( rng. random :: < NonZeroU64 > ( ) . get ( ) )
107108 }
108109
109110 /// Returns true iff the span ID is 0.
@@ -203,12 +204,6 @@ impl From<&opentelemetry::trace::SpanContext> for SamplingDecision {
203204 }
204205}
205206
206- impl Default for SamplingDecision {
207- fn default ( ) -> Self {
208- Self :: Unsampled
209- }
210- }
211-
212207/// Returned when a [`Context`] cannot be constructed from a [`Span`](tracing::Span).
213208#[ derive( Debug ) ]
214209pub struct NoActiveSpan ;
0 commit comments