From f31c95008de882a5e079e8b36dcba5ae73a338ee Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 17 Jul 2020 01:35:21 -0600 Subject: [PATCH] Store ScopeShim in context This uses the OpenTelemetry context management mechanism to store a ScopeShim object in order to make active return the same object as the one returned by start_active_span. WIP: there is one failing test case, apparently the context does not get cleared before running every test case. This seems related to the order in which test cases are being run. --- .../opentelemetry/instrumentation/opentracing_shim/__init__.py | 2 ++ .../tests/test_shim.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-opentracing-shim/src/opentelemetry/instrumentation/opentracing_shim/__init__.py b/instrumentation/opentelemetry-instrumentation-opentracing-shim/src/opentelemetry/instrumentation/opentracing_shim/__init__.py index 6c76444e6ee..a68c229b125 100644 --- a/instrumentation/opentelemetry-instrumentation-opentracing-shim/src/opentelemetry/instrumentation/opentracing_shim/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-opentracing-shim/src/opentelemetry/instrumentation/opentracing_shim/__init__.py @@ -395,6 +395,8 @@ def close(self): else: self._span.unwrap().end() + detach(self._token) + class ScopeManagerShim(opentracing.ScopeManager): """Implements :class:`opentracing.ScopeManager` by setting and getting the diff --git a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py index 445ce6ce161..0d093809138 100644 --- a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py +++ b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py @@ -532,6 +532,8 @@ def test_extract_empty_context_returns_invalid_context(self): try: carrier = {} + from ipdb import set_trace + set_trace() ctx = self.shim.extract(opentracing.Format.HTTP_HEADERS, carrier) self.assertEqual(ctx.unwrap(), trace.INVALID_SPAN_CONTEXT) finally: