@@ -244,28 +244,28 @@ where
244244 // Visit fields.
245245 event. record ( & mut visitor) ;
246246
247- #[ cfg( feature = "experimental_use_tracing_span_context" ) ]
248- if let Some ( span) = _ctx. event_span ( event) {
249- use opentelemetry:: trace:: TraceContextExt ;
250- use tracing_opentelemetry:: OtelData ;
251- if let Some ( otd) = span. extensions ( ) . get :: < OtelData > ( ) {
252- if let Some ( span_id) = otd. builder . span_id {
253- let opt_trace_id = if otd. parent_cx . has_active_span ( ) {
254- Some ( otd. parent_cx . span ( ) . span_context ( ) . trace_id ( ) )
255- } else {
256- span. scope ( ) . last ( ) . and_then ( |root_span| {
257- root_span
258- . extensions ( )
259- . get :: < OtelData > ( )
260- . and_then ( |otd| otd. builder . trace_id )
261- } )
262- } ;
263- if let Some ( trace_id) = opt_trace_id {
264- log_record. set_trace_context ( trace_id, span_id, None ) ;
265- }
266- }
267- }
268- }
247+ // #[cfg(feature = "experimental_use_tracing_span_context")]
248+ // if let Some(span) = _ctx.event_span(event) {
249+ // use opentelemetry::trace::TraceContextExt;
250+ // use tracing_opentelemetry::OtelData;
251+ // if let Some(otd) = span.extensions().get::<OtelData>() {
252+ // if let Some(span_id) = otd.builder.span_id {
253+ // let opt_trace_id = if otd.parent_cx.has_active_span() {
254+ // Some(otd.parent_cx.span().span_context().trace_id())
255+ // } else {
256+ // span.scope().last().and_then(|root_span| {
257+ // root_span
258+ // .extensions()
259+ // .get::<OtelData>()
260+ // .and_then(|otd| otd.builder.trace_id)
261+ // })
262+ // };
263+ // if let Some(trace_id) = opt_trace_id {
264+ // log_record.set_trace_context(trace_id, span_id, None);
265+ // }
266+ // }
267+ // }
268+ // }
269269
270270 //emit record
271271 self . logger . emit ( log_record) ;
@@ -611,117 +611,117 @@ mod tests {
611611 }
612612 }
613613
614- #[ cfg( feature = "experimental_use_tracing_span_context" ) ]
615- #[ test]
616- fn tracing_appender_inside_tracing_crate_context ( ) {
617- use opentelemetry:: { trace:: SpanContext , Context , SpanId , TraceId } ;
618- use opentelemetry_sdk:: trace:: InMemorySpanExporterBuilder ;
619- use tracing_opentelemetry:: OpenTelemetrySpanExt ;
620-
621- // Arrange
622- let exporter: InMemoryLogExporter = InMemoryLogExporter :: default ( ) ;
623- let logger_provider = SdkLoggerProvider :: builder ( )
624- . with_simple_exporter ( exporter. clone ( ) )
625- . build ( ) ;
626-
627- // setup tracing layer to compare trace/span IDs against
628- let span_exporter = InMemorySpanExporterBuilder :: new ( ) . build ( ) ;
629- let tracer_provider = SdkTracerProvider :: builder ( )
630- . with_simple_exporter ( span_exporter. clone ( ) )
631- . build ( ) ;
632- let tracer = tracer_provider. tracer ( "test-tracer" ) ;
633-
634- let level_filter = tracing_subscriber:: filter:: LevelFilter :: ERROR ;
635- let log_layer =
636- layer:: OpenTelemetryTracingBridge :: new ( & logger_provider) . with_filter ( level_filter) ;
637-
638- let subscriber = tracing_subscriber:: registry ( )
639- . with ( log_layer)
640- . with ( tracing_opentelemetry:: layer ( ) . with_tracer ( tracer) ) ;
641-
642- // Avoiding global subscriber.init() as that does not play well with unit tests.
643- let _guard = tracing:: subscriber:: set_default ( subscriber) ;
644-
645- // Act
646- tracing:: error_span!( "outer-span" ) . in_scope ( || {
647- error ! ( "first-event" ) ;
648-
649- tracing:: error_span!( "inner-span" ) . in_scope ( || {
650- error ! ( "second-event" ) ;
651- } ) ;
652- } ) ;
653-
654- assert ! ( logger_provider. force_flush( ) . is_ok( ) ) ;
655-
656- let logs = exporter. get_emitted_logs ( ) . expect ( "No emitted logs" ) ;
657- assert_eq ! ( logs. len( ) , 2 , "Expected 2 logs, got: {logs:?}" ) ;
658-
659- let spans = span_exporter. get_finished_spans ( ) . unwrap ( ) ;
660- assert_eq ! ( spans. len( ) , 2 ) ;
661-
662- let trace_id = spans[ 0 ] . span_context . trace_id ( ) ;
663- assert_eq ! ( trace_id, spans[ 1 ] . span_context. trace_id( ) ) ;
664- let inner_span_id = spans[ 0 ] . span_context . span_id ( ) ;
665- let outer_span_id = spans[ 1 ] . span_context . span_id ( ) ;
666- assert_eq ! ( outer_span_id, spans[ 0 ] . parent_span_id) ;
667-
668- let trace_ctx0 = logs[ 0 ] . record . trace_context ( ) . unwrap ( ) ;
669- let trace_ctx1 = logs[ 1 ] . record . trace_context ( ) . unwrap ( ) ;
670-
671- assert_eq ! ( trace_ctx0. trace_id, trace_id) ;
672- assert_eq ! ( trace_ctx1. trace_id, trace_id) ;
673- assert_eq ! ( trace_ctx0. span_id, outer_span_id) ;
674- assert_eq ! ( trace_ctx1. span_id, inner_span_id) ;
675-
676- // Set context from remote.
677- let remote_trace_id = TraceId :: from_u128 ( 233 ) ;
678- let remote_span_id = SpanId :: from_u64 ( 2333 ) ;
679- let remote_span_context = SpanContext :: new (
680- remote_trace_id,
681- remote_span_id,
682- TraceFlags :: SAMPLED ,
683- true ,
684- Default :: default ( ) ,
685- ) ;
686-
687- // Act again.
688- tracing:: error_span!( "outer-span" ) . in_scope ( || {
689- let span = tracing:: Span :: current ( ) ;
690- let parent_context = Context :: current ( ) . with_remote_span_context ( remote_span_context) ;
691- span. set_parent ( parent_context) ;
692-
693- error ! ( "first-event" ) ;
694-
695- tracing:: error_span!( "inner-span" ) . in_scope ( || {
696- error ! ( "second-event" ) ;
697- } ) ;
698- } ) ;
699-
700- assert ! ( logger_provider. force_flush( ) . is_ok( ) ) ;
701-
702- let logs = exporter. get_emitted_logs ( ) . expect ( "No emitted logs" ) ;
703- assert_eq ! ( logs. len( ) , 4 , "Expected 4 logs, got: {logs:?}" ) ;
704- let logs = & logs[ 2 ..] ;
705-
706- let spans = span_exporter. get_finished_spans ( ) . unwrap ( ) ;
707- assert_eq ! ( spans. len( ) , 4 ) ;
708- let spans = & spans[ 2 ..] ;
709-
710- let trace_id = spans[ 0 ] . span_context . trace_id ( ) ;
711- assert_eq ! ( trace_id, remote_trace_id) ;
712- assert_eq ! ( trace_id, spans[ 1 ] . span_context. trace_id( ) ) ;
713- let inner_span_id = spans[ 0 ] . span_context . span_id ( ) ;
714- let outer_span_id = spans[ 1 ] . span_context . span_id ( ) ;
715- assert_eq ! ( outer_span_id, spans[ 0 ] . parent_span_id) ;
716-
717- let trace_ctx0 = logs[ 0 ] . record . trace_context ( ) . unwrap ( ) ;
718- let trace_ctx1 = logs[ 1 ] . record . trace_context ( ) . unwrap ( ) ;
719-
720- assert_eq ! ( trace_ctx0. trace_id, trace_id) ;
721- assert_eq ! ( trace_ctx1. trace_id, trace_id) ;
722- assert_eq ! ( trace_ctx0. span_id, outer_span_id) ;
723- assert_eq ! ( trace_ctx1. span_id, inner_span_id) ;
724- }
614+ // #[cfg(feature = "experimental_use_tracing_span_context")]
615+ // #[test]
616+ // fn tracing_appender_inside_tracing_crate_context() {
617+ // use opentelemetry::{trace::SpanContext, Context, SpanId, TraceId};
618+ // use opentelemetry_sdk::trace::InMemorySpanExporterBuilder;
619+ // use tracing_opentelemetry::OpenTelemetrySpanExt;
620+
621+ // // Arrange
622+ // let exporter: InMemoryLogExporter = InMemoryLogExporter::default();
623+ // let logger_provider = SdkLoggerProvider::builder()
624+ // .with_simple_exporter(exporter.clone())
625+ // .build();
626+
627+ // // setup tracing layer to compare trace/span IDs against
628+ // let span_exporter = InMemorySpanExporterBuilder::new().build();
629+ // let tracer_provider = SdkTracerProvider::builder()
630+ // .with_simple_exporter(span_exporter.clone())
631+ // .build();
632+ // let tracer = tracer_provider.tracer("test-tracer");
633+
634+ // let level_filter = tracing_subscriber::filter::LevelFilter::ERROR;
635+ // let log_layer =
636+ // layer::OpenTelemetryTracingBridge::new(&logger_provider).with_filter(level_filter);
637+
638+ // let subscriber = tracing_subscriber::registry()
639+ // .with(log_layer)
640+ // .with(tracing_opentelemetry::layer().with_tracer(tracer));
641+
642+ // // Avoiding global subscriber.init() as that does not play well with unit tests.
643+ // let _guard = tracing::subscriber::set_default(subscriber);
644+
645+ // // Act
646+ // tracing::error_span!("outer-span").in_scope(|| {
647+ // error!("first-event");
648+
649+ // tracing::error_span!("inner-span").in_scope(|| {
650+ // error!("second-event");
651+ // });
652+ // });
653+
654+ // assert!(logger_provider.force_flush().is_ok());
655+
656+ // let logs = exporter.get_emitted_logs().expect("No emitted logs");
657+ // assert_eq!(logs.len(), 2, "Expected 2 logs, got: {logs:?}");
658+
659+ // let spans = span_exporter.get_finished_spans().unwrap();
660+ // assert_eq!(spans.len(), 2);
661+
662+ // let trace_id = spans[0].span_context.trace_id();
663+ // assert_eq!(trace_id, spans[1].span_context.trace_id());
664+ // let inner_span_id = spans[0].span_context.span_id();
665+ // let outer_span_id = spans[1].span_context.span_id();
666+ // assert_eq!(outer_span_id, spans[0].parent_span_id);
667+
668+ // let trace_ctx0 = logs[0].record.trace_context().unwrap();
669+ // let trace_ctx1 = logs[1].record.trace_context().unwrap();
670+
671+ // assert_eq!(trace_ctx0.trace_id, trace_id);
672+ // assert_eq!(trace_ctx1.trace_id, trace_id);
673+ // assert_eq!(trace_ctx0.span_id, outer_span_id);
674+ // assert_eq!(trace_ctx1.span_id, inner_span_id);
675+
676+ // // Set context from remote.
677+ // let remote_trace_id = TraceId::from_u128(233);
678+ // let remote_span_id = SpanId::from_u64(2333);
679+ // let remote_span_context = SpanContext::new(
680+ // remote_trace_id,
681+ // remote_span_id,
682+ // TraceFlags::SAMPLED,
683+ // true,
684+ // Default::default(),
685+ // );
686+
687+ // // Act again.
688+ // tracing::error_span!("outer-span").in_scope(|| {
689+ // let span = tracing::Span::current();
690+ // let parent_context = Context::current().with_remote_span_context(remote_span_context);
691+ // span.set_parent(parent_context);
692+
693+ // error!("first-event");
694+
695+ // tracing::error_span!("inner-span").in_scope(|| {
696+ // error!("second-event");
697+ // });
698+ // });
699+
700+ // assert!(logger_provider.force_flush().is_ok());
701+
702+ // let logs = exporter.get_emitted_logs().expect("No emitted logs");
703+ // assert_eq!(logs.len(), 4, "Expected 4 logs, got: {logs:?}");
704+ // let logs = &logs[2..];
705+
706+ // let spans = span_exporter.get_finished_spans().unwrap();
707+ // assert_eq!(spans.len(), 4);
708+ // let spans = &spans[2..];
709+
710+ // let trace_id = spans[0].span_context.trace_id();
711+ // assert_eq!(trace_id, remote_trace_id);
712+ // assert_eq!(trace_id, spans[1].span_context.trace_id());
713+ // let inner_span_id = spans[0].span_context.span_id();
714+ // let outer_span_id = spans[1].span_context.span_id();
715+ // assert_eq!(outer_span_id, spans[0].parent_span_id);
716+
717+ // let trace_ctx0 = logs[0].record.trace_context().unwrap();
718+ // let trace_ctx1 = logs[1].record.trace_context().unwrap();
719+
720+ // assert_eq!(trace_ctx0.trace_id, trace_id);
721+ // assert_eq!(trace_ctx1.trace_id, trace_id);
722+ // assert_eq!(trace_ctx0.span_id, outer_span_id);
723+ // assert_eq!(trace_ctx1.span_id, inner_span_id);
724+ // }
725725
726726 #[ test]
727727 fn tracing_appender_standalone_with_tracing_log ( ) {
0 commit comments