From a757a9bdd2ea16be63a78740fa429383c8dfa66f Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 14 Jul 2020 12:02:30 -0600 Subject: [PATCH 01/14] Implement get_attribute and set_attribute Fixes #239 --- opentelemetry-api/src/opentelemetry/trace/span.py | 10 ++++++++++ .../src/opentelemetry/sdk/trace/__init__.py | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/opentelemetry-api/src/opentelemetry/trace/span.py b/opentelemetry-api/src/opentelemetry/trace/span.py index d207ecf565b..c45f92a4e2c 100644 --- a/opentelemetry-api/src/opentelemetry/trace/span.py +++ b/opentelemetry-api/src/opentelemetry/trace/span.py @@ -37,6 +37,13 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None: Sets a single Attribute with the key and value passed as arguments. """ + @abc.abstractmethod + def get_attribute(self, key: str) -> types.AttributeValue: + """Gets an Attribute. + + Gets a single Attribute with the key passed as argument. + """ + @abc.abstractmethod def add_event( self, @@ -235,6 +242,9 @@ def end(self, end_time: typing.Optional[int] = None) -> None: def set_attribute(self, key: str, value: types.AttributeValue) -> None: pass + def get_attribute(self, key: str) -> types.AttributeValue: + pass + def add_event( self, name: str, diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index b76ba49ad4a..f83c0c9f775 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -553,6 +553,10 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None: with self._lock: self.attributes[key] = value + def get_attribute(self, key: str) -> types.AttributeValue: + + return self.attributes[key] + @staticmethod def _filter_attribute_values(attributes: types.Attributes): if attributes: From 16c0eea606bbf752b62f09634fbc6aeb7f657502 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 16 Jul 2020 18:47:56 -0600 Subject: [PATCH 02/14] Revert "Implement get_attribute and set_attribute" This reverts commit de3417252cea82f089e49bd681c35dff07463222. --- opentelemetry-api/src/opentelemetry/trace/span.py | 10 ---------- .../src/opentelemetry/sdk/trace/__init__.py | 4 ---- 2 files changed, 14 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/trace/span.py b/opentelemetry-api/src/opentelemetry/trace/span.py index c45f92a4e2c..d207ecf565b 100644 --- a/opentelemetry-api/src/opentelemetry/trace/span.py +++ b/opentelemetry-api/src/opentelemetry/trace/span.py @@ -37,13 +37,6 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None: Sets a single Attribute with the key and value passed as arguments. """ - @abc.abstractmethod - def get_attribute(self, key: str) -> types.AttributeValue: - """Gets an Attribute. - - Gets a single Attribute with the key passed as argument. - """ - @abc.abstractmethod def add_event( self, @@ -242,9 +235,6 @@ def end(self, end_time: typing.Optional[int] = None) -> None: def set_attribute(self, key: str, value: types.AttributeValue) -> None: pass - def get_attribute(self, key: str) -> types.AttributeValue: - pass - def add_event( self, name: str, diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index f83c0c9f775..b76ba49ad4a 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -553,10 +553,6 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None: with self._lock: self.attributes[key] = value - def get_attribute(self, key: str) -> types.AttributeValue: - - return self.attributes[key] - @staticmethod def _filter_attribute_values(attributes: types.Attributes): if attributes: From 2f07910d7ce3e7ac7fcc679403e3b458616582f0 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 17 Jul 2020 01:35:21 -0600 Subject: [PATCH 03/14] 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: From 0aabe24be955ce6eb05a072ba38a3977beee7cf9 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 17 Jul 2020 10:22:26 -0600 Subject: [PATCH 04/14] Add remaining fixes Fixes #242 --- .../instrumentation/opentracing_shim/__init__.py | 4 +--- .../tests/test_shim.py | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) 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 a68c229b125..f36a5f9da2d 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 @@ -327,7 +327,7 @@ class ScopeShim(opentracing.Scope): def __init__(self, manager, span, span_cm=None): super().__init__(manager, span) self._span_cm = span_cm - self._token = attach(set_value("scope_shim", self)) + attach(set_value("scope_shim", self)) # TODO: Change type of `manager` argument to `opentracing.ScopeManager`? We # need to get rid of `manager.tracer` for this. @@ -395,8 +395,6 @@ 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 0d093809138..445ce6ce161 100644 --- a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py +++ b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py @@ -532,8 +532,6 @@ 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: From d7932393add1ef10478fa9ab29c8d0bac2133e52 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 31 Jul 2020 14:34:20 -0600 Subject: [PATCH 05/14] Calling detach at the right place --- .../opentelemetry/instrumentation/opentracing_shim/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f36a5f9da2d..6c76444e6ee 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 @@ -327,7 +327,7 @@ class ScopeShim(opentracing.Scope): def __init__(self, manager, span, span_cm=None): super().__init__(manager, span) self._span_cm = span_cm - attach(set_value("scope_shim", self)) + self._token = attach(set_value("scope_shim", self)) # TODO: Change type of `manager` argument to `opentracing.ScopeManager`? We # need to get rid of `manager.tracer` for this. From 15128ed64722f02e0806c76995fa54ff098c5e25 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Tue, 14 Jul 2020 12:02:30 -0600 Subject: [PATCH 06/14] Implement get_attribute and set_attribute Fixes #239 --- opentelemetry-api/src/opentelemetry/trace/span.py | 10 ++++++++++ .../src/opentelemetry/sdk/trace/__init__.py | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/opentelemetry-api/src/opentelemetry/trace/span.py b/opentelemetry-api/src/opentelemetry/trace/span.py index d207ecf565b..c45f92a4e2c 100644 --- a/opentelemetry-api/src/opentelemetry/trace/span.py +++ b/opentelemetry-api/src/opentelemetry/trace/span.py @@ -37,6 +37,13 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None: Sets a single Attribute with the key and value passed as arguments. """ + @abc.abstractmethod + def get_attribute(self, key: str) -> types.AttributeValue: + """Gets an Attribute. + + Gets a single Attribute with the key passed as argument. + """ + @abc.abstractmethod def add_event( self, @@ -235,6 +242,9 @@ def end(self, end_time: typing.Optional[int] = None) -> None: def set_attribute(self, key: str, value: types.AttributeValue) -> None: pass + def get_attribute(self, key: str) -> types.AttributeValue: + pass + def add_event( self, name: str, diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index b76ba49ad4a..f83c0c9f775 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -553,6 +553,10 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None: with self._lock: self.attributes[key] = value + def get_attribute(self, key: str) -> types.AttributeValue: + + return self.attributes[key] + @staticmethod def _filter_attribute_values(attributes: types.Attributes): if attributes: From 66e6641e051da60f94c67c68d05a39e55b85fe95 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 16 Jul 2020 18:47:56 -0600 Subject: [PATCH 07/14] Revert "Implement get_attribute and set_attribute" This reverts commit de3417252cea82f089e49bd681c35dff07463222. --- opentelemetry-api/src/opentelemetry/trace/span.py | 10 ---------- .../src/opentelemetry/sdk/trace/__init__.py | 4 ---- 2 files changed, 14 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/trace/span.py b/opentelemetry-api/src/opentelemetry/trace/span.py index c45f92a4e2c..d207ecf565b 100644 --- a/opentelemetry-api/src/opentelemetry/trace/span.py +++ b/opentelemetry-api/src/opentelemetry/trace/span.py @@ -37,13 +37,6 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None: Sets a single Attribute with the key and value passed as arguments. """ - @abc.abstractmethod - def get_attribute(self, key: str) -> types.AttributeValue: - """Gets an Attribute. - - Gets a single Attribute with the key passed as argument. - """ - @abc.abstractmethod def add_event( self, @@ -242,9 +235,6 @@ def end(self, end_time: typing.Optional[int] = None) -> None: def set_attribute(self, key: str, value: types.AttributeValue) -> None: pass - def get_attribute(self, key: str) -> types.AttributeValue: - pass - def add_event( self, name: str, diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index f83c0c9f775..b76ba49ad4a 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -553,10 +553,6 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None: with self._lock: self.attributes[key] = value - def get_attribute(self, key: str) -> types.AttributeValue: - - return self.attributes[key] - @staticmethod def _filter_attribute_values(attributes: types.Attributes): if attributes: From 1bb13f5437eef319748fd006b5b87531ba226c78 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 16 Jul 2020 20:13:45 -0600 Subject: [PATCH 08/14] Add tests --- .../tests/test_shim.py | 1 - 1 file changed, 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py index 445ce6ce161..2906b5803cb 100644 --- a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py +++ b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py @@ -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) From af0ab231c82b27e3032ab6feaaf746c3aa8cb61a Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 17 Jul 2020 01:35:21 -0600 Subject: [PATCH 09/14] 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. --- .../tests/test_shim.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py index 2906b5803cb..09a07c83f4b 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: From d9755278f8a69a8dbd4067ae2b2e7ab71ed9207d Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 17 Jul 2020 10:22:26 -0600 Subject: [PATCH 10/14] Add remaining fixes Fixes #242 --- .../tests/test_shim.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py index 09a07c83f4b..2906b5803cb 100644 --- a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py +++ b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py @@ -532,8 +532,6 @@ 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: From d1aa5bcdaf3a176b029da8d3a9ed9d17465a51d4 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 17 Jul 2020 01:35:21 -0600 Subject: [PATCH 11/14] 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. --- .../tests/test_shim.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py index 2906b5803cb..09a07c83f4b 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: From 9205f1f0e063a4ea1fbe4dff649e01c8d1563407 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 17 Jul 2020 10:22:26 -0600 Subject: [PATCH 12/14] Add remaining fixes Fixes #242 --- .../tests/test_shim.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py index 09a07c83f4b..2906b5803cb 100644 --- a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py +++ b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py @@ -532,8 +532,6 @@ 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: From 0d1ad48c4238760127d4fb66c0a64d4a1ea33e72 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 17 Jul 2020 20:40:22 -0600 Subject: [PATCH 13/14] Add test case Fixes #161 --- .../opentracing_shim/__init__.py | 5 ++++ .../tests/test_shim.py | 28 +++++++++++++++++++ 2 files changed, 33 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..8660662d34b 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 @@ -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 None: + child_of = SpanShim(None, None, current_span) + span = self.start_span( operation_name=operation_name, child_of=child_of, diff --git a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py index 2906b5803cb..c880913a877 100644 --- a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py +++ b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py @@ -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, + ) From 504b11879d9e9ae1f45f0a82982407cbc98bfc74 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Fri, 31 Jul 2020 15:09:22 -0600 Subject: [PATCH 14/14] Use INVALID_SPAN_CONTEXT instead of None --- .../opentelemetry/instrumentation/opentracing_shim/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8660662d34b..dd05feecff2 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 @@ -572,7 +572,7 @@ def start_active_span( current_span = get_current_span() - if child_of is None and current_span is not None: + if child_of is None and current_span is not INVALID_SPAN_CONTEXT: child_of = SpanShim(None, None, current_span) span = self.start_span(