Skip to content

Commit

Permalink
translate_span: Make assert more specific
Browse files Browse the repository at this point in the history
Before this commit, the assert in translate_span would now allow for a
duration_ms of `0`. This usually makes sense, but what the assert seems
to actually be for, is to check whether duration_ms has been set (that
is, somebody has run .finished() on the Span).

This fixes the assert to check that duration_ms is not None, which has
the nice side-effect that it allows for Spans to be created+finished in
a unittest setting where freezegun.freeze_time() is activated.
  • Loading branch information
torarvid committed Mar 11, 2025
1 parent 574cfa4 commit 2dd9e94
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion troncos/tracing/_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def translate_span(
dd_span: DDSpan, default_resource: Resource, ignore_attrs: set[str]
) -> ReadableSpan:
"""Transelate a ddtrace span to an OTEL span."""
assert dd_span.duration_ns, "Span not finished."
assert dd_span.duration_ns is not None, "Span not finished."

status, events, attributes = _span_status_and_attributes(
dd_span, ignore_attrs=ignore_attrs
Expand Down

0 comments on commit 2dd9e94

Please sign in to comment.