diff --git a/dd-trace-ot/src/main/java/datadog/trace/common/serialization/MsgpackFormatWriter.java b/dd-trace-ot/src/main/java/datadog/trace/common/serialization/MsgpackFormatWriter.java index ca5579da7e..f892c80f6b 100644 --- a/dd-trace-ot/src/main/java/datadog/trace/common/serialization/MsgpackFormatWriter.java +++ b/dd-trace-ot/src/main/java/datadog/trace/common/serialization/MsgpackFormatWriter.java @@ -32,7 +32,11 @@ public class MsgpackFormatWriter extends FormatWriter { public void writeString(final String key, final String value, final MessagePacker destination) throws IOException { destination.packString(key); - destination.packString(value); + if (value == null) { + destination.packNil(); + } else { + destination.packString(value); + } } @Override @@ -82,6 +86,10 @@ public class MsgpackFormatWriter extends FormatWriter { final String key, final BigInteger value, final MessagePacker destination) throws IOException { destination.packString(key); - destination.packBigInteger(value); + if (value == null) { + destination.packNil(); + } else { + destination.packBigInteger(value); + } } } diff --git a/dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanSerializationTest.groovy b/dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanSerializationTest.groovy index 8b5e04a336..7e3ee405b2 100644 --- a/dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanSerializationTest.groovy +++ b/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" } }