Skip to content

Commit 560bb3a

Browse files
test(server): preserve tracing exporter isolation
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent 912071e commit 560bb3a

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎crates/openshell-server/src/otel_tracing.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ mod tests {
640640
// This is deliberately the child's last reference. Its parent has
641641
// no remaining references either, so both must close on this worker.
642642
drop(child);
643+
// Closing the carried span must also restore the worker's default,
644+
// so unrelated work cannot leak into this test's private exporter.
645+
drop(tracing::info_span!("unrelated_worker_span"));
643646
})
644647
.join()
645648
.expect("worker closes spans without consulting the global registry");
@@ -654,6 +657,37 @@ mod tests {
654657
);
655658
assert_eq!(parent_context.span().span_context(), &parent.span_context);
656659
assert_eq!(child_context.span().span_context(), &child.span_context);
660+
assert_eq!(traced.finished_spans().len(), 2);
661+
}
662+
663+
#[tokio::test]
664+
async fn tracing_exporters_isolate_unrelated_threads_and_successive_tests() {
665+
// Use the same callsite under all dispatchers to exercise the global
666+
// interest cache without sharing their captured spans.
667+
fn emit_span() {
668+
drop(tracing::info_span!("isolated_test_span"));
669+
}
670+
671+
let traced = test_exporter::install_traced();
672+
emit_span();
673+
std::thread::spawn(emit_span)
674+
.join()
675+
.expect("unrelated worker records only into the global registry");
676+
let first = traced.span_named("isolated_test_span");
677+
test_exporter::assert_is_root(&first);
678+
assert_eq!(traced.finished_spans().len(), 1);
679+
drop(traced);
680+
681+
let traced = test_exporter::install_traced();
682+
assert!(traced.finished_spans().is_empty());
683+
emit_span();
684+
let second = traced.span_named("isolated_test_span");
685+
test_exporter::assert_is_root(&second);
686+
assert_eq!(traced.finished_spans().len(), 1);
687+
assert_ne!(
688+
first.span_context.trace_id(),
689+
second.span_context.trace_id()
690+
);
657691
}
658692

659693
#[tokio::test]

0 commit comments

Comments
 (0)