Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ def start_active_span(
:class:`ScopeManagerShim`.
"""

current_span = get_current_span()

if child_of is None and current_span is not INVALID_SPAN_CONTEXT:
child_of = SpanShim(None, None, current_span)

span = self.start_span(
operation_name=operation_name,
child_of=child_of,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ def test_extract_binary(self):
self.shim.extract(opentracing.Format.BINARY, bytearray())

def test_baggage(self):
"""Test SpanShim baggage being set and being immutable"""

span_context_shim = SpanContextShim(
trace.SpanContext(1234, 5678, is_remote=False)
Expand Down Expand Up @@ -592,3 +591,31 @@ def test_active(self):

# Verify no span is active.
self.assertIsNone(self.shim.active_span)

def test_mixed_mode(self):
"""Test that span parent-child relationship is kept between
OpenTelemetry and the OpenTracing shim"""

span_shim = self.shim.start_span("TestSpan16")

with self.shim.scope_manager.activate(span_shim, finish_on_close=True):

with (
TracerProvider()
.get_tracer(__name__)
.start_as_current_span("abc")
) as opentelemetry_span:

self.assertIs(
span_shim.unwrap().context, opentelemetry_span.parent,
)

with (
TracerProvider().get_tracer(__name__).start_as_current_span("abc")
) as opentelemetry_span:

with self.shim.start_active_span("TestSpan17") as scope:

self.assertIs(
scope.span.unwrap().parent, opentelemetry_span.context,
)