Do not create a baggage HashMap each time

This commit is contained in:
Guillaume Polaert 2017-05-24 10:50:44 +02:00
parent 1cd1183f07
commit 405e5a5410
2 changed files with 12 additions and 13 deletions

View File

@ -1,18 +1,13 @@
package com.datadoghq.trace; 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.datadoghq.trace.integration.DDSpanContextDecorator;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import io.opentracing.Span; import io.opentracing.Span;
import io.opentracing.tag.Tags; import io.opentracing.tag.Tags;
import java.util.*;
/** /**
* SpanContext represents Span state that must propagate to descendant Spans and across process boundaries. * SpanContext represents Span state that must propagate to descendant Spans and across process boundaries.
* <p> * <p>
@ -81,8 +76,9 @@ public class DDSpanContext implements io.opentracing.SpanContext {
this.spanId = spanId; this.spanId = spanId;
this.parentId = parentId; this.parentId = parentId;
if (baggageItems == null) { if (baggageItems == null) {
this.baggageItems = new HashMap<String, String>(); this.baggageItems = Collections.emptyMap();
} else { } else {
this.baggageItems = baggageItems; this.baggageItems = baggageItems;
} }
@ -134,6 +130,9 @@ public class DDSpanContext implements io.opentracing.SpanContext {
} }
public void setBaggageItem(String key, String value) { public void setBaggageItem(String key, String value) {
if (this.baggageItems.isEmpty()) {
this.baggageItems = new HashMap<String, String>();
}
this.baggageItems.put(key, value); this.baggageItems.put(key, value);
} }

View File

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