Do not create a baggage HashMap each time
MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java
dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java
package com.datadoghq.trace;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import com.datadoghq.trace.integration.DDSpanContextDecorator;
import com.fasterxml.jackson.annotation.JsonIgnore;
-
import io.opentracing.Span;
import io.opentracing.tag.Tags;
+import java.util.*;
+
/**
* SpanContext represents Span state that must propagate to descendant Spans and across process boundaries.
* <p>
@@ -81,8 +76,9 @@ public class DDSpanContext implements io.opentracing.SpanContext {
this.spanId = spanId;
this.parentId = parentId;
+
if (baggageItems == null) {
- this.baggageItems = new HashMap<String, String>();
+ this.baggageItems = Collections.emptyMap();
} else {
this.baggageItems = baggageItems;
}
@@ -134,6 +130,9 @@ public class DDSpanContext implements io.opentracing.SpanContext {
}
public void setBaggageItem(String key, String value) {
+ if (this.baggageItems.isEmpty()) {
+ this.baggageItems = new HashMap<String, String>();
+ }
this.baggageItems.put(key, value);
}

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java
@@ -304,7 +304,7 @@ public class DDTracer implements io.opentracing.Tracer {
serviceName,
operationName,
this.resourceName,
- this.parent == null ? new HashMap<String, String>() : p.getBaggageItems(),
+ this.parent == null ? null : p.getBaggageItems(),
errorFlag,
spanType,
this.tags,

Do not create a baggage HashMap each time