Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ddtrace/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ def finished(self, value):

@property
def duration(self):
# type: () -> Optional[float]
"""The span duration in seconds."""
if self.duration_ns is not None:
return self.duration_ns / 1e9
# TODO: add return None if self.duration_ns is None
return None

@duration.setter
def duration(self, value):
Expand Down
4 changes: 4 additions & 0 deletions tests/tracer/test_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def test_setter_casts_duration_ns_as_int(self):
assert s.duration_ns == 3200000000
assert isinstance(s.duration_ns, int)

def test_get_span_returns_none_by_default(self):
s = Span(tracer=None, name="test.span")
assert s.duration is None

def test_traceback_with_error(self):
s = Span(None, "test.span")
try:
Expand Down