Skip to content

Commit 882350a

Browse files
Top level.
1 parent c86443e commit 882350a

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

dd-trace-core/src/main/java/datadog/trace/common/writer/ddagent/TraceMapperV1.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import datadog.trace.api.TagMap;
1818
import datadog.trace.api.sampling.SamplingMechanism;
1919
import datadog.trace.bootstrap.instrumentation.api.AgentSpanLink;
20+
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags;
2021
import datadog.trace.bootstrap.instrumentation.api.Tags;
2122
import datadog.trace.common.writer.Payload;
2223
import datadog.trace.core.CoreSpan;
@@ -358,6 +359,7 @@ private void encodeSpanAttributes(
358359
String httpStatusCode =
359360
meta.getHttpStatusCode() == null ? null : meta.getHttpStatusCode().toString();
360361
boolean writeHttpStatus = httpStatusCode != null && tags.getString(HTTP_STATUS) == null;
362+
boolean writeTopLevel = meta.topLevel();
361363
int tagCount = 0;
362364
for (TagMap.EntryReader entry : tags) {
363365
if (!DDTags.SPAN_EVENTS.equals(entry.tag())) {
@@ -367,7 +369,12 @@ private void encodeSpanAttributes(
367369

368370
writable.writeInt(fieldId);
369371
writable.startArray(
370-
(baggage.size() + tagCount + metaStruct.size() + (writeHttpStatus ? 1 : 0)) * 3);
372+
(tagCount
373+
+ baggage.size()
374+
+ metaStruct.size()
375+
+ (writeHttpStatus ? 1 : 0)
376+
+ (writeTopLevel ? 1 : 0))
377+
* 3);
371378

372379
for (Map.Entry<String, String> entry : baggage.entrySet()) {
373380
writeAttribute(writable, entry.getKey(), entry.getValue());
@@ -382,6 +389,9 @@ private void encodeSpanAttributes(
382389
if (writeHttpStatus) {
383390
writeAttribute(writable, HTTP_STATUS, httpStatusCode);
384391
}
392+
if (writeTopLevel) {
393+
writeAttribute(writable, InstrumentationTags.DD_TOP_LEVEL.toString(), 1);
394+
}
385395
for (Map.Entry<String, Object> metaStructField : metaStruct.entrySet()) {
386396
writeStreamingString(writable, metaStructField.getKey());
387397
writable.writeInt(VALUE_TYPE_BYTES);

dd-trace-core/src/test/groovy/datadog/trace/common/writer/ddagent/TraceMapperV1PayloadTest.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import datadog.trace.api.DDSpanId
1919
import datadog.trace.api.ProcessTags
2020
import datadog.trace.api.sampling.PrioritySampling
2121
import datadog.trace.api.sampling.SamplingMechanism
22+
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
2223
import datadog.trace.bootstrap.instrumentation.api.SpanAttributes
2324
import datadog.trace.bootstrap.instrumentation.api.SpanLink
2425
import datadog.trace.bootstrap.instrumentation.api.Tags
@@ -857,6 +858,9 @@ class TraceMapperV1PayloadTest extends DDSpecification {
857858
if (shouldContainHttpStatus) {
858859
expectedAttributes.put("http.status_code", Integer.toString(expectedHttpStatusCode))
859860
}
861+
if (expectedSpan.isTopLevel()) {
862+
expectedAttributes.put(InstrumentationTags.DD_TOP_LEVEL.toString(), 1d)
863+
}
860864

861865
assertEquals(expectedAttributes.size(), attributes.size())
862866
for (Map.Entry<String, Object> entry : expectedAttributes.entrySet()) {

0 commit comments

Comments
 (0)