Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opentracing shim references #2180

Merged
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2145](https://github.com/open-telemetry/opentelemetry-python/pull/2145))
- Add `schema_url` to `TracerProvider.get_tracer`
([#2154](https://github.com/open-telemetry/opentelemetry-python/pull/2154))
- Fix parental trace relationship for opentracing `follows_from` reference
([#2180](https://github.com/open-telemetry/opentelemetry-python/pull/2180))

## [1.5.0-0.24b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.5.0-0.24b0) - 2021-08-26

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,10 @@ def start_active_span(

current_span = get_current_span()

if child_of is None and current_span is not INVALID_SPAN_CONTEXT:
if (
child_of is None
and current_span.get_span_context() is not INVALID_SPAN_CONTEXT
):
child_of = SpanShim(None, None, current_span)

span = self.start_span(
Expand Down Expand Up @@ -649,12 +652,20 @@ def start_span(
if isinstance(parent, OtelSpanContext):
parent = NonRecordingSpan(parent)

parent_span_context = set_span_in_context(parent)

links = []
valid_links = []
if references:
for ref in references:
links.append(Link(ref.referenced_context.unwrap()))
if ref.referenced_context.unwrap() is not INVALID_SPAN_CONTEXT:
valid_links.append(ref)
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved

if valid_links and parent is None:
parent = NonRecordingSpan(
valid_links[0].referenced_context.unwrap()
)

parent_span_context = set_span_in_context(parent)

# The OpenTracing API expects time values to be `float` values which
# represent the number of seconds since the epoch. OpenTelemetry
Expand Down
18 changes: 18 additions & 0 deletions shim/opentelemetry-opentracing-shim/tests/test_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,24 @@ def test_references(self):
parent.context.unwrap(),
)

def test_follows_from_references(self):
"""Test span creation using the `references` argument with a follows from relationship."""

with self.shim.start_span("ParentSpan") as parent:
ref = opentracing.follows_from(parent.context)

with self.shim.start_active_span(
"FollowingSpan", references=[ref]
) as child:
self.assertEqual(
child.span.unwrap().links[0].context,
parent.context.unwrap(),
)
self.assertEqual(
child.span.unwrap().parent,
parent.context.unwrap(),
)

def test_set_operation_name(self):
"""Test `set_operation_name()` method."""

Expand Down