1
- use rand:: Rng ;
2
1
use std:: fmt;
3
2
4
3
use crate :: headers:: { Header , HeaderName , HeaderValue , Headers , TRACEPARENT } ;
@@ -60,12 +59,10 @@ impl TraceContext {
60
59
/// assert_eq!(context.sampled(), true);
61
60
/// ```
62
61
pub fn new ( ) -> Self {
63
- let mut rng = rand:: thread_rng ( ) ;
64
-
65
62
Self {
66
- id : rng . gen ( ) ,
63
+ id : fastrand :: u64 ( .. ) ,
67
64
version : 0 ,
68
- trace_id : rng . gen ( ) ,
65
+ trace_id : fastrand :: u128 ( .. ) ,
69
66
parent_id : None ,
70
67
flags : 1 ,
71
68
}
@@ -104,7 +101,6 @@ impl TraceContext {
104
101
/// ```
105
102
pub fn from_headers ( headers : impl AsRef < Headers > ) -> crate :: Result < Option < Self > > {
106
103
let headers = headers. as_ref ( ) ;
107
- let mut rng = rand:: thread_rng ( ) ;
108
104
109
105
let traceparent = match headers. get ( TRACEPARENT ) {
110
106
Some ( header) => header,
@@ -113,7 +109,7 @@ impl TraceContext {
113
109
let parts: Vec < & str > = traceparent. as_str ( ) . split ( '-' ) . collect ( ) ;
114
110
115
111
Ok ( Some ( Self {
116
- id : rng . gen ( ) ,
112
+ id : fastrand :: u64 ( .. ) ,
117
113
version : u8:: from_str_radix ( parts[ 0 ] , 16 ) ?,
118
114
trace_id : u128:: from_str_radix ( parts[ 1 ] , 16 ) . status ( 400 ) ?,
119
115
parent_id : Some ( u64:: from_str_radix ( parts[ 2 ] , 16 ) . status ( 400 ) ?) ,
@@ -126,10 +122,8 @@ impl TraceContext {
126
122
/// The child will have a new randomly genrated `id` and its `parent_id` will be set to the
127
123
/// `id` of this TraceContext.
128
124
pub fn child ( & self ) -> Self {
129
- let mut rng = rand:: thread_rng ( ) ;
130
-
131
125
Self {
132
- id : rng . gen ( ) ,
126
+ id : fastrand :: u64 ( .. ) ,
133
127
version : self . version ,
134
128
trace_id : self . trace_id ,
135
129
parent_id : Some ( self . id ) ,
0 commit comments