Skip to content

Commit a187b2a

Browse files
committed
fix(traces): keep a falsy status message set by before_span_send
A message of 0 or False was dropped, and one whose truth test raises took the whole span with it. Only None now means no message, as in set_status.
1 parent fe734e7 commit a187b2a

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

posthog/test/tracing/test_pipeline.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,15 @@ def long_message(span):
879879
pipeline.start_span("a").end()
880880
assert queued(pipeline)[0].status.message == "mmmmm"
881881

882+
def test_keeps_a_falsy_status_message_the_hook_sets(self):
883+
def zero_message(span):
884+
span["status"] = {"code": "error", "message": 0}
885+
return span
886+
887+
pipeline, _, _ = make(before_span_send=zero_message)
888+
pipeline.start_span("a").end()
889+
assert queued(pipeline)[0].status.message == "0"
890+
882891
def test_a_status_message_whose_str_raises_keeps_the_span(self):
883892
class Hostile:
884893
def __str__(self):

posthog/tracing/_before_span_send.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def _hook_status(value: Any, original: Optional[SpanStatus]) -> Optional[SpanSta
190190
return None
191191
if isinstance(value, Mapping) and value.get("code") in ("ok", "error"):
192192
message = value.get("message")
193-
return SpanStatus(value["code"], safe_str(message) if message else None)
193+
text = None if message is None else safe_str(message)
194+
return SpanStatus(value["code"], text or None)
194195
# An unknown code would lose an error the span really had.
195196
log.debug("before_span_send set an unknown span status; keeping the original")
196197
return original

0 commit comments

Comments
 (0)