File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
instrumentation/opentelemetry-instrumentation-opentracing-shim
src/opentelemetry/instrumentation/opentracing_shim Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -570,6 +570,11 @@ def start_active_span(
570
570
:class:`ScopeManagerShim`.
571
571
"""
572
572
573
+ current_span = get_current_span ()
574
+
575
+ if child_of is None and current_span is not INVALID_SPAN_CONTEXT :
576
+ child_of = SpanShim (None , None , current_span )
577
+
573
578
span = self .start_span (
574
579
operation_name = operation_name ,
575
580
child_of = child_of ,
Original file line number Diff line number Diff line change @@ -557,7 +557,6 @@ def test_extract_binary(self):
557
557
self .shim .extract (opentracing .Format .BINARY , bytearray ())
558
558
559
559
def test_baggage (self ):
560
- """Test SpanShim baggage being set and being immutable"""
561
560
562
561
span_context_shim = SpanContextShim (
563
562
trace .SpanContext (1234 , 5678 , is_remote = False )
@@ -592,3 +591,31 @@ def test_active(self):
592
591
593
592
# Verify no span is active.
594
593
self .assertIsNone (self .shim .active_span )
594
+
595
+ def test_mixed_mode (self ):
596
+ """Test that span parent-child relationship is kept between
597
+ OpenTelemetry and the OpenTracing shim"""
598
+
599
+ span_shim = self .shim .start_span ("TestSpan16" )
600
+
601
+ with self .shim .scope_manager .activate (span_shim , finish_on_close = True ):
602
+
603
+ with (
604
+ TracerProvider ()
605
+ .get_tracer (__name__ )
606
+ .start_as_current_span ("abc" )
607
+ ) as opentelemetry_span :
608
+
609
+ self .assertIs (
610
+ span_shim .unwrap ().context , opentelemetry_span .parent ,
611
+ )
612
+
613
+ with (
614
+ TracerProvider ().get_tracer (__name__ ).start_as_current_span ("abc" )
615
+ ) as opentelemetry_span :
616
+
617
+ with self .shim .start_active_span ("TestSpan17" ) as scope :
618
+
619
+ self .assertIs (
620
+ scope .span .unwrap ().parent , opentelemetry_span .context ,
621
+ )
You can’t perform that action at this time.
0 commit comments