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

Commit

Permalink
Don't validate parent type
Browse files Browse the repository at this point in the history
Validating the parent type complicates the logic of `start_span()`.
Since the OpenTracing API clearly specifies the valid types for a
parent span, it's the user's responsibility to specify a valid
parent.
  • Loading branch information
johananl committed Oct 18, 2019
1 parent 5e39956 commit bb25401
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,34 +222,13 @@ def start_span(
start_time=None,
ignore_active_span=False,
):
if child_of is None:
parent = None
else:
if isinstance(child_of, (SpanShim, SpanContextShim)):
# The parent specified in `child_of` is valid and is either a
# `SpanShim` or a `SpanContextShim`. Unwrap the `Span` or
# `SpanContext` to extract the OpenTracing object and use this
# object as the parent of the created span.
parent = child_of.unwrap()
else:
logger.warning(
"Unknown class %s passed in child_of argument to start_span() method.",
type(child_of),
)
parent = None
# TODO: Refuse to create a span and return `None` instead of
# proceeding with a `None` parent? This would cause the created
# span to become a child of the active span, if any, or create
# a new trace and make the span the root span of that trace.

# Use active span as parent when no explicit parent is specified.
if (
not parent
and not ignore_active_span
and self.active_span is not None
):
parent = self.active_span.unwrap()
if not ignore_active_span and not child_of:
child_of = self.active_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
span = self._otel_tracer.create_span(operation_name, parent)

if references:
Expand Down
12 changes: 0 additions & 12 deletions ext/opentelemetry-ext-opentracing-shim/tests/test_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,6 @@ def test_parent_child_explicit_span_context(self):
child.unwrap().parent, parent.context.unwrap()
)

def test_parent_child_explicit_invalid(self):
"""Test span creation with an explicit parent of an invalid type."""

with self.shim.start_active_span("ParentSpan") as parent:
with self.shim.start_active_span(
"ChildSpan", child_of=object
) as child:
# Verify span was created as a child of the active span.
self.assertEqual(
child.span.unwrap().parent, parent.span.unwrap()
)

def test_references(self):
"""Test span creation using the `references` argument."""

Expand Down

0 comments on commit bb25401

Please sign in to comment.