1717import datadog .trace .api .TagMap ;
1818import datadog .trace .api .sampling .SamplingMechanism ;
1919import datadog .trace .bootstrap .instrumentation .api .AgentSpanLink ;
20+ import datadog .trace .bootstrap .instrumentation .api .InstrumentationTags ;
2021import datadog .trace .bootstrap .instrumentation .api .Tags ;
2122import datadog .trace .common .writer .Payload ;
2223import 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 );
0 commit comments