@@ -190,15 +190,17 @@ func (p *payloadV1) push(t spanList) (stats payloadStats, err error) {
190
190
{key : streamingKey {isString : false , idx : 9 }, value : anyValue {valueType : StringValueType , value : p .appVersion }}, // appVersion
191
191
}
192
192
193
- p . chunks = append ( p . chunks , traceChunk {
193
+ tc := traceChunk {
194
194
priority : int32 (priority ),
195
195
origin : origin ,
196
196
attributes : keyValueList {},
197
197
spans : t ,
198
- traceID : t [0 ].Context ().traceID ,
199
- })
198
+ traceID : t [0 ].Context ().traceID [:],
199
+ }
200
+ p .chunks = append (p .chunks , tc )
200
201
wr := msgp .NewWriter (& p .buf )
201
- err = EncodeSpanList (t , wr , p )
202
+
203
+ err = tc .EncodeMsg (wr , p )
202
204
if err != nil {
203
205
return payloadStats {}, err
204
206
}
@@ -376,10 +378,11 @@ func (kv keyValueList) EncodeMsg(e *msgp.Writer, p *payloadV1) error {
376
378
}
377
379
378
380
func (t * traceChunk ) EncodeMsg (e * msgp.Writer , p * payloadV1 ) error {
381
+ e .WriteInt32 (11 ) // write msgp index for `chunks`
382
+
379
383
kv := keyValueList {
380
384
{key : streamingKey {isString : false , idx : 1 }, value : anyValue {valueType : IntValueType , value : int64 (t .priority )}}, // priority
381
385
{key : streamingKey {isString : false , idx : 2 }, value : anyValue {valueType : StringValueType , value : t .origin }}, // origin
382
- {key : streamingKey {isString : false , idx : 4 }, value : anyValue {valueType : keyValueListType , value : t .spans }}, // spans
383
386
{key : streamingKey {isString : false , idx : 5 }, value : anyValue {valueType : BoolValueType , value : t .droppedTrace }}, // droppedTrace
384
387
{key : streamingKey {isString : false , idx : 6 }, value : anyValue {valueType : BytesValueType , value : t .traceID }}, // traceID
385
388
{key : streamingKey {isString : false , idx : 7 }, value : anyValue {valueType : StringValueType , value : t .samplingMechanism }}, // samplingMechanism
@@ -389,22 +392,24 @@ func (t *traceChunk) EncodeMsg(e *msgp.Writer, p *payloadV1) error {
389
392
for k , v := range t .attributes {
390
393
attr = append (attr , keyValue {key : streamingKey {isString : false , idx : uint32 (k )}, value : anyValue {valueType : getAnyValueType (v ), value : v }})
391
394
}
392
- kv = append (kv , keyValue {key : streamingKey {isString : false , idx : 3 }, value : anyValue {valueType : ArrayValueType , value : attr }}) // attributes
395
+ kv = append (kv , keyValue {key : streamingKey {isString : false , idx : 3 }, value : anyValue {valueType : keyValueListType , value : attr }}) // attributes
396
+
397
+ err := kv .EncodeMsg (e , p )
398
+ if err != nil {
399
+ return err
400
+ }
393
401
394
- return kv . EncodeMsg ( e , p )
402
+ return EncodeSpanList ( t . spans , e , p )
395
403
}
396
404
397
- // EncodeMsg writes the contents of a list of spans into `p.buf`
398
- // Span, SpanLink, and SpanEvent structs are different for v0.4 and v1.0.
399
- // For v1 we need to manually encode the spans, span links, and span events
400
- // if we don't want to do extra allocations.
401
405
func EncodeSpanList (s spanList , e * msgp.Writer , p * payloadV1 ) error {
406
+ e .WriteInt32 (4 ) // write msgp index for `spans`
407
+
402
408
err := e .WriteArrayHeader (uint32 (len (s )))
403
409
if err != nil {
404
410
return msgp .WrapError (err )
405
411
}
406
412
407
- e .WriteInt32 (4 )
408
413
for _ , span := range s {
409
414
if span == nil {
410
415
err := e .WriteNil ()
@@ -622,26 +627,21 @@ func (p *payloadV1) Decode(b []byte) ([]byte, error) {
622
627
p .strings = newStringTable ()
623
628
}
624
629
625
- fields , o , err := msgp .ReadMapHeaderBytes (b )
630
+ fields , o , err := msgp .ReadArrayHeaderBytes (b )
626
631
if err != nil {
627
632
return o , err
628
633
}
629
634
630
635
for fields > 0 {
631
636
fields --
632
637
633
- f , o , err := msgp .ReadUint32Bytes ( b )
638
+ f , o , err := msgp .ReadInt32Bytes ( o )
634
639
if err != nil {
635
640
return o , err
636
641
}
637
642
638
643
switch f {
639
- case 1 : // stringTable
640
- o , err = DecodeStringTable (o , p .strings )
641
- if err != nil {
642
- return o , err
643
- }
644
-
644
+ // we don't care for the string table, so we don't decode it
645
645
case 2 : // containerID
646
646
p .containerID , o , err = DecodeStreamingString (o , p .strings )
647
647
if err != nil {
@@ -738,7 +738,7 @@ func DecodeStreamingString(b []byte, strings *stringTable) (string, []byte, erro
738
738
}
739
739
740
740
// else, try reading as a string, then add to the string table
741
- str , o , err := msgp .ReadStringBytes (b )
741
+ str , o , err := msgp .ReadStringBytes (o )
742
742
if err != nil {
743
743
return "" , nil , msgp .WrapError (err , "unable to read streaming string" )
744
744
}
@@ -783,7 +783,7 @@ func DecodeAnyValue(b []byte, strings *stringTable) (anyValue, []byte, error) {
783
783
}
784
784
return anyValue {valueType : BytesValueType , value : b }, o , nil
785
785
case ArrayValueType :
786
- len , o , err := msgp .ReadBytesHeader (o )
786
+ len , o , err := msgp .ReadArrayHeaderBytes (o )
787
787
if err != nil {
788
788
return anyValue {}, o , err
789
789
}
@@ -807,7 +807,7 @@ func DecodeAnyValue(b []byte, strings *stringTable) (anyValue, []byte, error) {
807
807
}
808
808
809
809
func DecodeKeyValueList (b []byte , strings * stringTable ) (keyValueList , []byte , error ) {
810
- len , o , err := msgp .ReadBytesHeader (b )
810
+ len , o , err := msgp .ReadMapHeaderBytes (b )
811
811
if err != nil {
812
812
return nil , o , err
813
813
}
@@ -833,22 +833,22 @@ func DecodeKeyValueList(b []byte, strings *stringTable) (keyValueList, []byte, e
833
833
}
834
834
835
835
func DecodeTraceChunks (b []byte , strings * stringTable ) ([]traceChunk , []byte , error ) {
836
- len , o , err := msgp .ReadArrayHeaderBytes (b )
836
+ len , o , err := msgp .ReadMapHeaderBytes (b )
837
837
if err != nil {
838
838
return nil , o , err
839
839
}
840
840
841
841
ret := make ([]traceChunk , len )
842
842
for i := range len {
843
- fields , o , err := msgp .ReadMapHeaderBytes (o )
843
+ fields , o , err := msgp .ReadArrayHeaderBytes (o )
844
844
if err != nil {
845
845
return nil , o , err
846
846
}
847
847
tc := traceChunk {}
848
848
for fields > 0 {
849
849
fields --
850
850
851
- f , o , err := msgp .ReadUint32Bytes (b )
851
+ f , o , err := msgp .ReadUint32Bytes (o )
852
852
if err != nil {
853
853
return ret , o , err
854
854
}
@@ -889,7 +889,7 @@ func DecodeTraceChunks(b []byte, strings *stringTable) ([]traceChunk, []byte, er
889
889
if err != nil {
890
890
return ret , o , err
891
891
}
892
- tc .traceID = [16 ]byte (s )
892
+ tc .traceID = []byte (s )
893
893
case 7 : // samplingMechanism
894
894
s , o , err := msgp .ReadStringBytes (o )
895
895
if err != nil {
@@ -928,7 +928,7 @@ func DecodeSpan(b []byte, strings *stringTable) (*Span, []byte, error) {
928
928
for fields > 0 {
929
929
fields --
930
930
931
- f , o , err := msgp .ReadUint32Bytes (b )
931
+ f , o , err := msgp .ReadUint32Bytes (o )
932
932
if err != nil {
933
933
return & sp , o , err
934
934
}
@@ -1091,11 +1091,11 @@ func DecodeSpanLinks(b []byte, strings *stringTable) ([]SpanLink, []byte, error)
1091
1091
}
1092
1092
sl .Tracestate = s
1093
1093
case 5 : // flags
1094
- s , o , err := msgp .ReadInt32Bytes (o )
1094
+ s , o , err := msgp .ReadUint32Bytes (o )
1095
1095
if err != nil {
1096
1096
return ret , o , err
1097
1097
}
1098
- sl .Flags = uint32 ( s )
1098
+ sl .Flags = s
1099
1099
}
1100
1100
}
1101
1101
ret [i ] = sl
@@ -1118,7 +1118,7 @@ func DecodeSpanEvents(b []byte, strings *stringTable) ([]spanEvent, []byte, erro
1118
1118
for fields > 0 {
1119
1119
fields --
1120
1120
1121
- f , o , err := msgp .ReadUint32Bytes (b )
1121
+ f , o , err := msgp .ReadUint32Bytes (o )
1122
1122
if err != nil {
1123
1123
return ret , o , err
1124
1124
}
0 commit comments