From 4e87e132a1225d4b9f7056f26b62609879c03200 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 21 Sep 2020 10:31:57 -0700 Subject: [PATCH 01/19] parent is now always passed in via Context, intead of Span or SpanContext --- .../src/opentelemetry/trace/__init__.py | 16 +++++++--------- .../src/opentelemetry/sdk/trace/__init__.py | 15 +++++---------- opentelemetry-sdk/tests/trace/test_trace.py | 3 ++- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index 1795192254f..21d6b966339 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -77,6 +77,8 @@ from contextlib import contextmanager from logging import getLogger +from opentelemetry.context import Context + from opentelemetry.trace.propagation import ( get_current_span, set_span_in_context, @@ -101,9 +103,6 @@ logger = getLogger(__name__) -# TODO: quarantine -ParentSpan = typing.Optional[typing.Union["Span", "SpanContext"]] - class LinkBase(abc.ABC): def __init__(self, context: "SpanContext") -> None: @@ -227,7 +226,7 @@ class Tracer(abc.ABC): def start_span( self, name: str, - parent: ParentSpan = CURRENT_SPAN, + parent: typing.Optional[Context] = None, kind: SpanKind = SpanKind.INTERNAL, attributes: types.Attributes = None, links: typing.Sequence[Link] = (), @@ -279,7 +278,7 @@ def start_span( def start_as_current_span( self, name: str, - parent: ParentSpan = CURRENT_SPAN, + parent: typing.Optional[Context] = None, kind: SpanKind = SpanKind.INTERNAL, attributes: types.Attributes = None, links: typing.Sequence[Link] = (), @@ -315,7 +314,7 @@ def start_as_current_span( Args: name: The name of the span to be created. - parent: The span's parent. Defaults to the current span. + parent: An optional Context containing the span's parent. kind: The span's kind (relationship to parent). Note that is meaningful even if there is no parent. attributes: The span's attributes. @@ -355,7 +354,7 @@ class DefaultTracer(Tracer): def start_span( self, name: str, - parent: ParentSpan = Tracer.CURRENT_SPAN, + parent: typing.Optional[Context] = None, kind: SpanKind = SpanKind.INTERNAL, attributes: types.Attributes = None, links: typing.Sequence[Link] = (), @@ -369,7 +368,7 @@ def start_span( def start_as_current_span( self, name: str, - parent: ParentSpan = Tracer.CURRENT_SPAN, + parent: typing.Optional[Context] = None, kind: SpanKind = SpanKind.INTERNAL, attributes: types.Attributes = None, links: typing.Sequence[Link] = (), @@ -444,7 +443,6 @@ def get_tracer_provider() -> TracerProvider: "DefaultTracerProvider", "Link", "LinkBase", - "ParentSpan", "Span", "SpanContext", "SpanKind", diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 13819ed35b0..b645781c7ab 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -345,8 +345,7 @@ class Span(trace_api.Span): Args: name: The name of the operation this span represents context: The immutable span context - parent: This span's parent's `opentelemetry.trace.SpanContext`, or - null if this is a root span + parent: An optional Context containing the span's parent sampler: The sampler used to create this span trace_config: TODO resource: Entity producing telemetry @@ -701,7 +700,7 @@ def __init__( def start_as_current_span( self, name: str, - parent: trace_api.ParentSpan = trace_api.Tracer.CURRENT_SPAN, + parent: Optional[context_api.Context] = None, kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL, attributes: types.Attributes = None, links: Sequence[trace_api.Link] = (), @@ -712,19 +711,15 @@ def start_as_current_span( def start_span( # pylint: disable=too-many-locals self, name: str, - parent: trace_api.ParentSpan = trace_api.Tracer.CURRENT_SPAN, + parent: Optional[context_api.Context] = None, kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL, attributes: types.Attributes = None, links: Sequence[trace_api.Link] = (), start_time: Optional[int] = None, set_status_on_exception: bool = True, ) -> trace_api.Span: - if parent is Tracer.CURRENT_SPAN: - parent = trace_api.get_current_span() - parent_context = parent - if isinstance(parent_context, trace_api.Span): - parent_context = parent.get_context() + parent_context = trace_api.get_current_span(parent).get_context() if parent_context is not None and not isinstance( parent_context, trace_api.SpanContext @@ -732,7 +727,7 @@ def start_span( # pylint: disable=too-many-locals raise TypeError("parent must be a Span, SpanContext or None.") if parent_context is None or not parent_context.is_valid: - parent = parent_context = None + parent_context = None trace_id = generate_trace_id() trace_flags = None trace_state = None diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index fdf85ef19b5..580a0e35462 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -358,6 +358,7 @@ def test_start_as_current_span_explicit(self): is_remote=False, trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED), ) + other_parent_ctx = trace_api.set_span_in_context(other_parent) self.assertEqual(trace_api.get_current_span(), trace_api.INVALID_SPAN) @@ -369,7 +370,7 @@ def test_start_as_current_span_explicit(self): self.assertIsNone(root.end_time) with tracer.start_as_current_span( - "stepchild", other_parent + "stepchild", other_parent_ctx ) as child: # The child should become the current span as usual, but its # parent should be the one passed in, not the From 9e707e31c631e19a84df93bd3b8850acf13ce04f Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 22 Sep 2020 20:40:37 -0700 Subject: [PATCH 02/19] fix tests --- opentelemetry-sdk/tests/trace/test_trace.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 580a0e35462..0220d987565 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -136,8 +136,9 @@ def test_default_sampler(self): # Check that the default tracer creates real spans via the default # sampler root_span = tracer.start_span(name="root span", parent=None) + ctx = trace_api.set_span_in_context(root_span) self.assertIsInstance(root_span, trace.Span) - child_span = tracer.start_span(name="child span", parent=root_span) + child_span = tracer.start_span(name="child span", parent=ctx) self.assertIsInstance(child_span, trace.Span) self.assertTrue(root_span.context.trace_flags.sampled) self.assertEqual( @@ -154,8 +155,9 @@ def test_sampler_no_sampling(self): # Check that the default tracer creates no-op spans if the sampler # decides not to sampler root_span = tracer.start_span(name="root span", parent=None) + ctx = trace_api.set_span_in_context(root_span) self.assertIsInstance(root_span, trace_api.DefaultSpan) - child_span = tracer.start_span(name="child span", parent=root_span) + child_span = tracer.start_span(name="child span", parent=ctx) self.assertIsInstance(child_span, trace_api.DefaultSpan) self.assertEqual( root_span.get_context().trace_flags, trace_api.TraceFlags.DEFAULT @@ -288,6 +290,7 @@ def test_start_span_explicit(self): is_remote=False, trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED), ) + other_parent_context = trace_api.set_span_in_context(other_parent) self.assertEqual(trace_api.get_current_span(), trace_api.INVALID_SPAN) @@ -299,7 +302,7 @@ def test_start_span_explicit(self): with tracer.use_span(root, True): self.assertIs(trace_api.get_current_span(), root) - with tracer.start_span("stepchild", other_parent) as child: + with tracer.start_span("stepchild", other_parent_context) as child: # The child's parent should be the one passed in, # not the current span. self.assertNotEqual(child.parent, root) @@ -539,7 +542,9 @@ def test_sampling_attributes(self): "attr-in-both": "decision-attr", } tracer_provider = trace.TracerProvider( - sampling.StaticSampler(sampling.Decision.RECORD_AND_SAMPLE,) + sampling.StaticSampler( + sampling.Decision.RECORD_AND_SAMPLE, + ) ) self.tracer = tracer_provider.get_tracer(__name__) From 3493bcee13da99510374e5228c69f2bae4719bb5 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 30 Sep 2020 17:25:12 -0700 Subject: [PATCH 03/19] fix one more test --- opentelemetry-sdk/tests/trace/test_trace.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 0220d987565..2a8085ddc92 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -176,9 +176,10 @@ def test_start_span_invalid_spancontext(self): eliminates redundant error handling logic in exporters. """ tracer = new_tracer() - new_span = tracer.start_span( - "root", parent=trace_api.INVALID_SPAN_CONTEXT + parent_context = trace_api.set_span_in_context( + trace_api.INVALID_SPAN_CONTEXT ) + new_span = tracer.start_span("root", parent=parent_context) self.assertTrue(new_span.context.is_valid) self.assertIsNone(new_span.parent) @@ -306,7 +307,7 @@ def test_start_span_explicit(self): # The child's parent should be the one passed in, # not the current span. self.assertNotEqual(child.parent, root) - self.assertIs(child.parent, other_parent) + self.assertIs(child.parent, other_parent_context) self.assertIsNotNone(child.start_time) self.assertIsNone(child.end_time) From 34b6cc1edec8b17b0d39dddf8cd7b94aab128a11 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 1 Oct 2020 15:11:52 -0700 Subject: [PATCH 04/19] fix test --- opentelemetry-sdk/tests/trace/test_trace.py | 43 +++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 2a8085ddc92..f870b3c1847 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -285,12 +285,16 @@ def test_start_span_implicit(self): def test_start_span_explicit(self): tracer = new_tracer() - other_parent = trace_api.SpanContext( - trace_id=0x000000000000000000000000DEADBEEF, - span_id=0x00000000DEADBEF0, - is_remote=False, - trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED), + other_parent = trace.Span( + "name", + trace_api.SpanContext( + trace_id=0x000000000000000000000000DEADBEEF, + span_id=0x00000000DEADBEF0, + is_remote=False, + trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED), + ), ) + other_parent_context = trace_api.set_span_in_context(other_parent) self.assertEqual(trace_api.get_current_span(), trace_api.INVALID_SPAN) @@ -307,7 +311,7 @@ def test_start_span_explicit(self): # The child's parent should be the one passed in, # not the current span. self.assertNotEqual(child.parent, root) - self.assertIs(child.parent, other_parent_context) + self.assertIs(child.parent, other_parent.get_context()) self.assertIsNotNone(child.start_time) self.assertIsNone(child.end_time) @@ -315,15 +319,19 @@ def test_start_span_explicit(self): # The child should inherit its context from the explicit # parent, not the current span. child_context = child.get_context() - self.assertEqual(other_parent.trace_id, child_context.trace_id) + self.assertEqual( + other_parent.get_context().trace_id, child_context.trace_id + ) self.assertNotEqual( - other_parent.span_id, child_context.span_id + other_parent.get_context().span_id, child_context.span_id ) self.assertEqual( - other_parent.trace_state, child_context.trace_state + other_parent.get_context().trace_state, + child_context.trace_state, ) self.assertEqual( - other_parent.trace_flags, child_context.trace_flags + other_parent.get_context().trace_flags, + child_context.trace_flags, ) # Verify start_span() did not set the current span. @@ -356,11 +364,14 @@ def test_start_as_current_span_implicit(self): def test_start_as_current_span_explicit(self): tracer = new_tracer() - other_parent = trace_api.SpanContext( - trace_id=0x000000000000000000000000DEADBEEF, - span_id=0x00000000DEADBEF0, - is_remote=False, - trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED), + other_parent = trace.Span( + "name", + trace_api.SpanContext( + trace_id=0x000000000000000000000000DEADBEEF, + span_id=0x00000000DEADBEF0, + is_remote=False, + trace_flags=trace_api.TraceFlags(trace_api.TraceFlags.SAMPLED), + ), ) other_parent_ctx = trace_api.set_span_in_context(other_parent) @@ -381,7 +392,7 @@ def test_start_as_current_span_explicit(self): # previously-current span. self.assertIs(trace_api.get_current_span(), child) self.assertNotEqual(child.parent, root) - self.assertIs(child.parent, other_parent) + self.assertIs(child.parent, other_parent.get_context()) # After exiting the child's scope the last span on the stack should # become current, not the child's parent. From eceae0f9dc34964024271f2b54ac777f3ea3c56a Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 1 Oct 2020 15:33:47 -0700 Subject: [PATCH 05/19] fix lint --- opentelemetry-sdk/tests/trace/test_trace.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 7cbcd8953ec..281db3de4cb 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -554,9 +554,7 @@ def test_sampling_attributes(self): "attr-in-both": "decision-attr", } tracer_provider = trace.TracerProvider( - sampling.StaticSampler( - sampling.Decision.RECORD_AND_SAMPLE, - ) + sampling.StaticSampler(sampling.Decision.RECORD_AND_SAMPLE) ) self.tracer = tracer_provider.get_tracer(__name__) From 865891cf9b7149790ebb32867598d4031fc2374f Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 1 Oct 2020 16:02:14 -0700 Subject: [PATCH 06/19] fix more tests --- .../opentelemetry/instrumentation/opentracing_shim/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 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 6bb22130d8e..28933023b71 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 @@ -630,6 +630,7 @@ def start_span( # Use the specified parent or the active span if possible. Otherwise, # use a `None` parent, which triggers the creation of a new trace. parent = child_of.unwrap() if child_of else None + parent_context = set_span_in_context(parent) if parent else None links = [] if references: @@ -645,7 +646,7 @@ def start_span( span = self._otel_tracer.start_span( operation_name, - parent, + parent_context, links=links, attributes=tags, start_time=start_time_ns, From 1acb6dbb02c0b72a863e7ac9778657315ddebf02 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 1 Oct 2020 16:07:41 -0700 Subject: [PATCH 07/19] fix import path --- opentelemetry-api/src/opentelemetry/trace/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index 99386af2a97..becf29baa3c 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -77,7 +77,7 @@ from contextlib import contextmanager from logging import getLogger -from opentelemetry.context import Context +from opentelemetry.context.context import Context from opentelemetry.trace.ids_generator import IdsGenerator, RandomIdsGenerator from opentelemetry.trace.propagation import ( get_current_span, From 01502ca87883cff4feebbc5cb566af136a86258e Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 1 Oct 2020 16:29:06 -0700 Subject: [PATCH 08/19] fix instrumentation tests --- .../src/opentelemetry/instrumentation/celery/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py index 4768e93d18e..940244e7920 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -118,14 +118,13 @@ def _trace_prerun(self, *args, **kwargs): return request = task.request - tracectx = propagators.extract(carrier_extractor, request) or {} - parent = get_current_span(tracectx) + tracectx = propagators.extract(carrier_extractor, request) or None logger.debug("prerun signal start task_id=%s", task_id) operation_name = "{0}/{1}".format(_TASK_RUN, task.name) span = self._tracer.start_span( - operation_name, parent=parent, kind=trace.SpanKind.CONSUMER + operation_name, parent=tracectx, kind=trace.SpanKind.CONSUMER ) activation = self._tracer.use_span(span, end_on_exit=True) From 42c574fc7b4fa7d0032720672bff9c1aec35ab6a Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 1 Oct 2020 21:41:41 -0700 Subject: [PATCH 09/19] fix shim --- .../instrumentation/opentracing_shim/__init__.py | 7 +++++-- opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py | 2 +- 2 files changed, 6 insertions(+), 3 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 28933023b71..6ddd41f2f4f 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 @@ -630,7 +630,10 @@ def start_span( # Use the specified parent or the active span if possible. Otherwise, # use a `None` parent, which triggers the creation of a new trace. parent = child_of.unwrap() if child_of else None - parent_context = set_span_in_context(parent) if parent else None + if isinstance(parent, OtelSpanContext): + parent = DefaultSpan(parent) + + parent_context = set_span_in_context(parent) links = [] if references: @@ -646,7 +649,7 @@ def start_span( span = self._otel_tracer.start_span( operation_name, - parent_context, + parent=parent_context, links=links, attributes=tags, start_time=start_time_ns, diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index fddddc10f6e..9d3d3f02d39 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -706,7 +706,7 @@ def start_span( # pylint: disable=too-many-locals if parent_context is not None and not isinstance( parent_context, trace_api.SpanContext ): - raise TypeError("parent must be a Span, SpanContext or None.") + raise TypeError("parent_context must be a SpanContext or None.") if parent_context is None or not parent_context.is_valid: parent_context = None From f82bd231a722ec2fea6724f13f12eb0d528902de Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 1 Oct 2020 21:56:21 -0700 Subject: [PATCH 10/19] updating docs/changelog --- opentelemetry-api/CHANGELOG.md | 2 ++ opentelemetry-api/src/opentelemetry/trace/__init__.py | 11 +++++++---- opentelemetry-sdk/CHANGELOG.md | 2 ++ .../src/opentelemetry/sdk/trace/__init__.py | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/opentelemetry-api/CHANGELOG.md b/opentelemetry-api/CHANGELOG.md index 91a822890bd..5eb87fbfe5e 100644 --- a/opentelemetry-api/CHANGELOG.md +++ b/opentelemetry-api/CHANGELOG.md @@ -8,6 +8,8 @@ ([#1118](https://github.com/open-telemetry/opentelemetry-python/pull/1118)) - Allow for Custom Trace and Span IDs Generation - `IdsGenerator` for TracerProvider ([#1153](https://github.com/open-telemetry/opentelemetry-python/pull/1153)) +- Parent is now always passed in via Context, intead of Span or SpanContext + ([#1146](https://github.com/open-telemetry/opentelemetry-python/pull/1146)) ## Version 0.13b0 diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index becf29baa3c..da567512ecd 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -240,8 +240,9 @@ def start_span( method, see :meth:`start_as_current_span`. By default the current span in the context will be used as parent, but an - explicit parent can also be specified, either a `Span` or a `opentelemetry.trace.SpanContext`. - If the specified value is `None`, the created span will be a root span. + explicit parent can also be specified, by passing in a `Context` containing + a current `Span`. If there is no current span in the global `Context` or in + the specified parent `Context`, the created span will be a root span. The span can be used as a context manager. On exiting the context manager, the span's end() method will be called. @@ -255,7 +256,8 @@ def start_span( Args: name: The name of the span to be created. - parent: The span's parent. Defaults to the current span. + parent: An optional Context containing the span's parent. Defaults to the + global context. kind: The span's kind (relationship to parent). Note that is meaningful even if there is no parent. attributes: The span's attributes. @@ -313,7 +315,8 @@ def start_as_current_span( Args: name: The name of the span to be created. - parent: An optional Context containing the span's parent. + parent: An optional Context containing the span's parent. Defaults to the + global context. kind: The span's kind (relationship to parent). Note that is meaningful even if there is no parent. attributes: The span's attributes. diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 71864282885..1b07c792c1b 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -10,6 +10,8 @@ ([#1105](https://github.com/open-telemetry/opentelemetry-python/pull/1120)) - Allow for Custom Trace and Span IDs Generation - `IdsGenerator` for TracerProvider ([#1153](https://github.com/open-telemetry/opentelemetry-python/pull/1153)) +- Parent is now always passed in via Context, intead of Span or SpanContext + ([#1146](https://github.com/open-telemetry/opentelemetry-python/pull/1146)) ## Version 0.13b0 diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 9d3d3f02d39..daba275e88d 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -345,7 +345,8 @@ class Span(trace_api.Span): Args: name: The name of the operation this span represents context: The immutable span context - parent: An optional Context containing the span's parent + parent: This span's parent's `opentelemetry.trace.SpanContext`, or + None if this is a root span sampler: The sampler used to create this span trace_config: TODO resource: Entity producing telemetry From b388cd8315e944c4c4d4b5e56419c91c2444d070 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 6 Oct 2020 09:17:43 -0700 Subject: [PATCH 11/19] rename parent parameter to context --- .../opentracing_shim/__init__.py | 2 +- .../src/opentelemetry/trace/__init__.py | 23 +++++++++++-------- .../src/opentelemetry/sdk/trace/__init__.py | 8 +++---- opentelemetry-sdk/tests/trace/test_trace.py | 10 ++++---- 4 files changed, 23 insertions(+), 20 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 6ddd41f2f4f..86a5c114739 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 @@ -649,7 +649,7 @@ def start_span( span = self._otel_tracer.start_span( operation_name, - parent=parent_context, + context=parent_context, links=links, attributes=tags, start_time=start_time_ns, diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index da567512ecd..97d794915a4 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -49,8 +49,11 @@ When creating a span that's "detached" from the context the active span doesn't change, and the caller is responsible for managing the span's lifetime:: - # Explicit parent span assignment - child = tracer.start_span("child", parent=parent) + # Explicit parent span assignment is done via the Context + from opentelemetry.trace import set_span_in_context + + parent_context = set_span_in_context(parent) + child = tracer.start_span("child", context=parent_context) try: do_work(span=child) @@ -226,7 +229,7 @@ class Tracer(abc.ABC): def start_span( self, name: str, - parent: typing.Optional[Context] = None, + context: typing.Optional[Context] = None, kind: SpanKind = SpanKind.INTERNAL, attributes: types.Attributes = None, links: typing.Sequence[Link] = (), @@ -240,9 +243,9 @@ def start_span( method, see :meth:`start_as_current_span`. By default the current span in the context will be used as parent, but an - explicit parent can also be specified, by passing in a `Context` containing + explicit context can also be specified, by passing in a `Context` containing a current `Span`. If there is no current span in the global `Context` or in - the specified parent `Context`, the created span will be a root span. + the specified context, the created span will be a root span. The span can be used as a context manager. On exiting the context manager, the span's end() method will be called. @@ -256,7 +259,7 @@ def start_span( Args: name: The name of the span to be created. - parent: An optional Context containing the span's parent. Defaults to the + context: An optional Context containing the span's parent. Defaults to the global context. kind: The span's kind (relationship to parent). Note that is meaningful even if there is no parent. @@ -278,7 +281,7 @@ def start_span( def start_as_current_span( self, name: str, - parent: typing.Optional[Context] = None, + context: typing.Optional[Context] = None, kind: SpanKind = SpanKind.INTERNAL, attributes: types.Attributes = None, links: typing.Sequence[Link] = (), @@ -315,7 +318,7 @@ def start_as_current_span( Args: name: The name of the span to be created. - parent: An optional Context containing the span's parent. Defaults to the + context: An optional Context containing the span's parent. Defaults to the global context. kind: The span's kind (relationship to parent). Note that is meaningful even if there is no parent. @@ -358,7 +361,7 @@ class DefaultTracer(Tracer): def start_span( self, name: str, - parent: typing.Optional[Context] = None, + context: typing.Optional[Context] = None, kind: SpanKind = SpanKind.INTERNAL, attributes: types.Attributes = None, links: typing.Sequence[Link] = (), @@ -372,7 +375,7 @@ def start_span( def start_as_current_span( self, name: str, - parent: typing.Optional[Context] = None, + context: typing.Optional[Context] = None, kind: SpanKind = SpanKind.INTERNAL, attributes: types.Attributes = None, links: typing.Sequence[Link] = (), diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index daba275e88d..77303063a1a 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -683,18 +683,18 @@ def __init__( def start_as_current_span( self, name: str, - parent: Optional[context_api.Context] = None, + context: Optional[context_api.Context] = None, kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL, attributes: types.Attributes = None, links: Sequence[trace_api.Link] = (), ) -> Iterator[trace_api.Span]: - span = self.start_span(name, parent, kind, attributes, links) + span = self.start_span(name, context, kind, attributes, links) return self.use_span(span, end_on_exit=True) def start_span( # pylint: disable=too-many-locals self, name: str, - parent: Optional[context_api.Context] = None, + context: Optional[context_api.Context] = None, kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL, attributes: types.Attributes = None, links: Sequence[trace_api.Link] = (), @@ -702,7 +702,7 @@ def start_span( # pylint: disable=too-many-locals set_status_on_exception: bool = True, ) -> trace_api.Span: - parent_context = trace_api.get_current_span(parent).get_context() + parent_context = trace_api.get_current_span(context).get_context() if parent_context is not None and not isinstance( parent_context, trace_api.SpanContext diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 281db3de4cb..d9696a8d075 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -135,10 +135,10 @@ def test_default_sampler(self): # Check that the default tracer creates real spans via the default # sampler - root_span = tracer.start_span(name="root span", parent=None) + root_span = tracer.start_span(name="root span", context=None) ctx = trace_api.set_span_in_context(root_span) self.assertIsInstance(root_span, trace.Span) - child_span = tracer.start_span(name="child span", parent=ctx) + child_span = tracer.start_span(name="child span", context=ctx) self.assertIsInstance(child_span, trace.Span) self.assertTrue(root_span.context.trace_flags.sampled) self.assertEqual( @@ -154,10 +154,10 @@ def test_sampler_no_sampling(self): # Check that the default tracer creates no-op spans if the sampler # decides not to sampler - root_span = tracer.start_span(name="root span", parent=None) + root_span = tracer.start_span(name="root span", context=None) ctx = trace_api.set_span_in_context(root_span) self.assertIsInstance(root_span, trace_api.DefaultSpan) - child_span = tracer.start_span(name="child span", parent=ctx) + child_span = tracer.start_span(name="child span", context=ctx) self.assertIsInstance(child_span, trace_api.DefaultSpan) self.assertEqual( root_span.get_context().trace_flags, trace_api.TraceFlags.DEFAULT @@ -179,7 +179,7 @@ def test_start_span_invalid_spancontext(self): parent_context = trace_api.set_span_in_context( trace_api.INVALID_SPAN_CONTEXT ) - new_span = tracer.start_span("root", parent=parent_context) + new_span = tracer.start_span("root", context=parent_context) self.assertTrue(new_span.context.is_valid) self.assertIsNone(new_span.parent) From 3114a133988740fa649806b0d3c85de428750e99 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 6 Oct 2020 09:20:00 -0700 Subject: [PATCH 12/19] fix celery instrumentation --- .../src/opentelemetry/instrumentation/celery/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py index 940244e7920..3bd912c5ed0 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -124,7 +124,7 @@ def _trace_prerun(self, *args, **kwargs): operation_name = "{0}/{1}".format(_TASK_RUN, task.name) span = self._tracer.start_span( - operation_name, parent=tracectx, kind=trace.SpanKind.CONSUMER + operation_name, context=tracectx, kind=trace.SpanKind.CONSUMER ) activation = self._tracer.use_span(span, end_on_exit=True) From a2dfae9486546ef2ac95a4c8264a0d93a3a04197 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 6 Oct 2020 09:42:26 -0700 Subject: [PATCH 13/19] fix lint --- opentelemetry-api/src/opentelemetry/trace/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index 97d794915a4..1c1510fd211 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -51,7 +51,7 @@ # Explicit parent span assignment is done via the Context from opentelemetry.trace import set_span_in_context - + parent_context = set_span_in_context(parent) child = tracer.start_span("child", context=parent_context) From 594f9f8ea9788fb060cf5cf6d8ca94a6e3d6b97c Mon Sep 17 00:00:00 2001 From: alrex Date: Tue, 6 Oct 2020 13:17:40 -0700 Subject: [PATCH 14/19] Apply suggestions from code review Co-authored-by: Diego Hurtado --- opentelemetry-api/src/opentelemetry/trace/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index 1c1510fd211..768764eb64c 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -52,8 +52,8 @@ # Explicit parent span assignment is done via the Context from opentelemetry.trace import set_span_in_context - parent_context = set_span_in_context(parent) - child = tracer.start_span("child", context=parent_context) + context = set_span_in_context(parent) + child = tracer.start_span("child", context=context) try: do_work(span=child) From a451c4f3952f348b34a379ca0469ddcc91ef0200 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 7 Oct 2020 08:29:11 -0700 Subject: [PATCH 15/19] rename get_context to get_span_context --- .../exporter/datadog/exporter.py | 8 ++-- .../exporter/datadog/propagator.py | 2 +- .../exporter/datadog/spanprocessor.py | 4 +- .../tests/test_datadog_format.py | 10 ++--- .../examples/jaeger_exporter_example.py | 2 +- .../opentelemetry/exporter/jaeger/__init__.py | 2 +- .../tests/test_otcollector_trace_exporter.py | 2 +- .../opentelemetry/exporter/zipkin/__init__.py | 4 +- .../tests/test_jinja2.py | 18 ++++----- .../opentracing_shim/__init__.py | 10 ++--- .../tests/test_shim.py | 35 ++++++++++------- .../tests/test_requests_integration.py | 4 +- .../tests/test_sqlite3.py | 2 +- .../trace/propagation/tracecontext.py | 2 +- .../src/opentelemetry/trace/span.py | 4 +- .../propagators/test_global_httptextformat.py | 2 +- .../tests/test_implementation.py | 8 ++-- .../test_tracecontexthttptextformat.py | 27 +++++++------ .../tests/trace/test_defaultspan.py | 6 +-- .../src/opentelemetry/sdk/trace/__init__.py | 4 +- .../sdk/trace/propagation/b3_format.py | 2 +- .../tests/context/test_asyncio.py | 2 +- .../tests/trace/propagation/test_b3_format.py | 14 +++---- .../tests/trace/test_implementation.py | 8 ++-- opentelemetry-sdk/tests/trace/test_trace.py | 39 +++++++++++-------- .../tests/mysql/test_mysql_functional.py | 2 +- .../tests/postgres/test_aiopg_functional.py | 4 +- .../tests/postgres/test_psycopg_functional.py | 2 +- .../tests/pymongo/test_pymongo_functional.py | 2 +- .../tests/pymysql/test_pymysql_functional.py | 2 +- .../tests/redis/test_redis_functional.py | 2 +- .../tests/sqlalchemy_tests/mixins.py | 2 +- .../src/opentelemetry/test/mock_textmap.py | 4 +- 33 files changed, 133 insertions(+), 108 deletions(-) diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py index 2b36299989f..36335c23588 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py @@ -189,12 +189,12 @@ def _translate_to_datadog(self, spans): def _get_trace_ids(span): """Extract tracer ids from span""" - ctx = span.get_context() + ctx = span.get_span_context() trace_id = ctx.trace_id span_id = ctx.span_id if isinstance(span.parent, trace_api.Span): - parent_id = span.parent.get_context().span_id + parent_id = span.parent.get_span_context().span_id elif isinstance(span.parent, trace_api.SpanContext): parent_id = span.parent.span_id else: @@ -255,13 +255,13 @@ def _get_exc_info(span): def _get_origin(span): - ctx = span.get_context() + ctx = span.get_span_context() origin = ctx.trace_state.get(DD_ORIGIN) return origin def _get_sampling_rate(span): - ctx = span.get_context() + ctx = span.get_span_context() return ( span.sampler.rate if ctx.trace_flags.sampled diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py index d2e60476e68..3ad9fa1ae21 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py @@ -86,7 +86,7 @@ def inject( context: typing.Optional[Context] = None, ) -> None: span = get_current_span(context) - span_context = span.get_context() + span_context = span.get_span_context() if span_context == trace.INVALID_SPAN_CONTEXT: return sampled = (trace.TraceFlags.SAMPLED & span.context.trace_flags) != 0 diff --git a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/spanprocessor.py b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/spanprocessor.py index 600778c88c2..603ea5024ec 100644 --- a/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/spanprocessor.py +++ b/exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/spanprocessor.py @@ -82,7 +82,7 @@ def __init__( self.worker_thread.start() def on_start(self, span: Span) -> None: - ctx = span.get_context() + ctx = span.get_span_context() trace_id = ctx.trace_id with self.traces_lock: @@ -102,7 +102,7 @@ def on_end(self, span: Span) -> None: logger.warning("Already shutdown, dropping span.") return - ctx = span.get_context() + ctx = span.get_span_context() trace_id = ctx.trace_id with self.traces_lock: diff --git a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py index 3c045539fd2..18409c7a6f8 100644 --- a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py +++ b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py @@ -51,7 +51,7 @@ def test_malformed_headers(self): malformed_parent_id_key: self.serialized_parent_id, }, ) - ).get_context() + ).get_span_context() self.assertNotEqual(context.trace_id, int(self.serialized_trace_id)) self.assertNotEqual(context.span_id, int(self.serialized_parent_id)) @@ -64,7 +64,7 @@ def test_missing_trace_id(self): } ctx = FORMAT.extract(get_as_list, carrier) - span_context = get_current_span(ctx).get_context() + span_context = get_current_span(ctx).get_span_context() self.assertEqual(span_context.trace_id, trace_api.INVALID_TRACE_ID) def test_missing_parent_id(self): @@ -74,7 +74,7 @@ def test_missing_parent_id(self): } ctx = FORMAT.extract(get_as_list, carrier) - span_context = get_current_span(ctx).get_context() + span_context = get_current_span(ctx).get_span_context() self.assertEqual(span_context.span_id, trace_api.INVALID_SPAN_ID) def test_context_propagation(self): @@ -89,7 +89,7 @@ def test_context_propagation(self): FORMAT.ORIGIN_KEY: self.serialized_origin, }, ) - ).get_context() + ).get_span_context() self.assertEqual( parent_context.trace_id, int(self.serialized_trace_id) @@ -145,7 +145,7 @@ def test_sampling_priority_auto_reject(self): FORMAT.SAMPLING_PRIORITY_KEY: str(constants.AUTO_REJECT), }, ) - ).get_context() + ).get_span_context() self.assertEqual(parent_context.trace_flags, constants.AUTO_REJECT) diff --git a/exporter/opentelemetry-exporter-jaeger/examples/jaeger_exporter_example.py b/exporter/opentelemetry-exporter-jaeger/examples/jaeger_exporter_example.py index 68453fd9fac..0552f75183b 100644 --- a/exporter/opentelemetry-exporter-jaeger/examples/jaeger_exporter_example.py +++ b/exporter/opentelemetry-exporter-jaeger/examples/jaeger_exporter_example.py @@ -34,7 +34,7 @@ foo.set_attribute("my_atribbute", True) foo.add_event("event in foo", {"name": "foo1"}) with tracer.start_as_current_span( - "bar", links=[trace.Link(foo.get_context())] + "bar", links=[trace.Link(foo.get_span_context())] ) as bar: time.sleep(0.2) bar.set_attribute("speed", 100.0) diff --git a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py index 354fe8b85c1..3cfd3fca431 100644 --- a/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py +++ b/exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py @@ -192,7 +192,7 @@ def _translate_to_jaeger(spans: Span): jaeger_spans = [] for span in spans: - ctx = span.get_context() + ctx = span.get_span_context() trace_id = ctx.trace_id span_id = ctx.span_id diff --git a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py index 3721139efc9..bc07b1b0e15 100644 --- a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py +++ b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py @@ -138,7 +138,7 @@ def test_translate_to_collector(self): name="test3", context=other_context, links=(link_2,), - parent=span_2.get_context(), + parent=span_2.get_span_context(), ) otel_spans = [span_1, span_2, span_3] otel_spans[0].start(start_time=start_times[0]) diff --git a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py index bacfcc278d3..c8578c9649c 100644 --- a/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py +++ b/exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py @@ -159,7 +159,7 @@ def _translate_to_zipkin(self, spans: Sequence[Span]): zipkin_spans = [] for span in spans: - context = span.get_context() + context = span.get_span_context() trace_id = context.trace_id span_id = context.span_id @@ -205,7 +205,7 @@ def _translate_to_zipkin(self, spans: Sequence[Span]): if isinstance(span.parent, Span): zipkin_span["parentId"] = format( - span.parent.get_context().span_id, "016x" + span.parent.get_span_context().span_id, "016x" ) elif isinstance(span.parent, SpanContext): zipkin_span["parentId"] = format(span.parent.span_id, "016x") diff --git a/instrumentation/opentelemetry-instrumentation-jinja2/tests/test_jinja2.py b/instrumentation/opentelemetry-instrumentation-jinja2/tests/test_jinja2.py index 7f5b52c936d..717431abbb9 100644 --- a/instrumentation/opentelemetry-instrumentation-jinja2/tests/test_jinja2.py +++ b/instrumentation/opentelemetry-instrumentation-jinja2/tests/test_jinja2.py @@ -49,8 +49,8 @@ def test_render_inline_template_with_root(self): # pylint:disable=unbalanced-tuple-unpacking render, template, root = spans[:3] - self.assertIs(render.parent, root.get_context()) - self.assertIs(template.parent, root.get_context()) + self.assertIs(render.parent, root.get_span_context()) + self.assertIs(template.parent, root.get_span_context()) self.assertIsNone(root.parent) def test_render_inline_template(self): @@ -88,8 +88,8 @@ def test_generate_inline_template_with_root(self): # pylint:disable=unbalanced-tuple-unpacking template, generate, root = spans - self.assertIs(generate.parent, root.get_context()) - self.assertIs(template.parent, root.get_context()) + self.assertIs(generate.parent, root.get_span_context()) + self.assertIs(template.parent, root.get_span_context()) self.assertIsNone(root.parent) def test_generate_inline_template(self): @@ -131,11 +131,11 @@ def test_file_template_with_root(self): # pylint:disable=unbalanced-tuple-unpacking compile2, load2, compile1, load1, render, root = spans - self.assertIs(compile2.parent, load2.get_context()) - self.assertIs(load2.parent, root.get_context()) - self.assertIs(compile1.parent, load1.get_context()) - self.assertIs(load1.parent, render.get_context()) - self.assertIs(render.parent, root.get_context()) + self.assertIs(compile2.parent, load2.get_span_context()) + self.assertIs(load2.parent, root.get_span_context()) + self.assertIs(compile1.parent, load1.get_span_context()) + self.assertIs(load1.parent, render.get_span_context()) + self.assertIs(render.parent, root.get_span_context()) self.assertIsNone(root.parent) def test_file_template(self): 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 86a5c114739..a7cfb28b6f8 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 @@ -378,7 +378,7 @@ def from_context_manager(cls, manager: "ScopeManagerShim", span_cm): """ otel_span = span_cm.__enter__() - span_context = SpanContextShim(otel_span.get_context()) + span_context = SpanContextShim(otel_span.get_span_context()) span = SpanShim(manager.tracer, span_context, otel_span) return cls(manager, span, span_cm) @@ -474,13 +474,13 @@ def active(self) -> "ScopeShim": """ span = get_current_span() - if span.get_context() == INVALID_SPAN_CONTEXT: + if span.get_span_context() == INVALID_SPAN_CONTEXT: return None try: return get_value("scope_shim") except KeyError: - span_context = SpanContextShim(span.get_context()) + span_context = SpanContextShim(span.get_span_context()) wrapped_span = SpanShim(self._tracer, span_context, span) return ScopeShim(self, span=wrapped_span) @@ -655,7 +655,7 @@ def start_span( start_time=start_time_ns, ) - context = SpanContextShim(span.get_context()) + context = SpanContextShim(span.get_span_context()) return SpanShim(self, context, span) def inject(self, span_context, format: object, carrier: object): @@ -718,7 +718,7 @@ def get_as_list(dict_object, key): ctx = propagator.extract(get_as_list, carrier) span = get_current_span(ctx) if span is not None: - otel_context = span.get_context() + otel_context = span.get_span_context() else: otel_context = INVALID_SPAN_CONTEXT diff --git a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py index 672e7b02f96..151ca07ba9e 100644 --- a/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py +++ b/instrumentation/opentelemetry-instrumentation-opentracing-shim/tests/test_shim.py @@ -284,13 +284,17 @@ def test_parent_child_implicit(self): ) # Verify parent-child relationship. - parent_trace_id = parent.span.unwrap().get_context().trace_id - child_trace_id = child.span.unwrap().get_context().trace_id + parent_trace_id = ( + parent.span.unwrap().get_span_context().trace_id + ) + child_trace_id = ( + child.span.unwrap().get_span_context().trace_id + ) self.assertEqual(parent_trace_id, child_trace_id) self.assertEqual( child.span.unwrap().parent, - parent.span.unwrap().get_context(), + parent.span.unwrap().get_span_context(), ) # Verify parent span becomes the active span again. @@ -314,23 +318,26 @@ def test_parent_child_explicit_span(self): with self.shim.start_active_span( "ChildSpan", child_of=parent ) as child: - parent_trace_id = parent.unwrap().get_context().trace_id - child_trace_id = child.span.unwrap().get_context().trace_id + parent_trace_id = parent.unwrap().get_span_context().trace_id + child_trace_id = ( + child.span.unwrap().get_span_context().trace_id + ) self.assertEqual(child_trace_id, parent_trace_id) self.assertEqual( - child.span.unwrap().parent, parent.unwrap().get_context() + child.span.unwrap().parent, + parent.unwrap().get_span_context(), ) with self.shim.start_span("ParentSpan") as parent: child = self.shim.start_span("ChildSpan", child_of=parent) - parent_trace_id = parent.unwrap().get_context().trace_id - child_trace_id = child.unwrap().get_context().trace_id + parent_trace_id = parent.unwrap().get_span_context().trace_id + child_trace_id = child.unwrap().get_span_context().trace_id self.assertEqual(child_trace_id, parent_trace_id) self.assertEqual( - child.unwrap().parent, parent.unwrap().get_context() + child.unwrap().parent, parent.unwrap().get_span_context() ) child.finish() @@ -344,8 +351,10 @@ def test_parent_child_explicit_span_context(self): with self.shim.start_active_span( "ChildSpan", child_of=parent.context ) as child: - parent_trace_id = parent.unwrap().get_context().trace_id - child_trace_id = child.span.unwrap().get_context().trace_id + parent_trace_id = parent.unwrap().get_span_context().trace_id + child_trace_id = ( + child.span.unwrap().get_span_context().trace_id + ) self.assertEqual(child_trace_id, parent_trace_id) self.assertEqual( @@ -356,8 +365,8 @@ def test_parent_child_explicit_span_context(self): with self.shim.start_span( "SpanWithContextParent", child_of=parent.context ) as child: - parent_trace_id = parent.unwrap().get_context().trace_id - child_trace_id = child.unwrap().get_context().trace_id + parent_trace_id = parent.unwrap().get_span_context().trace_id + child_trace_id = child.unwrap().get_span_context().trace_id self.assertEqual(child_trace_id, parent_trace_id) self.assertEqual( diff --git a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py index 2d3636284bb..678499e8794 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py +++ b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py @@ -198,12 +198,12 @@ def test_distributed_context(self): headers = dict(httpretty.last_request().headers) self.assertIn(MockTextMapPropagator.TRACE_ID_KEY, headers) self.assertEqual( - str(span.get_context().trace_id), + str(span.get_span_context().trace_id), headers[MockTextMapPropagator.TRACE_ID_KEY], ) self.assertIn(MockTextMapPropagator.SPAN_ID_KEY, headers) self.assertEqual( - str(span.get_context().span_id), + str(span.get_span_context().span_id), headers[MockTextMapPropagator.SPAN_ID_KEY], ) diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py index a4444e7d937..0e385cf3e76 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/tests/test_sqlite3.py @@ -52,7 +52,7 @@ def validate_spans(self): self.assertEqual(root_span.name, "rootSpan") self.assertEqual(child_span.name, "sqlite3") self.assertIsNotNone(child_span.parent) - self.assertIs(child_span.parent, root_span.get_context()) + self.assertIs(child_span.parent, root_span.get_span_context()) self.assertIs(child_span.kind, trace_api.SpanKind.CLIENT) def test_execute(self): diff --git a/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontext.py b/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontext.py index 8627b9a65cb..4b77246ac5e 100644 --- a/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontext.py +++ b/opentelemetry-api/src/opentelemetry/trace/propagation/tracecontext.py @@ -118,7 +118,7 @@ def inject( See `opentelemetry.trace.propagation.textmap.TextMapPropagator.inject` """ span = trace.get_current_span(context) - span_context = span.get_context() + span_context = span.get_span_context() if span_context == trace.INVALID_SPAN_CONTEXT: return traceparent_string = "00-{:032x}-{:016x}-{:02x}".format( diff --git a/opentelemetry-api/src/opentelemetry/trace/span.py b/opentelemetry-api/src/opentelemetry/trace/span.py index 99620ed1443..2b206468afa 100644 --- a/opentelemetry-api/src/opentelemetry/trace/span.py +++ b/opentelemetry-api/src/opentelemetry/trace/span.py @@ -23,7 +23,7 @@ def end(self, end_time: typing.Optional[int] = None) -> None: """ @abc.abstractmethod - def get_context(self) -> "SpanContext": + def get_span_context(self) -> "SpanContext": """Gets the span's SpanContext. Get an immutable, serializable identifier for this span that can be @@ -237,7 +237,7 @@ class DefaultSpan(Span): def __init__(self, context: "SpanContext") -> None: self._context = context - def get_context(self) -> "SpanContext": + def get_span_context(self) -> "SpanContext": return self._context def is_recording(self) -> bool: diff --git a/opentelemetry-api/tests/propagators/test_global_httptextformat.py b/opentelemetry-api/tests/propagators/test_global_httptextformat.py index 9a97b281297..2668be27c3d 100644 --- a/opentelemetry-api/tests/propagators/test_global_httptextformat.py +++ b/opentelemetry-api/tests/propagators/test_global_httptextformat.py @@ -48,7 +48,7 @@ def test_propagation(self): baggage_entries = baggage.get_all(context=ctx) expected = {"key1": "val1", "key2": "val2"} self.assertEqual(baggage_entries, expected) - span_context = get_current_span(context=ctx).get_context() + span_context = get_current_span(context=ctx).get_span_context() self.assertEqual(span_context.trace_id, self.TRACE_ID) self.assertEqual(span_context.span_id, self.SPAN_ID) diff --git a/opentelemetry-api/tests/test_implementation.py b/opentelemetry-api/tests/test_implementation.py index 0d5b22b18f5..8e18fcb48d7 100644 --- a/opentelemetry-api/tests/test_implementation.py +++ b/opentelemetry-api/tests/test_implementation.py @@ -37,12 +37,14 @@ def test_default_tracer(self): tracer_provider = trace.DefaultTracerProvider() tracer = tracer_provider.get_tracer(__name__) with tracer.start_span("test") as span: - self.assertEqual(span.get_context(), trace.INVALID_SPAN_CONTEXT) + self.assertEqual( + span.get_span_context(), trace.INVALID_SPAN_CONTEXT + ) self.assertEqual(span, trace.INVALID_SPAN) self.assertIs(span.is_recording(), False) with tracer.start_span("test2") as span2: self.assertEqual( - span2.get_context(), trace.INVALID_SPAN_CONTEXT + span2.get_span_context(), trace.INVALID_SPAN_CONTEXT ) self.assertEqual(span2, trace.INVALID_SPAN) self.assertIs(span2.is_recording(), False) @@ -54,7 +56,7 @@ def test_span(self): def test_default_span(self): span = trace.DefaultSpan(trace.INVALID_SPAN_CONTEXT) - self.assertEqual(span.get_context(), trace.INVALID_SPAN_CONTEXT) + self.assertEqual(span.get_span_context(), trace.INVALID_SPAN_CONTEXT) self.assertIs(span.is_recording(), False) # METER diff --git a/opentelemetry-api/tests/trace/propagation/test_tracecontexthttptextformat.py b/opentelemetry-api/tests/trace/propagation/test_tracecontexthttptextformat.py index 8abe4193873..9e187e9398a 100644 --- a/opentelemetry-api/tests/trace/propagation/test_tracecontexthttptextformat.py +++ b/opentelemetry-api/tests/trace/propagation/test_tracecontexthttptextformat.py @@ -43,7 +43,7 @@ def test_no_traceparent_header(self): """ output = {} # type:typing.Dict[str, typing.List[str]] span = trace.get_current_span(FORMAT.extract(get_as_list, output)) - self.assertIsInstance(span.get_context(), trace.SpanContext) + self.assertIsInstance(span.get_span_context(), trace.SpanContext) def test_headers_with_tracestate(self): """When there is a traceparent and tracestate header, data from @@ -62,7 +62,7 @@ def test_headers_with_tracestate(self): "tracestate": [tracestate_value], }, ) - ).get_context() + ).get_span_context() self.assertEqual(span_context.trace_id, self.TRACE_ID) self.assertEqual(span_context.span_id, self.SPAN_ID) self.assertEqual( @@ -109,7 +109,7 @@ def test_invalid_trace_id(self): }, ) ) - self.assertEqual(span.get_context(), trace.INVALID_SPAN_CONTEXT) + self.assertEqual(span.get_span_context(), trace.INVALID_SPAN_CONTEXT) def test_invalid_parent_id(self): """If the parent id is invalid, we must ignore the full traceparent @@ -140,7 +140,7 @@ def test_invalid_parent_id(self): }, ) ) - self.assertEqual(span.get_context(), trace.INVALID_SPAN_CONTEXT) + self.assertEqual(span.get_span_context(), trace.INVALID_SPAN_CONTEXT) def test_no_send_empty_tracestate(self): """If the tracestate is empty, do not set the header. @@ -179,7 +179,7 @@ def test_format_not_supported(self): }, ) ) - self.assertEqual(span.get_context(), trace.INVALID_SPAN_CONTEXT) + self.assertEqual(span.get_span_context(), trace.INVALID_SPAN_CONTEXT) def test_propagate_invalid_context(self): """Do not propagate invalid trace context.""" @@ -202,7 +202,7 @@ def test_tracestate_empty_header(self): }, ) ) - self.assertEqual(span.get_context().trace_state["foo"], "1") + self.assertEqual(span.get_span_context().trace_state["foo"], "1") def test_tracestate_header_with_trailing_comma(self): """Do not propagate invalid trace context. @@ -218,7 +218,7 @@ def test_tracestate_header_with_trailing_comma(self): }, ) ) - self.assertEqual(span.get_context().trace_state["foo"], "1") + self.assertEqual(span.get_span_context().trace_state["foo"], "1") def test_tracestate_keys(self): """Test for valid key patterns in the tracestate @@ -242,9 +242,14 @@ def test_tracestate_keys(self): }, ) ) - self.assertEqual(span.get_context().trace_state["1a-2f@foo"], "bar1") self.assertEqual( - span.get_context().trace_state["1a-_*/2b@foo"], "bar2" + span.get_span_context().trace_state["1a-2f@foo"], "bar1" ) - self.assertEqual(span.get_context().trace_state["foo"], "bar3") - self.assertEqual(span.get_context().trace_state["foo-_*/bar"], "bar4") + self.assertEqual( + span.get_span_context().trace_state["1a-_*/2b@foo"], "bar2" + ) + self.assertEqual(span.get_span_context().trace_state["foo"], "bar3") + self.assertEqual( + span.get_span_context().trace_state["foo-_*/bar"], "bar4" + ) + diff --git a/opentelemetry-api/tests/trace/test_defaultspan.py b/opentelemetry-api/tests/trace/test_defaultspan.py index 67c2fc33521..73f068825b1 100644 --- a/opentelemetry-api/tests/trace/test_defaultspan.py +++ b/opentelemetry-api/tests/trace/test_defaultspan.py @@ -27,9 +27,9 @@ def test_ctor(self): trace_state=trace.DEFAULT_TRACE_STATE, ) span = trace.DefaultSpan(context) - self.assertEqual(context, span.get_context()) + self.assertEqual(context, span.get_span_context()) def test_invalid_span(self): self.assertIsNotNone(trace.INVALID_SPAN) - self.assertIsNotNone(trace.INVALID_SPAN.get_context()) - self.assertFalse(trace.INVALID_SPAN.get_context().is_valid) + self.assertIsNotNone(trace.INVALID_SPAN.get_span_context()) + self.assertFalse(trace.INVALID_SPAN.get_span_context().is_valid) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 77e7262490e..f8b4828f028 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -519,7 +519,7 @@ def to_json(self, indent=4): return json.dumps(f_span, indent=indent) - def get_context(self): + def get_span_context(self): return self.context def set_attribute(self, key: str, value: types.AttributeValue) -> None: @@ -721,7 +721,7 @@ def start_span( # pylint: disable=too-many-locals set_status_on_exception: bool = True, ) -> trace_api.Span: - parent_context = trace_api.get_current_span(context).get_context() + parent_context = trace_api.get_current_span(context).get_span_context() if parent_context is not None and not isinstance( parent_context, trace_api.SpanContext diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/propagation/b3_format.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/propagation/b3_format.py index 813b6e85600..8a6b8e2247c 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/propagation/b3_format.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/propagation/b3_format.py @@ -140,7 +140,7 @@ def inject( ) -> None: span = trace.get_current_span(context=context) - span_context = span.get_context() + span_context = span.get_span_context() if span_context == trace.INVALID_SPAN_CONTEXT: return diff --git a/opentelemetry-sdk/tests/context/test_asyncio.py b/opentelemetry-sdk/tests/context/test_asyncio.py index 4fa653205b0..452915d86c4 100644 --- a/opentelemetry-sdk/tests/context/test_asyncio.py +++ b/opentelemetry-sdk/tests/context/test_asyncio.py @@ -108,4 +108,4 @@ def test_with_asyncio(self): for span in span_list: if span is expected_parent: continue - self.assertEqual(span.parent, expected_parent.get_context()) + self.assertEqual(span.parent, expected_parent.get_span_context()) diff --git a/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py b/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py index b825ea1a755..124d0e23031 100644 --- a/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py +++ b/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py @@ -31,7 +31,7 @@ def get_as_list(dict_object, key): def get_child_parent_new_carrier(old_carrier): ctx = FORMAT.extract(get_as_list, old_carrier) - parent_context = trace_api.get_current_span(ctx).get_context() + parent_context = trace_api.get_current_span(ctx).get_span_context() parent = trace._Span("parent", parent_context) child = trace._Span( @@ -43,7 +43,7 @@ def get_child_parent_new_carrier(old_carrier): trace_flags=parent_context.trace_flags, trace_state=parent_context.trace_state, ), - parent=parent.get_context(), + parent=parent.get_span_context(), ) new_carrier = {} @@ -232,7 +232,7 @@ def test_invalid_single_header(self): """ carrier = {FORMAT.SINGLE_HEADER_KEY: "0-1-2-3-4-5-6-7"} ctx = FORMAT.extract(get_as_list, carrier) - span_context = trace_api.get_current_span(ctx).get_context() + span_context = trace_api.get_current_span(ctx).get_span_context() self.assertEqual(span_context.trace_id, trace_api.INVALID_TRACE_ID) self.assertEqual(span_context.span_id, trace_api.INVALID_SPAN_ID) @@ -244,7 +244,7 @@ def test_missing_trace_id(self): } ctx = FORMAT.extract(get_as_list, carrier) - span_context = trace_api.get_current_span(ctx).get_context() + span_context = trace_api.get_current_span(ctx).get_span_context() self.assertEqual(span_context.trace_id, trace_api.INVALID_TRACE_ID) @patch( @@ -268,7 +268,7 @@ def test_invalid_trace_id( } ctx = FORMAT.extract(get_as_list, carrier) - span_context = trace_api.get_current_span(ctx).get_context() + span_context = trace_api.get_current_span(ctx).get_span_context() self.assertEqual(span_context.trace_id, 1) self.assertEqual(span_context.span_id, 2) @@ -294,7 +294,7 @@ def test_invalid_span_id( } ctx = FORMAT.extract(get_as_list, carrier) - span_context = trace_api.get_current_span(ctx).get_context() + span_context = trace_api.get_current_span(ctx).get_span_context() self.assertEqual(span_context.trace_id, 1) self.assertEqual(span_context.span_id, 2) @@ -307,7 +307,7 @@ def test_missing_span_id(self): } ctx = FORMAT.extract(get_as_list, carrier) - span_context = trace_api.get_current_span(ctx).get_context() + span_context = trace_api.get_current_span(ctx).get_span_context() self.assertEqual(span_context.span_id, trace_api.INVALID_SPAN_ID) @staticmethod diff --git a/opentelemetry-sdk/tests/trace/test_implementation.py b/opentelemetry-sdk/tests/trace/test_implementation.py index 7e6ede1ae03..961e68d9869 100644 --- a/opentelemetry-sdk/tests/trace/test_implementation.py +++ b/opentelemetry-sdk/tests/trace/test_implementation.py @@ -29,11 +29,13 @@ class TestTracerImplementation(unittest.TestCase): def test_tracer(self): tracer = trace.TracerProvider().get_tracer(__name__) with tracer.start_span("test") as span: - self.assertNotEqual(span.get_context(), INVALID_SPAN_CONTEXT) + self.assertNotEqual(span.get_span_context(), INVALID_SPAN_CONTEXT) self.assertNotEqual(span, INVALID_SPAN) self.assertIs(span.is_recording(), True) with tracer.start_span("test2") as span2: - self.assertNotEqual(span2.get_context(), INVALID_SPAN_CONTEXT) + self.assertNotEqual( + span2.get_span_context(), INVALID_SPAN_CONTEXT + ) self.assertNotEqual(span2, INVALID_SPAN) self.assertIs(span2.is_recording(), True) @@ -43,5 +45,5 @@ def test_span(self): span = trace._Span() span = trace._Span("name", INVALID_SPAN_CONTEXT) - self.assertEqual(span.get_context(), INVALID_SPAN_CONTEXT) + self.assertEqual(span.get_span_context(), INVALID_SPAN_CONTEXT) self.assertIs(span.is_recording(), True) diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index a24c47ca54b..32694a5d2c3 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -142,10 +142,12 @@ def test_default_sampler(self): self.assertIsInstance(child_span, trace.Span) self.assertTrue(root_span.context.trace_flags.sampled) self.assertEqual( - root_span.get_context().trace_flags, trace_api.TraceFlags.SAMPLED + root_span.get_span_context().trace_flags, + trace_api.TraceFlags.SAMPLED, ) self.assertEqual( - child_span.get_context().trace_flags, trace_api.TraceFlags.SAMPLED + child_span.get_span_context().trace_flags, + trace_api.TraceFlags.SAMPLED, ) def test_sampler_no_sampling(self): @@ -160,10 +162,12 @@ def test_sampler_no_sampling(self): child_span = tracer.start_span(name="child span", context=ctx) self.assertIsInstance(child_span, trace_api.DefaultSpan) self.assertEqual( - root_span.get_context().trace_flags, trace_api.TraceFlags.DEFAULT + root_span.get_span_context().trace_flags, + trace_api.TraceFlags.DEFAULT, ) self.assertEqual( - child_span.get_context().trace_flags, trace_api.TraceFlags.DEFAULT + child_span.get_span_context().trace_flags, + trace_api.TraceFlags.DEFAULT, ) @@ -253,7 +257,7 @@ def test_start_span_implicit(self): with tracer.start_span( "child", kind=trace_api.SpanKind.CLIENT ) as child: - self.assertIs(child.parent, root.get_context()) + self.assertIs(child.parent, root.get_span_context()) self.assertEqual(child.kind, trace_api.SpanKind.CLIENT) self.assertIsNotNone(child.start_time) @@ -261,8 +265,8 @@ def test_start_span_implicit(self): # The new child span should inherit the parent's context but # get a new span ID. - root_context = root.get_context() - child_context = child.get_context() + root_context = root.get_span_context() + child_context = child.get_span_context() self.assertEqual(root_context.trace_id, child_context.trace_id) self.assertNotEqual( root_context.span_id, child_context.span_id @@ -311,26 +315,28 @@ def test_start_span_explicit(self): # The child's parent should be the one passed in, # not the current span. self.assertNotEqual(child.parent, root) - self.assertIs(child.parent, other_parent.get_context()) + self.assertIs(child.parent, other_parent.get_span_context()) self.assertIsNotNone(child.start_time) self.assertIsNone(child.end_time) # The child should inherit its context from the explicit # parent, not the current span. - child_context = child.get_context() + child_context = child.get_span_context() self.assertEqual( - other_parent.get_context().trace_id, child_context.trace_id + other_parent.get_span_context().trace_id, + child_context.trace_id, ) self.assertNotEqual( - other_parent.get_context().span_id, child_context.span_id + other_parent.get_span_context().span_id, + child_context.span_id, ) self.assertEqual( - other_parent.get_context().trace_state, + other_parent.get_span_context().trace_state, child_context.trace_state, ) self.assertEqual( - other_parent.get_context().trace_flags, + other_parent.get_span_context().trace_flags, child_context.trace_flags, ) @@ -351,7 +357,7 @@ def test_start_as_current_span_implicit(self): with tracer.start_as_current_span("child") as child: self.assertIs(trace_api.get_current_span(), child) - self.assertIs(child.parent, root.get_context()) + self.assertIs(child.parent, root.get_span_context()) # After exiting the child's scope the parent should become the # current span again. @@ -392,7 +398,7 @@ def test_start_as_current_span_explicit(self): # previously-current span. self.assertIs(trace_api.get_current_span(), child) self.assertNotEqual(child.parent, root) - self.assertIs(child.parent, other_parent.get_context()) + self.assertIs(child.parent, other_parent.get_span_context()) # After exiting the child's scope the last span on the stack should # become current, not the child's parent. @@ -571,7 +577,8 @@ def test_sampling_attributes(self): self.assertEqual(root.attributes["sampler-attr"], "sample-val") self.assertEqual(root.attributes["attr-in-both"], "decision-attr") self.assertEqual( - root.get_context().trace_flags, trace_api.TraceFlags.SAMPLED + root.get_span_context().trace_flags, + trace_api.TraceFlags.SAMPLED, ) def test_events(self): diff --git a/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py b/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py index 5be0be9f0ec..fc237fe12b0 100644 --- a/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py +++ b/tests/opentelemetry-docker-tests/tests/mysql/test_mysql_functional.py @@ -68,7 +68,7 @@ def validate_spans(self): self.assertEqual(root_span.name, "rootSpan") self.assertEqual(db_span.name, "mysql.opentelemetry-tests") self.assertIsNotNone(db_span.parent) - self.assertIs(db_span.parent, root_span.get_context()) + self.assertIs(db_span.parent, root_span.get_span_context()) self.assertIs(db_span.kind, trace_api.SpanKind.CLIENT) self.assertEqual(db_span.attributes["db.instance"], MYSQL_DB_NAME) self.assertEqual(db_span.attributes["net.peer.name"], MYSQL_HOST) diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py b/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py index e7a0d39b51e..d76cd702ee6 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_aiopg_functional.py @@ -76,7 +76,7 @@ def validate_spans(self): self.assertEqual(root_span.name, "rootSpan") self.assertEqual(child_span.name, "postgresql.opentelemetry-tests") self.assertIsNotNone(child_span.parent) - self.assertIs(child_span.parent, root_span.get_context()) + self.assertIs(child_span.parent, root_span.get_span_context()) self.assertIs(child_span.kind, trace_api.SpanKind.CLIENT) self.assertEqual( child_span.attributes["db.instance"], POSTGRES_DB_NAME @@ -157,7 +157,7 @@ def validate_spans(self): self.assertEqual(root_span.name, "rootSpan") self.assertEqual(child_span.name, "postgresql.opentelemetry-tests") self.assertIsNotNone(child_span.parent) - self.assertIs(child_span.parent, root_span.get_context()) + self.assertIs(child_span.parent, root_span.get_span_context()) self.assertIs(child_span.kind, trace_api.SpanKind.CLIENT) self.assertEqual( child_span.attributes["db.instance"], POSTGRES_DB_NAME diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py index 27391647818..28db4c064f9 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py @@ -68,7 +68,7 @@ def validate_spans(self): self.assertEqual(root_span.name, "rootSpan") self.assertEqual(child_span.name, "postgresql.opentelemetry-tests") self.assertIsNotNone(child_span.parent) - self.assertIs(child_span.parent, root_span.get_context()) + self.assertIs(child_span.parent, root_span.get_span_context()) self.assertIs(child_span.kind, trace_api.SpanKind.CLIENT) self.assertEqual( child_span.attributes["db.instance"], POSTGRES_DB_NAME diff --git a/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py b/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py index acb60178d06..577477a2aba 100644 --- a/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py +++ b/tests/opentelemetry-docker-tests/tests/pymongo/test_pymongo_functional.py @@ -51,7 +51,7 @@ def validate_spans(self): self.assertIsNot(root_span, None) self.assertIsNot(pymongo_span, None) self.assertIsNotNone(pymongo_span.parent) - self.assertIs(pymongo_span.parent, root_span.get_context()) + self.assertIs(pymongo_span.parent, root_span.get_span_context()) self.assertIs(pymongo_span.kind, trace_api.SpanKind.CLIENT) self.assertEqual( pymongo_span.attributes["db.instance"], MONGODB_DB_NAME diff --git a/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py b/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py index c5c4d4f4497..7c09025551d 100644 --- a/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py +++ b/tests/opentelemetry-docker-tests/tests/pymysql/test_pymysql_functional.py @@ -65,7 +65,7 @@ def validate_spans(self): self.assertEqual(root_span.name, "rootSpan") self.assertEqual(db_span.name, "mysql.opentelemetry-tests") self.assertIsNotNone(db_span.parent) - self.assertIs(db_span.parent, root_span.get_context()) + self.assertIs(db_span.parent, root_span.get_span_context()) self.assertIs(db_span.kind, trace_api.SpanKind.CLIENT) self.assertEqual(db_span.attributes["db.instance"], MYSQL_DB_NAME) self.assertEqual(db_span.attributes["net.peer.name"], MYSQL_HOST) diff --git a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py index 7e6ea2e0446..64984e9c4fa 100644 --- a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py +++ b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py @@ -109,7 +109,7 @@ def test_parent(self): # confirm the parenting self.assertIsNone(parent_span.parent) - self.assertIs(child_span.parent, parent_span.get_context()) + self.assertIs(child_span.parent, parent_span.get_span_context()) self.assertEqual(parent_span.name, "redis_get") self.assertEqual(parent_span.instrumentation_info.name, "redis_svc") diff --git a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py index a438f58eb91..b2d8c0abc51 100644 --- a/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py +++ b/tests/opentelemetry-docker-tests/tests/sqlalchemy_tests/mixins.py @@ -175,7 +175,7 @@ def test_parent(self): # confirm the parenting self.assertIsNone(parent_span.parent) - self.assertIs(child_span.parent, parent_span.get_context()) + self.assertIs(child_span.parent, parent_span.get_span_context()) self.assertEqual(parent_span.name, "sqlalch_op") self.assertEqual(parent_span.instrumentation_info.name, "sqlalch_svc") diff --git a/tests/util/src/opentelemetry/test/mock_textmap.py b/tests/util/src/opentelemetry/test/mock_textmap.py index 92c0f21f0ec..bf46ec32fa1 100644 --- a/tests/util/src/opentelemetry/test/mock_textmap.py +++ b/tests/util/src/opentelemetry/test/mock_textmap.py @@ -84,8 +84,8 @@ def inject( ) -> None: span = trace.get_current_span(context) set_in_carrier( - carrier, self.TRACE_ID_KEY, str(span.get_context().trace_id) + carrier, self.TRACE_ID_KEY, str(span.get_span_context().trace_id) ) set_in_carrier( - carrier, self.SPAN_ID_KEY, str(span.get_context().span_id) + carrier, self.SPAN_ID_KEY, str(span.get_span_context().span_id) ) From c6f52891b678e4ada2a77b4f1686629c17b43d1b Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 7 Oct 2020 08:36:24 -0700 Subject: [PATCH 16/19] rename parent_context to parent_span_context where appropriate --- .../tests/test_datadog_exporter.py | 6 ++-- .../tests/test_datadog_format.py | 34 ++++++++++--------- .../tests/test_jaeger_exporter.py | 6 ++-- .../tests/test_otcollector_trace_exporter.py | 8 ++--- .../tests/test_zipkin_exporter.py | 12 ++++--- .../opentracing_shim/__init__.py | 4 +-- .../src/opentelemetry/sdk/trace/__init__.py | 26 ++++++++------ .../src/opentelemetry/sdk/trace/sampling.py | 16 ++++----- .../tests/trace/propagation/test_b3_format.py | 10 +++--- 9 files changed, 65 insertions(+), 57 deletions(-) diff --git a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py index 27b4d0fa03f..98e894f94d4 100644 --- a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py +++ b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py @@ -178,7 +178,7 @@ def test_translate_to_datadog(self): span_context = trace_api.SpanContext( trace_id, span_id, is_remote=False ) - parent_context = trace_api.SpanContext( + parent_span_context = trace_api.SpanContext( trace_id, parent_id, is_remote=False ) other_context = trace_api.SpanContext( @@ -191,14 +191,14 @@ def test_translate_to_datadog(self): trace._Span( name=span_names[0], context=span_context, - parent=parent_context, + parent=parent_span_context, kind=trace_api.SpanKind.CLIENT, instrumentation_info=instrumentation_info, resource=Resource({}), ), trace._Span( name=span_names[1], - context=parent_context, + context=parent_span_context, parent=None, instrumentation_info=instrumentation_info, resource=resource_without_service, diff --git a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py index 18409c7a6f8..8480374471b 100644 --- a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py +++ b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py @@ -79,7 +79,7 @@ def test_missing_parent_id(self): def test_context_propagation(self): """Test the propagation of Datadog headers.""" - parent_context = get_current_span( + parent_span_context = get_current_span( FORMAT.extract( get_as_list, { @@ -92,28 +92,28 @@ def test_context_propagation(self): ).get_span_context() self.assertEqual( - parent_context.trace_id, int(self.serialized_trace_id) + parent_span_context.trace_id, int(self.serialized_trace_id) ) self.assertEqual( - parent_context.span_id, int(self.serialized_parent_id) + parent_span_context.span_id, int(self.serialized_parent_id) ) - self.assertEqual(parent_context.trace_flags, constants.AUTO_KEEP) + self.assertEqual(parent_span_context.trace_flags, constants.AUTO_KEEP) self.assertEqual( - parent_context.trace_state.get(constants.DD_ORIGIN), + parent_span_context.trace_state.get(constants.DD_ORIGIN), self.serialized_origin, ) - self.assertTrue(parent_context.is_remote) + self.assertTrue(parent_span_context.is_remote) child = trace._Span( "child", trace_api.SpanContext( - parent_context.trace_id, + parent_span_context.trace_id, trace_api.RandomIdsGenerator().generate_span_id(), is_remote=False, - trace_flags=parent_context.trace_flags, - trace_state=parent_context.trace_state, + trace_flags=parent_span_context.trace_flags, + trace_state=parent_span_context.trace_state, ), - parent=parent_context, + parent=parent_span_context, ) child_carrier = {} @@ -136,7 +136,7 @@ def test_context_propagation(self): def test_sampling_priority_auto_reject(self): """Test sampling priority rejected.""" - parent_context = get_current_span( + parent_span_context = get_current_span( FORMAT.extract( get_as_list, { @@ -147,18 +147,20 @@ def test_sampling_priority_auto_reject(self): ) ).get_span_context() - self.assertEqual(parent_context.trace_flags, constants.AUTO_REJECT) + self.assertEqual( + parent_span_context.trace_flags, constants.AUTO_REJECT + ) child = trace._Span( "child", trace_api.SpanContext( - parent_context.trace_id, + parent_span_context.trace_id, trace_api.RandomIdsGenerator().generate_span_id(), is_remote=False, - trace_flags=parent_context.trace_flags, - trace_state=parent_context.trace_state, + trace_flags=parent_span_context.trace_flags, + trace_state=parent_span_context.trace_state, ), - parent=parent_context, + parent=parent_span_context, ) child_carrier = {} diff --git a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py index bb4920f7b3d..0a01bcb2347 100644 --- a/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py +++ b/exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py @@ -144,7 +144,7 @@ def test_translate_to_jaeger(self): span_context = trace_api.SpanContext( trace_id, span_id, is_remote=False ) - parent_context = trace_api.SpanContext( + parent_span_context = trace_api.SpanContext( trace_id, parent_id, is_remote=False ) other_context = trace_api.SpanContext( @@ -190,13 +190,13 @@ def test_translate_to_jaeger(self): trace._Span( name=span_names[0], context=span_context, - parent=parent_context, + parent=parent_span_context, events=(event,), links=(link,), kind=trace_api.SpanKind.CLIENT, ), trace._Span( - name=span_names[1], context=parent_context, parent=None + name=span_names[1], context=parent_span_context, parent=None ), trace._Span( name=span_names[2], context=other_context, parent=None diff --git a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py index bc07b1b0e15..c49310b30a6 100644 --- a/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py +++ b/exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py @@ -96,7 +96,7 @@ def test_translate_to_collector(self): trace_flags=TraceFlags(TraceFlags.SAMPLED), trace_state=trace_api.TraceState({"testKey": "testValue"}), ) - parent_context = trace_api.SpanContext( + parent_span_context = trace_api.SpanContext( trace_id, parent_id, is_remote=False ) other_context = trace_api.SpanContext( @@ -118,19 +118,19 @@ def test_translate_to_collector(self): context=other_context, attributes=link_attributes ) link_2 = trace_api.Link( - context=parent_context, attributes=link_attributes + context=parent_span_context, attributes=link_attributes ) span_1 = trace._Span( name="test1", context=span_context, - parent=parent_context, + parent=parent_span_context, events=(event,), links=(link_1,), kind=trace_api.SpanKind.CLIENT, ) span_2 = trace._Span( name="test2", - context=parent_context, + context=parent_span_context, parent=None, kind=trace_api.SpanKind.SERVER, ) diff --git a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py index 8d6d8bb8604..c3098da8847 100644 --- a/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py +++ b/exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py @@ -127,7 +127,7 @@ def test_export(self): is_remote=False, trace_flags=TraceFlags(TraceFlags.SAMPLED), ) - parent_context = trace_api.SpanContext( + parent_span_context = trace_api.SpanContext( trace_id, parent_id, is_remote=False ) other_context = trace_api.SpanContext( @@ -157,12 +157,12 @@ def test_export(self): trace._Span( name=span_names[0], context=span_context, - parent=parent_context, + parent=parent_span_context, events=(event,), links=(link,), ), trace._Span( - name=span_names[1], context=parent_context, parent=None + name=span_names[1], context=parent_span_context, parent=None ), trace._Span( name=span_names[2], context=other_context, parent=None @@ -328,12 +328,14 @@ def test_zero_padding(self): is_remote=False, trace_flags=TraceFlags(TraceFlags.SAMPLED), ) - parent_context = trace_api.SpanContext( + parent_span_context = trace_api.SpanContext( trace_id, parent_id, is_remote=False ) otel_span = trace._Span( - name=span_names[0], context=span_context, parent=parent_context, + name=span_names[0], + context=span_context, + parent=parent_span_context, ) otel_span.start(start_time=start_time) 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 a7cfb28b6f8..63be13fe489 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 @@ -633,7 +633,7 @@ def start_span( if isinstance(parent, OtelSpanContext): parent = DefaultSpan(parent) - parent_context = set_span_in_context(parent) + parent_span_context = set_span_in_context(parent) links = [] if references: @@ -649,7 +649,7 @@ def start_span( span = self._otel_tracer.start_span( operation_name, - context=parent_context, + context=parent_span_context, links=links, attributes=tags, start_time=start_time_ns, diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index f8b4828f028..d0626a65687 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -721,22 +721,26 @@ def start_span( # pylint: disable=too-many-locals set_status_on_exception: bool = True, ) -> trace_api.Span: - parent_context = trace_api.get_current_span(context).get_span_context() + parent_span_context = trace_api.get_current_span( + context + ).get_span_context() - if parent_context is not None and not isinstance( - parent_context, trace_api.SpanContext + if parent_span_context is not None and not isinstance( + parent_span_context, trace_api.SpanContext ): - raise TypeError("parent_context must be a SpanContext or None.") + raise TypeError( + "parent_span_context must be a SpanContext or None." + ) - if parent_context is None or not parent_context.is_valid: - parent_context = None + if parent_span_context is None or not parent_span_context.is_valid: + parent_span_context = None trace_id = self.source.ids_generator.generate_trace_id() trace_flags = None trace_state = None else: - trace_id = parent_context.trace_id - trace_flags = parent_context.trace_flags - trace_state = parent_context.trace_state + trace_id = parent_span_context.trace_id + trace_flags = parent_span_context.trace_flags + trace_state = parent_span_context.trace_state # The sampler decides whether to create a real or no-op span at the # time of span creation. No-op spans do not record events, and are not @@ -744,7 +748,7 @@ def start_span( # pylint: disable=too-many-locals # The sampler may also add attributes to the newly-created span, e.g. # to include information about the sampling result. sampling_result = self.source.sampler.should_sample( - parent_context, trace_id, name, attributes, links, + parent_span_context, trace_id, name, attributes, links, ) trace_flags = ( @@ -766,7 +770,7 @@ def start_span( # pylint: disable=too-many-locals span = _Span( name=name, context=context, - parent=parent_context, + parent=parent_span_context, sampler=self.source.sampler, resource=self.source.resource, attributes=sampling_result.attributes.copy(), diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py index c40d3e691ee..7a1e10752ea 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py @@ -113,7 +113,7 @@ class Sampler(abc.ABC): @abc.abstractmethod def should_sample( self, - parent_context: Optional["SpanContext"], + parent_span_context: Optional["SpanContext"], trace_id: int, name: str, attributes: Attributes = None, @@ -134,7 +134,7 @@ def __init__(self, decision: "Decision"): def should_sample( self, - parent_context: Optional["SpanContext"], + parent_span_context: Optional["SpanContext"], trace_id: int, name: str, attributes: Attributes = None, @@ -188,7 +188,7 @@ def bound(self) -> int: def should_sample( self, - parent_context: Optional["SpanContext"], + parent_span_context: Optional["SpanContext"], trace_id: int, name: str, attributes: Attributes = None, # TODO @@ -220,22 +220,22 @@ def __init__(self, delegate: Sampler): def should_sample( self, - parent_context: Optional["SpanContext"], + parent_span_context: Optional["SpanContext"], trace_id: int, name: str, attributes: Attributes = None, # TODO links: Sequence["Link"] = (), ) -> "SamplingResult": - if parent_context is not None: + if parent_span_context is not None: if ( - not parent_context.is_valid - or not parent_context.trace_flags.sampled + not parent_span_context.is_valid + or not parent_span_context.trace_flags.sampled ): return SamplingResult(Decision.DROP) return SamplingResult(Decision.RECORD_AND_SAMPLE, attributes) return self._delegate.should_sample( - parent_context=parent_context, + parent_span_context=parent_span_context, trace_id=trace_id, name=name, attributes=attributes, diff --git a/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py b/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py index 124d0e23031..a788a812c76 100644 --- a/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py +++ b/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py @@ -31,17 +31,17 @@ def get_as_list(dict_object, key): def get_child_parent_new_carrier(old_carrier): ctx = FORMAT.extract(get_as_list, old_carrier) - parent_context = trace_api.get_current_span(ctx).get_span_context() + parent_span_context = trace_api.get_current_span(ctx).get_span_context() - parent = trace._Span("parent", parent_context) + parent = trace._Span("parent", parent_span_context) child = trace._Span( "child", trace_api.SpanContext( - parent_context.trace_id, + parent_span_context.trace_id, trace_api.RandomIdsGenerator().generate_span_id(), is_remote=False, - trace_flags=parent_context.trace_flags, - trace_state=parent_context.trace_state, + trace_flags=parent_span_context.trace_flags, + trace_state=parent_span_context.trace_state, ), parent=parent.get_span_context(), ) From 2585e3f00d2a31afc7a1dfd9d29d059671eecadd Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 7 Oct 2020 09:03:43 -0700 Subject: [PATCH 17/19] fix test --- opentelemetry-sdk/tests/trace/test_trace.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 32694a5d2c3..d4f2b7293f3 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -289,7 +289,7 @@ def test_start_span_implicit(self): def test_start_span_explicit(self): tracer = new_tracer() - other_parent = trace.Span( + other_parent = trace._Span( "name", trace_api.SpanContext( trace_id=0x000000000000000000000000DEADBEEF, @@ -370,7 +370,7 @@ def test_start_as_current_span_implicit(self): def test_start_as_current_span_explicit(self): tracer = new_tracer() - other_parent = trace.Span( + other_parent = trace._Span( "name", trace_api.SpanContext( trace_id=0x000000000000000000000000DEADBEEF, From 6a910fa182ec783e383b51d63dbce43209e9ff89 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 7 Oct 2020 09:44:24 -0700 Subject: [PATCH 18/19] fix lint --- opentelemetry-sdk/tests/trace/test_trace.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index d4f2b7293f3..6a0399c28cd 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=too-many-lines import shutil import subprocess import unittest From bf512da5f41dd61b4d7ec10a73fceb4823cf2341 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Wed, 7 Oct 2020 18:09:07 -0700 Subject: [PATCH 19/19] fix lint --- .../tests/trace/propagation/test_tracecontexthttptextformat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/opentelemetry-api/tests/trace/propagation/test_tracecontexthttptextformat.py b/opentelemetry-api/tests/trace/propagation/test_tracecontexthttptextformat.py index 9e187e9398a..295e3971a39 100644 --- a/opentelemetry-api/tests/trace/propagation/test_tracecontexthttptextformat.py +++ b/opentelemetry-api/tests/trace/propagation/test_tracecontexthttptextformat.py @@ -252,4 +252,3 @@ def test_tracestate_keys(self): self.assertEqual( span.get_span_context().trace_state["foo-_*/bar"], "bar4" ) -