Skip to content

Commit acfa565

Browse files
committed
fix(testing): Fix JSON span link decoding
1 parent 8f7defe commit acfa565

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎utils/test-agent-utils/decoder/src/main/java/datadog/trace/test/agent/decoder/json/raw/SpanJson.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public List<DecodedSpanLink> getLinks() {
132132
* submitted a {@code v1.0} payload) and from the meta tag otherwise.
133133
*/
134134
void resolveLinks() {
135-
if (this.spanLinks == null || this.spanLinks.isEmpty()) {
135+
if (this.spanLinks == null) {
136136
this.links = DecodedSpanLinks.fromMeta(getMeta());
137137
return;
138138
}

‎utils/test-agent-utils/decoder/src/test/java/datadog/trace/test/agent/decoder/SpanLinksDecoderTest.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,23 @@ void structuredSpanLinksFieldWinsOverTheMetaTag() {
202202
assertEquals(7L, span.getLinks().get(0).getSpanId(), "the structured field is preferred");
203203
}
204204

205+
@Test
206+
void anEmptyStructuredSpanLinksFieldWinsOverTheMetaTag() {
207+
// A v1.0 payload always carries the span_links field, so an empty one means the span has no
208+
// link, whichever legacy meta tag the payload also holds.
209+
String json =
210+
"[[{\"service\":\"s\",\"name\":\"n\",\"resource\":\"r\","
211+
+ "\"trace_id\":1,\"span_id\":1,\"parent_id\":0,\"start\":0,\"duration\":1,\"error\":0,"
212+
+ "\"metrics\":{},\"meta\":{\""
213+
+ SPAN_LINKS_TAG
214+
+ "\":\"[{\\\"trace_id\\\":\\\"1\\\",\\\"span_id\\\":\\\"99\\\"}]\"},"
215+
+ "\"span_links\":[]}]]";
216+
217+
DecodedSpan span = Decoder.decodeJson(json).getTraces().get(0).getSpans().get(0);
218+
219+
assertTrue(span.getLinks().isEmpty(), "the structured field is preferred, even when empty");
220+
}
221+
205222
@Test
206223
void decodedSpanWithoutTheTagExposesNoLink() {
207224
String json =

0 commit comments

Comments
 (0)