Skip to content

Commit

Permalink
Propagate unknown trace flag bits
Browse files Browse the repository at this point in the history
  • Loading branch information
XSAM committed Mar 14, 2024
1 parent 54b6ee4 commit 560c798
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions propagation/trace_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@ func (tc TraceContext) Inject(ctx context.Context, carrier TextMapCarrier) {
carrier.Set(tracestateHeader, ts)
}

// Clear all flags other than the trace-context supported sampling bit.
flags := sc.TraceFlags() & trace.FlagsSampled

var sb strings.Builder
sb.Grow(2 + 32 + 16 + 2 + 3)
_, _ = sb.WriteString(versionPart)
traceID := sc.TraceID()
spanID := sc.SpanID()
flagByte := [1]byte{byte(flags)}
flagByte := [1]byte{byte(sc.TraceFlags())}
var buf [32]byte
for _, src := range [][]byte{traceID[:], spanID[:], flagByte[:]} {
_ = sb.WriteByte(delimiter[0])
Expand Down
4 changes: 2 additions & 2 deletions propagation/trace_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ func TestInjectValidTraceContext(t *testing.T) {
}),
},
{
name: "unsupported trace flag bits dropped",
name: "keep unknown trace flag bits",
header: http.Header{
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"},
traceparent: []string{"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-ff"},
},
sc: trace.NewSpanContext(trace.SpanContextConfig{
TraceID: traceID,
Expand Down

0 comments on commit 560c798

Please sign in to comment.