@@ -229,6 +229,80 @@ class TraceMapperV1PayloadTest extends DDSpecification {
229229 " invalid" | SamplingMechanism . DEFAULT
230230 }
231231
232+ def " test span ids are encoded as unsigned values in v1 payloads" () {
233+ setup :
234+ long spanId = Long . MIN_VALUE + 123L
235+ long parentId = Long . MIN_VALUE + 456L
236+ def span = new TraceGenerator.PojoSpan (
237+ " service-a" ,
238+ " operation-a" ,
239+ " resource-a" ,
240+ DDTraceId . ONE ,
241+ spanId,
242+ parentId,
243+ 1000L ,
244+ 2000L ,
245+ 0 ,
246+ [:],
247+ [:],
248+ " web" ,
249+ false ,
250+ PrioritySampling . SAMPLER_KEEP ,
251+ 200 ,
252+ null )
253+
254+ TraceMapperV1 mapper = new TraceMapperV1 ()
255+ byte [] encoded = serializeMappedPayload(mapper, [[span]])
256+ MessageUnpacker unpacker = MessagePack . newDefaultUnpacker(encoded)
257+ List<String > stringTable = new ArrayList<> ()
258+ stringTable. add(" " )
259+
260+ when :
261+ unpacker. unpackMapHeader()
262+ Long actualSpanId = null
263+ Long actualParentId = null
264+
265+ for (int i = 0 ; i < 10 ; i++ ) {
266+ int payloadFieldId = unpacker. unpackInt()
267+ if (payloadFieldId == 11 ) {
268+ int chunkCount = unpacker. unpackArrayHeader()
269+ assertEquals (1 , chunkCount)
270+ int chunkFieldCount = unpacker. unpackMapHeader()
271+ for (int j = 0 ; j < chunkFieldCount; j++ ) {
272+ int chunkFieldId = unpacker. unpackInt()
273+ if (chunkFieldId == 4 ) {
274+ int spanCount = unpacker. unpackArrayHeader()
275+ assertEquals (1 , spanCount)
276+ int spanFieldCount = unpacker. unpackMapHeader()
277+ for (int k = 0 ; k < spanFieldCount; k++ ) {
278+ int spanFieldId = unpacker. unpackInt()
279+ switch (spanFieldId) {
280+ case 4 :
281+ assertEquals (MessageFormat . UINT64 , unpacker. nextFormat)
282+ actualSpanId = DDSpanId . from(" ${ unpacker.unpackBigInteger()} " )
283+ break
284+ case 5 :
285+ assertEquals (MessageFormat . UINT64 , unpacker. nextFormat)
286+ actualParentId = DDSpanId . from(" ${ unpacker.unpackBigInteger()} " )
287+ break
288+ default :
289+ skipSpanField(unpacker, spanFieldId, stringTable)
290+ }
291+ }
292+ } else {
293+ skipChunkField(unpacker, chunkFieldId, stringTable)
294+ }
295+ }
296+ } else {
297+ skipPayloadField(unpacker, payloadFieldId, stringTable)
298+ }
299+ }
300+
301+ then :
302+ assertEquals (spanId, actualSpanId)
303+ assertEquals (parentId, actualParentId)
304+ }
305+
232306 def " test span links are encoded from structured span links" () {
233307 setup :
234308 List<SpanLink > spanLinks = [
@@ -783,10 +857,10 @@ class TraceMapperV1PayloadTest extends DDSpecification {
783857 resource = readStreamingString(unpacker, stringTable)
784858 break
785859 case 4 :
786- spanId = unpacker . unpackValue() . asNumberValue() . toLong( )
860+ spanId = unpackUnsignedLong(unpacker )
787861 break
788862 case 5 :
789- parentId = unpacker . unpackValue() . asNumberValue() . toLong( )
863+ parentId = unpackUnsignedLong(unpacker )
790864 break
791865 case 6 :
792866 start = unpacker. unpackLong()
@@ -919,6 +993,14 @@ class TraceMapperV1PayloadTest extends DDSpecification {
919993 }
920994 }
921995
996+ private static long unpackUnsignedLong (MessageUnpacker unpacker ) {
997+ MessageFormat format = unpacker. nextFormat
998+ if (format == MessageFormat . UINT64 ) {
999+ return DDSpanId . from(" ${ unpacker.unpackBigInteger()} " )
1000+ }
1001+ return unpacker. unpackLong()
1002+ }
1003+
9221004 private static void addFlattenedExpectedAttribute (
9231005 Map<String , Object > expectedAttributes ,
9241006 String key ,
0 commit comments