Skip to content

Commit

Permalink
SDK Tracer treats invalid span parent like null
Browse files Browse the repository at this point in the history
Fixes open-telemetry#233. The SDK tracer will now create spans with invalid parents
as brand new spans, similar to not having a parent at all.

Adding this behavior to the Tracer ensures that integrations do not have
to handle invalid span contexts in their own code, and ensures that behavior
is consistent with w3c tracecontext (which specifies invalid results should
be handled by creating new spans).
  • Loading branch information
toumorokoshi committed Oct 24, 2019
1 parent 5c89850 commit 84c8cf5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ def test_sampler_no_sampling(self):


class TestSpanCreation(unittest.TestCase):
def test_create_span_invalid_spancontext(self):
"""If an invalid span context is passed as the parent, the created
span should use a new span id.
"""
tracer = trace.Tracer("test_create_span_invalid_spancontext")
new_span = tracer.create_span(
"root", parent=trace_api.INVALID_SPAN_CONTEXT
)
self.assertNotEqual(
new_span.context.span_id, trace_api.INVALID_SPAN_ID
)

def test_start_span_implicit(self):
tracer = trace.Tracer("test_start_span_implicit")

Expand Down

0 comments on commit 84c8cf5

Please sign in to comment.