Skip to content

Commit

Permalink
TraceID.String prefix with zeroes
Browse files Browse the repository at this point in the history
The wire encoding of the TraceID uses zero prefixes (jaegertracing#472).
The JaegerUI also uses zero prefixes (since 1.16).
So it makes sense that the Stringer of the TraceID also does this.

Resolves jaegertracing#532

Signed-off-by: Lukas Vogel <vogel@anapaya.net>
  • Loading branch information
lukedirtwalker committed Sep 11, 2020
1 parent 4b20232 commit 14e3bff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions span_context.go
Expand Up @@ -344,9 +344,9 @@ func (c *SpanContext) isDebugIDContainerOnly() bool {

func (t TraceID) String() string {
if t.High == 0 {
return fmt.Sprintf("%x", t.Low)
return fmt.Sprintf("%016x", t.Low)
}
return fmt.Sprintf("%x%016x", t.High, t.Low)
return fmt.Sprintf("%016x%016x", t.High, t.Low)
}

// TraceIDFromString creates a TraceID from a hexadecimal string
Expand Down
26 changes: 26 additions & 0 deletions span_context_test.go
Expand Up @@ -15,6 +15,7 @@
package jaeger

import (
"math"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -166,3 +167,28 @@ func TestSpanContext_CopyFrom(t *testing.T) {
assert.Equal(t, ctx, ctx2)
assert.Equal(t, "y", ctx2.baggage["x"])
}

func TestTraceIDString(t *testing.T) {
var tests = map[string]struct {
in TraceID
expected string
}{
"Empty TraceID": {
in: TraceID{},
expected: "0000000000000000",
},
"TraceID low only": {
in: TraceID{Low: math.MaxUint64/16 - 405},
expected: "0ffffffffffffe6a",
},
"TraceID low and high": {
in: TraceID{High: math.MaxUint64 / 16, Low: math.MaxUint64/16 - 405},
expected: "0fffffffffffffff0ffffffffffffe6a",
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.expected, tc.in.String())
})
}
}

0 comments on commit 14e3bff

Please sign in to comment.