11package datadog .trace .common .writer .ddagent ;
22
33import static datadog .communication .http .OkHttpUtils .msgpackRequestBodyOf ;
4+ import static java .util .Collections .emptyMap ;
5+ import static java .util .Collections .singletonMap ;
46
57import datadog .common .container .ContainerInfo ;
68import datadog .communication .ddagent .TracerVersion ;
1113import datadog .environment .JavaVirtualMachine ;
1214import datadog .trace .api .Config ;
1315import datadog .trace .api .DDTags ;
16+ import datadog .trace .api .ProcessTags ;
1417import datadog .trace .api .TagMap ;
1518import datadog .trace .api .sampling .SamplingMechanism ;
1619import datadog .trace .bootstrap .instrumentation .api .AgentSpanLink ;
2427import java .nio .ByteBuffer ;
2528import java .nio .channels .WritableByteChannel ;
2629import java .util .Arrays ;
27- import java .util .Collections ;
2830import java .util .HashMap ;
2931import java .util .LinkedHashMap ;
3032import java .util .List ;
@@ -91,7 +93,7 @@ public void map(List<? extends CoreSpan<?>> trace, Writable writable) {
9193 // origin = 2, the optional string origin ("lambda", "rum", etc.) of the trace chunk
9294 encodeField (writable , 2 , firstSpan .getOrigin ()); // TODO double check
9395 // attributes = 3, a collection of key to value pairs common in all `spans`
94- encodeAttributes (writable , 3 , buildChunkAttributes (trace ), Collections . emptyMap ());
96+ encodeAttributes (writable , 3 , buildChunkAttributes (trace ), emptyMap ());
9597 // spans = 4, a list of spans in this chunk
9698 encodeSpans (writable , 4 , trace );
9799 // traceID = 6, the ID of the trace to which all spans in this chunk belong
@@ -102,14 +104,14 @@ public void map(List<? extends CoreSpan<?>> trace, Writable writable) {
102104
103105 private Map <String , Object > buildChunkAttributes (List <? extends CoreSpan <?>> trace ) {
104106 if (trace .isEmpty ()) {
105- return Collections . emptyMap ();
107+ return emptyMap ();
106108 }
107109 CoreSpan <?> localRoot = trace .get (0 ).getLocalRootSpan ();
108110 CharSequence service = localRoot == null ? null : localRoot .getServiceName ();
109111 if (service == null ) {
110- return Collections . emptyMap ();
112+ return emptyMap ();
111113 }
112- return Collections . singletonMap ("service" , service );
114+ return singletonMap ("service" , service );
113115 }
114116
115117 private void encodeSpans (Writable writable , int fieldId , List <? extends CoreSpan <?>> spans ) {
@@ -180,7 +182,7 @@ private void encodeSpanLinks(Writable writable, int fieldId, List<AgentSpanLink>
180182 encodeField (writable , 2 , link .spanId ());
181183 Map <String , Object > attributes = new LinkedHashMap <>();
182184 attributes .putAll (link .attributes ().asMap ());
183- encodeAttributes (writable , 3 , attributes , Collections . emptyMap ());
185+ encodeAttributes (writable , 3 , attributes , emptyMap ());
184186 encodeField (writable , 4 , link .traceState ());
185187 encodeField (writable , 5 , link .traceFlags () & 0xFF );
186188 }
@@ -522,26 +524,34 @@ private ByteBuffer buildHeader() {
522524
523525 // containerID = 2, the string ID of the container where the tracer is running
524526 encodeField (headerWriter , 2 , ContainerInfo .get ().getContainerId ());
527+
525528 // languageName = 3, the string language name of the tracer
526529 encodeField (headerWriter , 3 , "java" ); // TODO: check java or jvm?
530+
527531 // languageVersion = 4, the string language version of the tracer
528532 encodeField (headerWriter , 4 , JavaVirtualMachine .getLangVersion ());
533+
529534 // tracerVersion = 5, the string version of the tracer
530535 encodeField (headerWriter , 5 , TracerVersion .TRACER_VERSION );
536+
531537 // runtimeID = 6, the V4 string UUID representation of a tracer session
532538 encodeField (headerWriter , 6 , cfg .getRuntimeId ());
539+
533540 // env=7, the optional `env` string tag that set with the tracer
534541 encodeField (headerWriter , 7 , cfg .getEnv ());
542+
535543 // hostname = 8, the optional string hostname of where the tracer is running
536544 encodeField (headerWriter , 8 , cfg .getHostName ());
545+
537546 // appVersion = 9, the optional string `version` tag for the application set in the tracer
538547 encodeField (headerWriter , 9 , cfg .getVersion ());
548+
539549 // attributes = 10, a collection of key to value pairs common in all `chunks`
540- encodeAttributes (
541- headerWriter ,
542- 10 ,
543- Collections . emptyMap (),
544- Collections . emptyMap ()); // TODO check useful attrs.
550+ CharSequence processTags = ProcessTags . getTagsForSerialization ();
551+ Map < String , Object > tags =
552+ processTags != null ? singletonMap ( DDTags . PROCESS_TAGS , processTags ) : emptyMap ();
553+ encodeAttributes ( headerWriter , 10 , tags , emptyMap ());
554+
545555 // chunks = 11, a list of trace `chunks`, value is written by PayloadV1
546556 headerWriter .writeInt (11 );
547557
0 commit comments