diff --git a/src/span_ext.rs b/src/span_ext.rs index a683521..94d96a9 100644 --- a/src/span_ext.rs +++ b/src/span_ext.rs @@ -143,7 +143,6 @@ impl OpenTelemetrySpanExt for tracing::Span { get_context.with_context(subscriber, id, move |data, _tracer| { if let Some(cx) = cx.take() { data.parent_cx = cx; - data.builder.trace_id = None; } }); } diff --git a/tests/trace_state_propagation.rs b/tests/trace_state_propagation.rs index 2ad209b..a020a74 100644 --- a/tests/trace_state_propagation.rs +++ b/tests/trace_state_propagation.rs @@ -63,6 +63,24 @@ fn trace_root_with_children() { assert_shared_attrs_eq(&spans[0].span_context, &spans[1].span_context); } +#[test] +fn propagate_invalid_context() { + let (_tracer, provider, exporter, subscriber) = test_tracer(); + let propagator = TraceContextPropagator::new(); + let invalid_cx = propagator.extract(&HashMap::new()); // empty context extracted + + tracing::subscriber::with_default(subscriber, || { + let root = tracing::debug_span!("root"); + root.set_parent(invalid_cx); + root.in_scope(|| tracing::debug_span!("child")); + }); + + drop(provider); // flush all spans + let spans = exporter.0.lock().unwrap(); + assert_eq!(spans.len(), 2); + assert_shared_attrs_eq(&spans[0].span_context, &spans[1].span_context); +} + #[test] fn inject_context_into_outgoing_requests() { let (_tracer, _provider, _exporter, subscriber) = test_tracer();