Span metadata must be string values.
MODIFY
dd-trace/src/main/java/datadog/trace/tracer/Span.java
dd-trace/src/main/java/datadog/trace/tracer/Span.java
@@ -99,7 +99,7 @@ public interface Span {
/**
* Get all the metadata attached to this span.
*
- * @return
+ * @return immutable map of span metadata.
*/
Map<String, Object> getMeta();

MODIFY
dd-trace/src/main/java/datadog/trace/tracer/SpanImpl.java
dd-trace/src/main/java/datadog/trace/tracer/SpanImpl.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonGetter;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@@ -13,6 +14,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigInteger;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -213,9 +215,19 @@ class SpanImpl implements Span {
}
@Override
- @JsonGetter("meta")
+ @JsonIgnore
public synchronized Map<String, Object> getMeta() {
- final Map<String, Object> result = new HashMap<>(meta.size());
+ return Collections.unmodifiableMap(meta);
+ }
+
+ /**
+ * The agent expects meta's values to be strings.
+ *
+ * @return a copy of meta with all values converted to strings.
+ */
+ @JsonGetter("meta")
+ synchronized Map<String, String> getMetaString() {
+ final Map<String, String> result = new HashMap<>(meta.size());
for (final Map.Entry<String, Object> entry : meta.entrySet()) {
result.put(entry.getKey(), String.valueOf(entry.getValue()));
}

MODIFY
dd-trace/src/test/groovy/datadog/trace/tracer/JsonSpan.groovy
dd-trace/src/test/groovy/datadog/trace/tracer/JsonSpan.groovy
@@ -43,7 +43,7 @@ class JsonSpan {
@JsonCreator
JsonSpan() {}
- JsonSpan(Span span) {
+ JsonSpan(SpanImpl span) {
traceId = new BigInteger(span.getContext().getTraceId())
parentId = new BigInteger(span.getContext().getParentId())
spanId = new BigInteger(span.getContext().getSpanId())
@@ -58,6 +58,6 @@ class JsonSpan {
error = span.isErrored() ? 1 : 0
- meta = span.getMeta()
+ meta = span.getMetaString()
}
}

MODIFY
dd-trace/src/test/groovy/datadog/trace/tracer/SpanImplTest.groovy
dd-trace/src/test/groovy/datadog/trace/tracer/SpanImplTest.groovy
@@ -129,7 +129,8 @@ class SpanImplTest extends Specification {
span.setMeta("boolean.key", true)
then:
- span.getMeta() == ["number.key": "123", "string.key": "meta string", "boolean.key": "true"]
+ span.getMeta() == ["number.key": 123, "string.key": "meta string", "boolean.key": true]
+ span.getMetaString() == ["number.key": "123", "string.key": "meta string", "boolean.key": "true"]
}
def "test meta setter on finished span for #key"() {

Span metadata must be string values.