Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Verify ScopeShim.close() deactivates span
Browse files Browse the repository at this point in the history
Verify that calling `close()` on a `ScopeShim` deactivates the span
in the OpenTelemetry tracer.
  • Loading branch information
johananl committed Oct 16, 2019
1 parent 0db5302 commit d6e82bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ def close(self):
self._span_cm.__exit__(None, None, None)
else:
self._span.unwrap().end()
# TODO: Set active span on OpenTelemetry tracer.
# https://github.com/open-telemetry/opentelemetry-python/issues/161#issuecomment-534136274


class ScopeManagerShim(opentracing.ScopeManager):
Expand Down
27 changes: 20 additions & 7 deletions ext/opentelemetry-ext-opentracing-shim/tests/test_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,29 @@ def test_activate_finish_on_close(self):
def test_explicit_scope_close(self):
"""Test `close()` method on `ScopeShim`."""

span = self.shim.start_span("TestSpan")
scope = opentracingshim.ScopeShim(self.shim.scope_manager, span)
with self.shim.start_active_span("ParentSpan") as parent:
# Verify parent span is active.
self.assertEqual(
self.shim.active_span.context, parent.span.context
)

# Verify span hasn't ended.
self.assertIsNone(span.unwrap().end_time)
child = self.shim.start_active_span("ChildSpan")

scope.close()
# Verify child span is active.
self.assertEqual(self.shim.active_span.context, child.span.context)

# Verify span has ended.
self.assertIsNotNone(span.unwrap().end_time)
# Verify child span hasn't ended.
self.assertIsNone(child.span.unwrap().end_time)

child.close()

# Verify child span has ended.
self.assertIsNotNone(child.span.unwrap().end_time)

# Verify parent span becomes active again.
self.assertEqual(
self.shim.active_span.context, parent.span.context
)

def test_parent_child_implicit(self):
"""Test parent-child relationship and activation/deactivation of spans
Expand Down

0 comments on commit d6e82bc

Please sign in to comment.