Skip to content

Commit

Permalink
Fix opentracing shim references (#2180)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsben authored Oct 19, 2021
1 parent 6b38689 commit 9b25d74
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Propagation: only warn about oversized baggage headers when headers exist
([#2212](https://github.com/open-telemetry/opentelemetry-python/pull/2212))

- Fix parental trace relationship for opentracing `follows_from` reference
([#2180](https://github.com/open-telemetry/opentelemetry-python/pull/2180))


## [1.6.0-0.25b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.6.0-0.25b0) - 2021-10-13


Expand Down Expand Up @@ -51,6 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add name to `BatchSpanProcessor` worker thread
([#2186](https://github.com/open-telemetry/opentelemetry-python/pull/2186))


## [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,16 @@ 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(Link(ref.referenced_context.unwrap()))

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

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 All @@ -666,7 +673,7 @@ def start_span(
span = self._otel_tracer.start_span(
operation_name,
context=parent_span_context,
links=links,
links=valid_links,
attributes=tags,
start_time=start_time_ns,
)
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

0 comments on commit 9b25d74

Please sign in to comment.