1- use rand:: Rng ;
21use std:: fmt;
32
43use crate :: headers:: { Header , HeaderName , HeaderValue , Headers , TRACEPARENT } ;
@@ -60,12 +59,10 @@ impl TraceContext {
6059 /// assert_eq!(context.sampled(), true);
6160 /// ```
6261 pub fn new ( ) -> Self {
63- let mut rng = rand:: thread_rng ( ) ;
64-
6562 Self {
66- id : rng . gen ( ) ,
63+ id : fastrand :: u64 ( .. ) ,
6764 version : 0 ,
68- trace_id : rng . gen ( ) ,
65+ trace_id : fastrand :: u128 ( .. ) ,
6966 parent_id : None ,
7067 flags : 1 ,
7168 }
@@ -104,7 +101,6 @@ impl TraceContext {
104101 /// ```
105102 pub fn from_headers ( headers : impl AsRef < Headers > ) -> crate :: Result < Option < Self > > {
106103 let headers = headers. as_ref ( ) ;
107- let mut rng = rand:: thread_rng ( ) ;
108104
109105 let traceparent = match headers. get ( TRACEPARENT ) {
110106 Some ( header) => header,
@@ -113,7 +109,7 @@ impl TraceContext {
113109 let parts: Vec < & str > = traceparent. as_str ( ) . split ( '-' ) . collect ( ) ;
114110
115111 Ok ( Some ( Self {
116- id : rng . gen ( ) ,
112+ id : fastrand :: u64 ( .. ) ,
117113 version : u8:: from_str_radix ( parts[ 0 ] , 16 ) ?,
118114 trace_id : u128:: from_str_radix ( parts[ 1 ] , 16 ) . status ( 400 ) ?,
119115 parent_id : Some ( u64:: from_str_radix ( parts[ 2 ] , 16 ) . status ( 400 ) ?) ,
@@ -126,10 +122,8 @@ impl TraceContext {
126122 /// The child will have a new randomly genrated `id` and its `parent_id` will be set to the
127123 /// `id` of this TraceContext.
128124 pub fn child ( & self ) -> Self {
129- let mut rng = rand:: thread_rng ( ) ;
130-
131125 Self {
132- id : rng . gen ( ) ,
126+ id : fastrand :: u64 ( .. ) ,
133127 version : self . version ,
134128 trace_id : self . trace_id ,
135129 parent_id : Some ( self . id ) ,
0 commit comments