diff --git a/ddtrace/_trace/_span_pointer.py b/ddtrace/_trace/_span_pointer.py index e430f746025..cad57bfcda5 100644 --- a/ddtrace/_trace/_span_pointer.py +++ b/ddtrace/_trace/_span_pointer.py @@ -64,7 +64,8 @@ def __post_init__(self): def __repr__(self): return ( f"SpanPointer(trace_id={self.trace_id}, span_id={self.span_id}, kind={self.kind}, " - f"direction={self.direction}, hash={self.hash}, attributes={self.attributes})" + f"direction={self.attributes.get('ptr.dir')}, hash={self.attributes.get('ptr.hash')}, " + f"attributes={self.attributes})" ) diff --git a/releasenotes/notes/fix-spanpointer-repr-565ebb8e6679ebde.yaml b/releasenotes/notes/fix-spanpointer-repr-565ebb8e6679ebde.yaml new file mode 100644 index 00000000000..1ac54b64073 --- /dev/null +++ b/releasenotes/notes/fix-spanpointer-repr-565ebb8e6679ebde.yaml @@ -0,0 +1,3 @@ +fixes: + - | + tracing: Fixes a bug where calling __repr__ on SpanPointer objected raised an AttributeError. This caused aws_lambdas to crash when debug logging was enabled. diff --git a/tests/tracer/test_span.py b/tests/tracer/test_span.py index 0b18307c93d..617601bf1c9 100644 --- a/tests/tracer/test_span.py +++ b/tests/tracer/test_span.py @@ -855,6 +855,7 @@ def test_span_pprint(): root.set_metric("m", 1.0) root._add_event("message", {"importance": 10}, 16789898242) root.set_link(trace_id=99, span_id=10, attributes={"link.name": "s1_to_s2", "link.kind": "scheduled_by"}) + root._add_span_pointer("test_kind", _SpanPointerDirection.DOWNSTREAM, "test_hash_123", {"extra": "attr"}) root.finish() actual = root._pprint() @@ -867,9 +868,11 @@ def test_span_pprint(): assert "metrics={'m': 1.0}" in actual assert "events=[SpanEvent(name='message', time=16789898242, attributes={'importance': 10})]" in actual assert ( - "[SpanLink(trace_id=99, span_id=10, attributes={'link.name': 's1_to_s2', 'link.kind': 'scheduled_by'}, " - "tracestate=None, flags=None, dropped_attributes=0)]" + "SpanLink(trace_id=99, span_id=10, attributes={'link.name': 's1_to_s2', 'link.kind': 'scheduled_by'}, " + "tracestate=None, flags=None, dropped_attributes=0)" ) in actual + assert "SpanPointer(trace_id=0, span_id=0, kind=span-pointer" in actual + assert "direction=d, hash=test_hash_123" in actual assert ( f"context=Context(trace_id={root.trace_id}, span_id={root.span_id}, _meta={{}}, " "_metrics={}, _span_links=[], _baggage={}, _is_remote=False)"