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

Commit

Permalink
Handle explicit end time when ending spans
Browse files Browse the repository at this point in the history
  • Loading branch information
johananl committed Oct 7, 2019
1 parent 58aeee1 commit e3ce0fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 5 additions & 6 deletions opentracing-shim/src/opentracingshim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ def set_operation_name(self, operation_name):
self._otel_span.update_name(operation_name)
return self

def finish(self, finish_time=None):
self._otel_span.end()
# TODO: Handle finish_time. The OpenTelemetry API doesn't currently
# support setting end time on a span and we cannot assume that all
# OpenTelemetry Tracer implementations have an `end_time` field.
# https://github.com/open-telemetry/opentelemetry-python/issues/134
def finish(self, finish_time: float = None):
end_time = finish_time
if end_time is not None:
end_time = util.time_seconds_to_ns(finish_time)
self._otel_span.end(end_time=end_time)

def set_tag(self, key, value):
self._otel_span.set_attribute(key, value)
Expand Down
10 changes: 10 additions & 0 deletions opentracing-shim/tests/test_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ def test_explicit_start_time(self):
result = util.time_seconds_from_ns(scope.span.unwrap().start_time)
self.assertEqual(result, now)

def test_explicit_end_time(self):
"""Test `end_time` argument of `finish()` method."""

span = self.shim.start_span("TestSpan")
now = time.time()
span.finish(now)

end_time = util.time_seconds_from_ns(span.unwrap().end_time)
self.assertEqual(end_time, now)

def test_explicit_span_activation(self):
"""Test manual activation and deactivation of a span."""

Expand Down

0 comments on commit e3ce0fd

Please sign in to comment.