Merge pull request #534 from aesy/aesy/fix-64bit-trace-id-encoding

Fix trace id can't be decoded by agent due to being transmitted as float
This commit is contained in:
Tyler Benson 2018-10-18 17:45:18 +10:00 committed by GitHub
commit b58606d601
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.ref.WeakReference;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@ -419,7 +420,7 @@ public class DDSpan implements Span, MutableSpan {
public void serialize(
final String value, final JsonGenerator gen, final SerializerProvider provider)
throws IOException {
gen.writeNumber(value);
gen.writeNumber(new BigInteger(value));
}
}
}

View File

@ -5,6 +5,10 @@ import com.google.common.collect.Maps
import datadog.trace.api.DDTags
import datadog.trace.api.sampling.PrioritySampling
import datadog.trace.common.writer.ListWriter
import org.msgpack.core.MessagePack
import org.msgpack.core.buffer.ArrayBufferInput
import org.msgpack.jackson.dataformat.MessagePackFactory
import org.msgpack.value.ValueType
import spock.lang.Specification
class DDSpanSerializationTest extends Specification {
@ -72,4 +76,51 @@ class DDSpanSerializationTest extends Specification {
PrioritySampling.SAMPLER_KEEP | _
PrioritySampling.UNSET | _
}
def "serialize trace/span with id #value as int"() {
setup:
def objectMapper = new ObjectMapper(new MessagePackFactory())
def writer = new ListWriter()
def tracer = new DDTracer(writer)
def context = new DDSpanContext(
value.toString(),
value.toString(),
"0",
"fakeService",
"fakeOperation",
"fakeResource",
PrioritySampling.UNSET,
Collections.emptyMap(),
false,
"fakeType",
Collections.emptyMap(),
new PendingTrace(tracer, "1", [:]),
tracer)
def span = new DDSpan(0, context)
byte[] bytes = objectMapper.writeValueAsBytes(span)
def unpacker = MessagePack.newDefaultUnpacker(new ArrayBufferInput(bytes))
int size = unpacker.unpackMapHeader()
expect:
for (int i = 0; i < size; i++) {
String key = unpacker.unpackString()
switch (key) {
case "trace_id":
case "span_id":
assert unpacker.nextFormat.valueType == ValueType.INTEGER
assert unpacker.unpackBigInteger() == value
break
default:
unpacker.unpackValue()
}
}
where:
value | _
BigInteger.ZERO | _
BigInteger.ONE | _
BigInteger.valueOf(Long.MAX_VALUE).subtract(BigInteger.ONE) | _
BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE) | _
}
}