File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed
Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -327,9 +327,19 @@ impl Context {
327327
328328impl fmt:: Debug for Context {
329329 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 ( )
333343 }
334344}
335345
Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ pub(crate) struct SynchronizedSpan {
3232 inner : Option < Mutex < global:: BoxedSpan > > ,
3333}
3434
35+ impl SynchronizedSpan {
36+ pub ( crate ) fn span_context ( & self ) -> & SpanContext {
37+ & self . span_context
38+ }
39+ }
40+
3541impl From < SpanContext > for SynchronizedSpan {
3642 fn from ( value : SpanContext ) -> Self {
3743 Self {
Original file line number Diff line number Diff line change @@ -544,6 +544,7 @@ impl SpanContext {
544544#[ cfg( test) ]
545545mod tests {
546546 use super :: * ;
547+ use crate :: { trace:: TraceContextExt , Context } ;
547548
548549 #[ rustfmt:: skip]
549550 fn trace_id_test_data ( ) -> Vec < ( TraceId , & ' static str , [ u8 ; 16 ] ) > {
@@ -647,4 +648,27 @@ mod tests {
647648 assert ! ( trace_state. get( "testkey" ) . is_none( ) ) ; // The original state doesn't change
648649 assert_eq ! ( inserted_trace_state. get( "testkey" ) . unwrap( ) , "testvalue" ) ; //
649650 }
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+ }
650674}
You can’t perform that action at this time.
0 commit comments