File tree 2 files changed +33
-0
lines changed
ext/opentelemetry-ext-opentracing-shim
src/opentelemetry/ext/opentracing_shim
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -568,6 +568,11 @@ def start_active_span(
568
568
:class:`ScopeManagerShim`.
569
569
"""
570
570
571
+ current_span = get_current_span ()
572
+
573
+ if child_of is None and current_span is not None :
574
+ child_of = SpanShim (None , None , current_span )
575
+
571
576
span = self .start_span (
572
577
operation_name = operation_name ,
573
578
child_of = child_of ,
Original file line number Diff line number Diff line change @@ -592,3 +592,31 @@ def test_active(self):
592
592
593
593
# Verify no span is active.
594
594
self .assertIsNone (self .shim .active_span )
595
+
596
+ def test_mixed_mode (self ):
597
+ """Test that span parent-child relationship is kept between
598
+ OpenTelemetry and the OpenTracing shim"""
599
+
600
+ span_shim = self .shim .start_span ("TestSpan16" )
601
+
602
+ with self .shim .scope_manager .activate (span_shim , finish_on_close = True ):
603
+
604
+ with (
605
+ TracerProvider ()
606
+ .get_tracer (__name__ )
607
+ .start_as_current_span ("abc" )
608
+ ) as opentelemetry_span :
609
+
610
+ self .assertIs (
611
+ span_shim .unwrap ().context , opentelemetry_span .parent ,
612
+ )
613
+
614
+ with (
615
+ TracerProvider ().get_tracer (__name__ ).start_as_current_span ("abc" )
616
+ ) as opentelemetry_span :
617
+
618
+ with self .shim .start_active_span ("TestSpan17" ) as scope :
619
+
620
+ self .assertIs (
621
+ scope .span .unwrap ().parent , opentelemetry_span .context ,
622
+ )
You can’t perform that action at this time.
0 commit comments