@@ -3,6 +3,7 @@ package tracer
33import (
44 "encoding/binary"
55 "fmt"
6+ "github.com/google/uuid"
67 "io"
78 "strconv"
89 "strings"
@@ -44,19 +45,22 @@ func (p *textMapPropagator) Inject(
4445 if ! ok {
4546 return opentracing .ErrInvalidCarrier
4647 }
47- carrier .Set (fieldNameTraceID , strconv .FormatUint (sc .TraceID , 16 ))
48+
49+ traceId := strings .ReplaceAll (sc .TraceID .String (), "-" , "" )
50+
51+ carrier .Set (fieldNameTraceID , traceId )
4852 carrier .Set (fieldNameSpanID , strconv .FormatUint (sc .SpanID , 16 ))
4953 carrier .Set (fieldNameSampled , strconv .FormatBool (sc .Sampled ))
5054
5155 tpSampled := "00"
5256 if sc .Sampled {
5357 tpSampled = "01"
5458 }
55- traceParentValue := fmt .Sprintf ("%v-%032x -%016x-%v" ,
56- "00" , // Version 0
57- sc . TraceID , // 8bytes TraceId
58- sc .SpanID , // 8bytes SpanId
59- tpSampled , // 00 for not sampled, 01 for sampled
59+ traceParentValue := fmt .Sprintf ("%v-%v -%016x-%v" ,
60+ "00" , // Version 0
61+ traceId , // 16bytes TraceId
62+ sc .SpanID , // 8bytes SpanId
63+ tpSampled , // 00 for not sampled, 01 for sampled
6064 )
6165 carrier .Set (traceParentKey , traceParentValue )
6266
@@ -81,14 +85,15 @@ func (p *textMapPropagator) Extract(
8185 return nil , opentracing .ErrInvalidCarrier
8286 }
8387 requiredFieldCount := 0
84- var traceID , spanID uint64
88+ var traceID uuid.UUID
89+ var spanID uint64
8590 var sampled bool
8691 var err error
8792 decodedBaggage := make (map [string ]string )
8893 err = carrier .ForeachKey (func (k , v string ) error {
8994 switch strings .ToLower (k ) {
9095 case fieldNameTraceID :
91- traceID , err = strconv . ParseUint ( v , 16 , 64 )
96+ traceID , err = uuid . Parse ( v )
9297 if err != nil {
9398 return opentracing .ErrSpanContextCorrupted
9499 }
@@ -111,7 +116,7 @@ func (p *textMapPropagator) Extract(
111116 return opentracing .ErrSpanContextCorrupted
112117 }
113118
114- traceID , err = strconv . ParseUint (traceParentArray [1 ][ 16 :], 16 , 64 )
119+ traceID , err = uuid . Parse (traceParentArray [1 ])
115120 if err != nil {
116121 return opentracing .ErrSpanContextCorrupted
117122 }
@@ -174,7 +179,8 @@ func (p *binaryPropagator) Inject(
174179 }
175180
176181 state := wire.TracerState {}
177- state .TraceId = sc .TraceID
182+ bytes , _ := sc .TraceID .MarshalBinary ()
183+ state .TraceId = binary .LittleEndian .Uint64 (bytes [8 :])
178184 state .SpanId = sc .SpanID
179185 state .Sampled = sc .Sampled
180186 state .BaggageItems = sc .Baggage
@@ -223,8 +229,11 @@ func (p *binaryPropagator) Extract(
223229 return nil , opentracing .ErrSpanContextCorrupted
224230 }
225231
232+ traceIdBytes := make ([]byte , 16 )
233+ binary .LittleEndian .PutUint64 (traceIdBytes , ctx .TraceId )
234+ traceID , _ := uuid .FromBytes (traceIdBytes )
226235 return SpanContext {
227- TraceID : ctx . TraceId ,
236+ TraceID : traceID ,
228237 SpanID : ctx .SpanId ,
229238 Sampled : ctx .Sampled ,
230239 Baggage : ctx .BaggageItems ,
0 commit comments