Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jul 22, 2020
1 parent b17322e commit 81f12df
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ def start_active_span(
:class:`ScopeManagerShim`.
"""

current_span = get_current_span()

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

span = self.start_span(
operation_name=operation_name,
child_of=child_of,
Expand Down
28 changes: 28 additions & 0 deletions ext/opentelemetry-ext-opentracing-shim/tests/test_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,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,
)

0 comments on commit 81f12df

Please sign in to comment.