Skip to content

Commit

Permalink
trim leading zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Jan 20, 2025
1 parent 3a9e02f commit 9666f8c
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pkg/core/xtrace/propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
traceID128bitsWidth = 128 / 4
spanIDWidth = 64 / 4

// idPaddingChar = "0"
idPaddingChar = "0"

flagsDebug = 0x02
flagsSampled = 0x01
Expand Down Expand Up @@ -54,7 +54,9 @@ func (jaeger Jaeger) Inject(ctx context.Context, carrier propagation.TextMapCarr
if !sc.TraceID().IsValid() || !sc.SpanID().IsValid() {
return
}
headers = append(headers, sc.TraceID().String(), sc.SpanID().String(), deprecatedParentSpanID)
// trim leading zeros
tid := strings.TrimLeft(sc.TraceID().String(), "0")
headers = append(headers, tid, sc.SpanID().String(), deprecatedParentSpanID)
if debugFromContext(ctx) {
headers = append(headers, fmt.Sprintf("%x", flagsDebug|flagsSampled))
} else if sc.IsSampled() {
Expand Down Expand Up @@ -96,11 +98,11 @@ func extract(ctx context.Context, headerVal string) (context.Context, trace.Span
if len(id) > traceID128bitsWidth {
return ctx, empty, errInvalidTraceIDLength
}
// // padding when length is less than 32
// if len(id) < traceID128bitsWidth {
// padCharCount := traceID128bitsWidth - len(id)
// id = strings.Repeat(idPaddingChar, padCharCount) + id
// }
// padding when length is less than 32
if len(id) < traceID128bitsWidth {
padCharCount := traceID128bitsWidth - len(id)
id = strings.Repeat(idPaddingChar, padCharCount) + id
}
scc.TraceID, err = trace.TraceIDFromHex(id)
if err != nil {
return ctx, empty, errMalformedTraceID
Expand All @@ -113,11 +115,11 @@ func extract(ctx context.Context, headerVal string) (context.Context, trace.Span
if len(id) > spanIDWidth {
return ctx, empty, errInvalidSpanIDLength
}
// // padding when length is less than 16
// if len(id) < spanIDWidth {
// padCharCount := spanIDWidth - len(id)
// id = strings.Repeat(idPaddingChar, padCharCount) + id
// }
// padding when length is less than 16
if len(id) < spanIDWidth {
padCharCount := spanIDWidth - len(id)
id = strings.Repeat(idPaddingChar, padCharCount) + id
}
scc.SpanID, err = trace.SpanIDFromHex(id)
if err != nil {
return ctx, empty, errMalformedSpanID
Expand Down

0 comments on commit 9666f8c

Please sign in to comment.