From da396a253853702d55dc5fdaefe34728a160fd24 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 2 Aug 2022 13:43:06 -0500 Subject: Add test for what happens when side by side spans in with statement --- tests/logging/test_tracing.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/logging/test_tracing.py') diff --git a/tests/logging/test_tracing.py b/tests/logging/test_tracing.py index d380c3b9ad..75b7745ab6 100644 --- a/tests/logging/test_tracing.py +++ b/tests/logging/test_tracing.py @@ -112,6 +112,24 @@ class TracingTestCase(TestCase): ["child_span2", "child_span1", "root_span"], ) + def test_side_by_side_spans(self) -> None: + with start_active_span( + "span1", tracer=self._tracer + ) as span1, start_active_span("span2", tracer=self._tracer) as span2: + # We expect the last span in `with` list to be active + self.assertEqual(opentelemetry.trace.get_current_span(), span2) + + # Active span is unset now that we're outside of the `with` scopes + self.assertEqual( + opentelemetry.trace.get_current_span(), opentelemetry.trace.INVALID_SPAN + ) + + # the spans should be reported in order of their finishing. + self.assertListEqual( + [span.name for span in self._exporter.get_finished_spans()], + ["span2", "span1"], + ) + def test_overlapping_spans(self) -> None: """Overlapping spans which are not neatly nested should work""" reactor = MemoryReactorClock() -- cgit 1.5.1