Fix NPE on serialization with no span type
Add tests.
MODIFY
dd-trace-ot/src/main/java/datadog/trace/common/serialization/MsgpackFormatWriter.java
dd-trace-ot/src/main/java/datadog/trace/common/serialization/MsgpackFormatWriter.java
@@ -32,8 +32,12 @@ public class MsgpackFormatWriter extends FormatWriter<MessagePacker> {
public void writeString(final String key, final String value, final MessagePacker destination)
throws IOException {
destination.packString(key);
+ if (value == null) {
+ destination.packNil();
+ } else {
destination.packString(value);
}
+ }
@Override
public void writeShort(final String key, final short value, final MessagePacker destination)
@@ -82,6 +86,10 @@ public class MsgpackFormatWriter extends FormatWriter<MessagePacker> {
final String key, final BigInteger value, final MessagePacker destination)
throws IOException {
destination.packString(key);
+ if (value == null) {
+ destination.packNil();
+ } else {
destination.packBigInteger(value);
}
}
+}

MODIFY
dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanSerializationTest.groovy
dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanSerializationTest.groovy
@@ -33,7 +33,7 @@ class DDSpanSerializationTest extends DDSpecification {
parent_id: 0l,
start : 100000,
duration : 33000,
- type : "type",
+ type : spanType,
error : 0,
metrics : metrics,
meta : [
@@ -58,7 +58,7 @@ class DDSpanSerializationTest extends DDSpecification {
null,
["a-baggage": "value"],
false,
- "type",
+ spanType,
["k1": "v1"],
new PendingTrace(tracer, 1G, [:]),
tracer)
@@ -73,9 +73,9 @@ class DDSpanSerializationTest extends DDSpecification {
actualTree == expectedTree
where:
- samplingPriority | _
- PrioritySampling.SAMPLER_KEEP | _
- PrioritySampling.UNSET | _
+ samplingPriority | spanType
+ PrioritySampling.SAMPLER_KEEP | null
+ PrioritySampling.UNSET | "some-type"
}
def "serialize trace/span with id #value as int"() {
@@ -93,7 +93,7 @@ class DDSpanSerializationTest extends DDSpecification {
null,
Collections.emptyMap(),
false,
- "fakeType",
+ spanType,
Collections.emptyMap(),
new PendingTrace(tracer, 1G, [:]),
tracer)
@@ -122,12 +122,12 @@ class DDSpanSerializationTest extends DDSpecification {
}
where:
- value | _
- 0G | _
- 1G | _
- 8223372036854775807G | _
- BigInteger.valueOf(Long.MAX_VALUE).subtract(1G) | _
- BigInteger.valueOf(Long.MAX_VALUE).add(1G) | _
- 2G.pow(64).subtract(1G) | _
+ value | spanType
+ 0G | null
+ 1G | "some-type"
+ 8223372036854775807G | null
+ BigInteger.valueOf(Long.MAX_VALUE).subtract(1G) | "some-type"
+ BigInteger.valueOf(Long.MAX_VALUE).add(1G) | null
+ 2G.pow(64).subtract(1G) | "some-type"
}
}

Fix NPE on serialization with no span type

Add tests.