Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: [SVLS-5265] add span links to encoded spans #10850

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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: 3 additions & 0 deletions ddtrace/internal/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def _span_to_dict(span):
if span.span_type:
d["type"] = span.span_type

if span._links:
d["span_links"] = [link.to_dict() for link in span._links]

return d


Expand Down
19 changes: 19 additions & 0 deletions tests/integration/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,22 @@ def test_trace_with_metrics_accepted_by_agent(self, metrics):
tracer.shutdown()
log.warning.assert_not_called()
log.error.assert_not_called()

@pytest.mark.parametrize(
"span_links_kwargs",
[
{"trace_id": 12345, "span_id": 67890},
],
)
def test_trace_with_links_accepted_by_agent(self, span_links_kwargs):
"""The agent does not return an error code when accepting a trace payload containing span links."""
tracer = Tracer()
with mock.patch("ddtrace.internal.writer.writer.log") as log:
with tracer.trace("root", service="test_encoding", resource="test_resource") as root:
root.set_link(**span_links_kwargs)
for _ in range(999):
with tracer.trace("child") as child:
child.set_link(**span_links_kwargs)
tracer.shutdown()
log.warning.assert_not_called()
log.error.assert_not_called()
6 changes: 4 additions & 2 deletions tests/tracer/test_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_encode_traces_json(self):
# test encoding for JSON format
traces = [
[
Span(name="client.testing"),
Span(name="client.testing", links=[SpanLink(trace_id=12345, span_id=678990)]),
Span(name="client.testing"),
],
[
Expand All @@ -184,6 +184,7 @@ def test_encode_traces_json(self):
assert isinstance(spans, str)
assert len(items) == 3
assert len(items[0]) == 2
assert len(items[0][0]["span_links"]) == 1
assert len(items[1]) == 2
assert len(items[2]) == 2
for i in range(3):
Expand All @@ -194,7 +195,7 @@ def test_encode_traces_json_v2(self):
# test encoding for JSON format
traces = [
[
Span(name="client.testing", span_id=0xAAAAAA),
Span(name="client.testing", span_id=0xAAAAAA, links=[SpanLink(trace_id=12345, span_id=67890)]),
Span(name="client.testing", span_id=0xAAAAAA),
],
[
Expand All @@ -215,6 +216,7 @@ def test_encode_traces_json_v2(self):
assert isinstance(spans, str)
assert len(items) == 3
assert len(items[0]) == 2
assert len(items[0][0]["span_links"]) == 1
assert len(items[1]) == 2
assert len(items[2]) == 2
for i in range(3):
Expand Down
Loading