Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
[zipkin] Encode span IDs as full 16-hex strings #601
Browse files Browse the repository at this point in the history
Based on the openzipkin/b3-propagation specification, the SpanID and
ParentSpanID are to be encoded as 16 lower-hex characters.

#533 fixed this
for TraceID, and fixed the SpanID.String() method, but did not update
the Zipkin Propagator SpanID encoding.

This fix uses SpanID.String() to ensure proper encoding of the SpanID and
ParentSpandID within the Zipkin Propagator.

Signed-off-by: Nathan Bowler <nzb301@psu.edu>
  • Loading branch information
nabowler committed Oct 6, 2021
1 parent 7aa7af5 commit ab82d08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions zipkin/propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func (p Propagator) Inject(

textMapWriter.Set("x-b3-traceid", sc.TraceID().String())
if sc.ParentID() != 0 {
textMapWriter.Set("x-b3-parentspanid", strconv.FormatUint(uint64(sc.ParentID()), 16))
textMapWriter.Set("x-b3-parentspanid", sc.ParentID().String())
}
textMapWriter.Set("x-b3-spanid", strconv.FormatUint(uint64(sc.SpanID()), 16))
textMapWriter.Set("x-b3-spanid", sc.SpanID().String())
if sc.IsSampled() {
textMapWriter.Set("x-b3-sampled", "1")
} else {
Expand Down
20 changes: 10 additions & 10 deletions zipkin/propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ var (
var (
rootSampledHeader = opentracing.TextMapCarrier{
"x-b3-traceid": "0000000000000001",
"x-b3-spanid": "2",
"x-b3-spanid": "0000000000000002",
"x-b3-sampled": "1",
"baggage-foo": "bar",
}
nonRootSampledHeader = opentracing.TextMapCarrier{
"x-b3-traceid": "0000000000000001",
"x-b3-spanid": "2",
"x-b3-parentspanid": "1",
"x-b3-spanid": "0000000000000002",
"x-b3-parentspanid": "0000000000000001",
"x-b3-sampled": "1",
}
nonRootNonSampledHeader = opentracing.TextMapCarrier{
"x-b3-traceid": "0000000000000001",
"x-b3-spanid": "2",
"x-b3-parentspanid": "1",
"x-b3-spanid": "0000000000000002",
"x-b3-parentspanid": "0000000000000001",
"x-b3-sampled": "0",
}
rootSampledBooleanHeader = opentracing.TextMapCarrier{
"x-b3-traceid": "0000000000000001",
"x-b3-spanid": "2",
"x-b3-spanid": "0000000000000002",
"x-b3-sampled": "true",
"baggage-foo": "bar",
}
nonRootSampledBooleanHeader = opentracing.TextMapCarrier{
"x-b3-traceid": "0000000000000001",
"x-b3-spanid": "2",
"x-b3-spanid": "0000000000000002",
"x-b3-parentspanid": "1",
"x-b3-sampled": "true",
}
Expand All @@ -69,12 +69,12 @@ var (
}
sampled128bitTraceID = opentracing.TextMapCarrier{
"x-b3-traceid": "463ac35c9f6413ad48485a3953bb6124",
"x-b3-spanid": "2",
"x-b3-spanid": "0000000000000002",
"x-b3-sampled": "1",
}
invalidTraceID = opentracing.TextMapCarrier{
"x-b3-traceid": "00000000000000000000000000000000",
"x-b3-spanid": "2",
"x-b3-spanid": "0000000000000002",
"x-b3-sampled": "1",
}
)
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestCustomBaggagePrefix(t *testing.T) {
assert.Nil(t, err)
m := opentracing.TextMapCarrier{
"x-b3-traceid": "0000000000000001",
"x-b3-spanid": "2",
"x-b3-spanid": "0000000000000002",
"x-b3-sampled": "1",
"emoji:)foo": "bar",
}
Expand Down

0 comments on commit ab82d08

Please sign in to comment.