@@ -20,6 +20,7 @@ use std::{
2020 fmt:: Debug ,
2121 sync:: { Arc , Mutex } ,
2222} ;
23+ use tracing:: { trace, warn} ;
2324
2425/// Mock Tracing Provider - used for testing distributed tracing without involving a specific tracing implementation.
2526#[ derive( Debug ) ]
@@ -132,9 +133,9 @@ impl MockSpanInner {
132133 where
133134 C : Into < Cow < ' static , str > > + Debug ,
134135 {
135- eprintln ! ( "Creating MockSpan: {:?}" , name) ;
136+ trace ! ( "Creating MockSpan: {:?}" , name) ;
136137
137- eprintln ! ( "Attributes: {:?}" , attributes) ;
138+ trace ! ( "Attributes: {:?}" , attributes) ;
138139 let id = rng ( ) . random ( ) ;
139140
140141 let parent = parent. map ( |p| p. span_id ( ) ) ;
@@ -165,7 +166,7 @@ impl AsAny for MockSpanInner {
165166
166167impl Span for MockSpanInner {
167168 fn set_attribute ( & self , key : & ' static str , value : AttributeValue ) {
168- eprintln ! ( "{}: Setting attribute {}: {:?}" , self . name, key, value) ;
169+ trace ! ( "{}: Setting attribute {}: {:?}" , self . name, key, value) ;
169170 let mut attributes = self . attributes . lock ( ) . unwrap ( ) ;
170171 attributes. push ( Attribute {
171172 key : key. into ( ) ,
@@ -174,13 +175,13 @@ impl Span for MockSpanInner {
174175 }
175176
176177 fn set_status ( & self , status : crate :: tracing:: SpanStatus ) {
177- eprintln ! ( "{}: Setting span status: {:?}" , self . name, status) ;
178+ trace ! ( "{}: Setting span status: {:?}" , self . name, status) ;
178179 let mut state = self . state . lock ( ) . unwrap ( ) ;
179180 * state = status;
180181 }
181182
182183 fn end ( & self ) {
183- eprintln ! ( "Ending span: {}" , self . name) ;
184+ trace ! ( "Ending span: {}" , self . name) ;
184185 let mut is_open = self . is_open . lock ( ) . unwrap ( ) ;
185186 * is_open = false ;
186187 }
@@ -219,7 +220,7 @@ pub struct MockSpan {
219220impl Drop for MockSpan {
220221 fn drop ( & mut self ) {
221222 if self . inner . is_open ( ) {
222- eprintln ! ( "Warning: Dropping open span: {}" , self . inner. name) ;
223+ warn ! ( "Dropping open span: {}" , self . inner. name) ;
223224 self . inner . end ( ) ;
224225 }
225226 }
@@ -297,8 +298,8 @@ pub fn check_instrumentation_result(
297298) {
298299 let tracers = mock_tracer. tracers . lock ( ) . unwrap ( ) ;
299300 if tracers. len ( ) != expected_tracers. len ( ) {
300- eprintln ! ( "Expected tracers: {:?}" , expected_tracers) ;
301- eprintln ! ( "Found tracers: {:?}" , tracers) ;
301+ trace ! ( "Expected tracers: {:?}" , expected_tracers) ;
302+ trace ! ( "Found tracers: {:?}" , tracers) ;
302303 }
303304 assert_eq ! (
304305 tracers. len( ) ,
@@ -308,7 +309,7 @@ pub fn check_instrumentation_result(
308309 tracers. len( )
309310 ) ;
310311 for ( index, expected) in expected_tracers. iter ( ) . enumerate ( ) {
311- eprintln ! ( "Checking tracer {}: {}" , index, expected. name) ;
312+ trace ! ( "Checking tracer {}: {}" , index, expected. name) ;
312313 let tracer = & tracers[ index] ;
313314 let mut parent_span_map = HashMap :: new ( ) ;
314315 assert_eq ! ( tracer. package_name, expected. name) ;
@@ -329,9 +330,11 @@ pub fn check_instrumentation_result(
329330
330331 let mut expected_index = 0 ;
331332 for ( span_index, span_actual) in spans. iter ( ) . enumerate ( ) {
332- eprintln ! (
333+ trace ! (
333334 "Checking span {} of tracer {}: {}" ,
334- span_index, expected. name, span_actual. name
335+ span_index,
336+ expected. name,
337+ span_actual. name
335338 ) ;
336339 check_span_information (
337340 span_actual,
@@ -342,7 +345,7 @@ pub fn check_instrumentation_result(
342345 parent_span_map. insert ( expected. spans [ expected_index] . span_id , span_actual. id ) ;
343346 if expected. spans [ expected_index] . is_wildcard {
344347 // If this is a wildcard span, we don't increment the expected index.
345- eprintln ! (
348+ trace ! (
346349 "Span {} is a wildcard, not incrementing expected index" ,
347350 span_actual. name
348351 ) ;
@@ -353,7 +356,7 @@ pub fn check_instrumentation_result(
353356 & expected. spans [ expected_index] ,
354357 & parent_span_map,
355358 ) {
356- eprintln ! (
359+ trace ! (
357360 "Next actual span does not match expected span: {}" ,
358361 expected. spans[ expected_index] . span_name
359362 ) ;
@@ -432,10 +435,10 @@ fn check_span_information(
432435 }
433436 }
434437 let attributes = span. attributes . lock ( ) . unwrap ( ) ;
435- eprintln ! ( "Expected attributes: {:?}" , expected. attributes) ;
436- eprintln ! ( "Found attributes: {:?}" , attributes) ;
438+ trace ! ( "Expected attributes: {:?}" , expected. attributes) ;
439+ trace ! ( "Found attributes: {:?}" , attributes) ;
437440 for ( index, attr) in attributes. iter ( ) . enumerate ( ) {
438- eprintln ! ( "Attribute {}: {} = {:?}" , index, attr. key, attr. value) ;
441+ trace ! ( "Attribute {}: {} = {:?}" , index, attr. key, attr. value) ;
439442 let mut found = false ;
440443 for ( key, value) in & expected. attributes {
441444 if attr. key == * key {
@@ -495,10 +498,10 @@ fn compare_span_information(
495498 }
496499 }
497500 let attributes = actual. attributes . lock ( ) . unwrap ( ) ;
498- eprintln ! ( "Expected attributes: {:?}" , expected. attributes) ;
499- eprintln ! ( "Found attributes: {:?}" , attributes) ;
501+ trace ! ( "Expected attributes: {:?}" , expected. attributes) ;
502+ trace ! ( "Found attributes: {:?}" , attributes) ;
500503 for ( index, attr) in attributes. iter ( ) . enumerate ( ) {
501- eprintln ! ( "Attribute {}: {} = {:?}" , index, attr. key, attr. value) ;
504+ trace ! ( "Attribute {}: {} = {:?}" , index, attr. key, attr. value) ;
502505 let mut found = false ;
503506 for ( key, value) in & expected. attributes {
504507 if attr. key == * key {
0 commit comments