File tree 3 files changed +43
-3
lines changed
3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -327,9 +327,19 @@ impl Context {
327
327
328
328
impl fmt:: Debug for Context {
329
329
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
330
- f. debug_struct ( "Context" )
331
- . field ( "entries" , & self . entries . len ( ) )
332
- . finish ( )
330
+ let mut dbg = f. debug_struct ( "Context" ) ;
331
+ let mut entries = self . entries . len ( ) ;
332
+ #[ cfg( feature = "trace" ) ]
333
+ {
334
+ if let Some ( span) = & self . span {
335
+ dbg. field ( "span" , & span. span_context ( ) ) ;
336
+ entries += 1 ;
337
+ } else {
338
+ dbg. field ( "span" , & "None" ) ;
339
+ }
340
+ }
341
+
342
+ dbg. field ( "entries" , & entries) . finish ( )
333
343
}
334
344
}
335
345
Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ pub(crate) struct SynchronizedSpan {
32
32
inner : Option < Mutex < global:: BoxedSpan > > ,
33
33
}
34
34
35
+ impl SynchronizedSpan {
36
+ pub ( crate ) fn span_context ( & self ) -> & SpanContext {
37
+ & self . span_context
38
+ }
39
+ }
40
+
35
41
impl From < SpanContext > for SynchronizedSpan {
36
42
fn from ( value : SpanContext ) -> Self {
37
43
Self {
Original file line number Diff line number Diff line change @@ -544,6 +544,7 @@ impl SpanContext {
544
544
#[ cfg( test) ]
545
545
mod tests {
546
546
use super :: * ;
547
+ use crate :: { trace:: TraceContextExt , Context } ;
547
548
548
549
#[ rustfmt:: skip]
549
550
fn trace_id_test_data ( ) -> Vec < ( TraceId , & ' static str , [ u8 ; 16 ] ) > {
@@ -647,4 +648,27 @@ mod tests {
647
648
assert ! ( trace_state. get( "testkey" ) . is_none( ) ) ; // The original state doesn't change
648
649
assert_eq ! ( inserted_trace_state. get( "testkey" ) . unwrap( ) , "testvalue" ) ; //
649
650
}
651
+
652
+ #[ test]
653
+ fn test_context_span_debug ( ) {
654
+ let cx = Context :: current ( ) ;
655
+ assert_eq ! (
656
+ format!( "{:?}" , cx) ,
657
+ "Context { span: \" None\" , entries: 0 }"
658
+ ) ;
659
+ let cx = Context :: current ( ) . with_remote_span_context ( SpanContext :: NONE ) ;
660
+ assert_eq ! (
661
+ format!( "{:?}" , cx) ,
662
+ "Context { \
663
+ span: SpanContext { \
664
+ trace_id: 00000000000000000000000000000000, \
665
+ span_id: 0000000000000000, \
666
+ trace_flags: TraceFlags(0), \
667
+ is_remote: false, \
668
+ trace_state: TraceState(None) \
669
+ }, \
670
+ entries: 1 \
671
+ }"
672
+ ) ;
673
+ }
650
674
}
You can’t perform that action at this time.
0 commit comments