Skip to content

Commit 2b8bd63

Browse files
authored
fix(tracing): span pointer __repr__ (#14539)
## What's the issue In the _SpanPointer.__repr__ method, it's trying to access self.direction and self.hash, but these attributes don't exist on the object. The _SpanPointer class: 1. It inherits from SpanLink 2. The direction and hash information are stored in the attributes dictionary as "ptr.dir" and "ptr.hash" Therefore the fix. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent 08ae31e commit 2b8bd63

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

ddtrace/_trace/_span_pointer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def __post_init__(self):
6464
def __repr__(self):
6565
return (
6666
f"SpanPointer(trace_id={self.trace_id}, span_id={self.span_id}, kind={self.kind}, "
67-
f"direction={self.direction}, hash={self.hash}, attributes={self.attributes})"
67+
f"direction={self.attributes.get('ptr.dir')}, hash={self.attributes.get('ptr.hash')}, "
68+
f"attributes={self.attributes})"
6869
)
6970

7071

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fixes:
2+
- |
3+
tracing: Fixes a bug where calling __repr__ on SpanPointer objected raised an AttributeError. This caused aws_lambdas to crash when debug logging was enabled.

tests/tracer/test_span.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ def test_span_pprint():
872872
root.set_metric("m", 1.0)
873873
root._add_event("message", {"importance": 10}, 16789898242)
874874
root.set_link(trace_id=99, span_id=10, attributes={"link.name": "s1_to_s2", "link.kind": "scheduled_by"})
875+
root._add_span_pointer("test_kind", _SpanPointerDirection.DOWNSTREAM, "test_hash_123", {"extra": "attr"})
875876

876877
root.finish()
877878
actual = root._pprint()
@@ -884,9 +885,11 @@ def test_span_pprint():
884885
assert "metrics={'m': 1.0}" in actual
885886
assert "events=[SpanEvent(name='message', time=16789898242, attributes={'importance': 10})]" in actual
886887
assert (
887-
"[SpanLink(trace_id=99, span_id=10, attributes={'link.name': 's1_to_s2', 'link.kind': 'scheduled_by'}, "
888-
"tracestate=None, flags=None, dropped_attributes=0)]"
888+
"SpanLink(trace_id=99, span_id=10, attributes={'link.name': 's1_to_s2', 'link.kind': 'scheduled_by'}, "
889+
"tracestate=None, flags=None, dropped_attributes=0)"
889890
) in actual
891+
assert "SpanPointer(trace_id=0, span_id=0, kind=span-pointer" in actual
892+
assert "direction=d, hash=test_hash_123" in actual
890893
assert (
891894
f"context=Context(trace_id={root.trace_id}, span_id={root.span_id}, _meta={{}}, "
892895
"_metrics={}, _span_links=[], _baggage={}, _is_remote=False)"

0 commit comments

Comments
 (0)