Skip to content

Commit

Permalink
feat: trace-id client get from incoming
Browse files Browse the repository at this point in the history
  • Loading branch information
Makonike committed Aug 27, 2023
1 parent 55fd85f commit 7920389
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,21 @@ func (gen *JaegerIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace.
gen.defaultIDGenerator()
}
if ctx.Value(o.meta.TraceHeader) != "" {
str, ok := ctx.Value(o.meta.TraceHeader).(string)
if !ok {
t, s := gen.newRandIDs()
return t, s
if str, ok := ctx.Value(o.meta.TraceHeader).(string); ok {
t, _ := trace.TraceIDFromHex(str)
return t, gen.newRandSpanID()
}
}
if md, ok := metadata.FromIncomingContext(ctx); ok {
traceIDs := md.Get(o.meta.TraceHeader)
if len(traceIDs) > 0 {
t, err := trace.TraceIDFromHex(traceIDs[0])
if err != nil {
return gen.newRandIDs()
}
return t, gen.newRandSpanID()
}
t, _ := trace.TraceIDFromHex(str)
return t, gen.newRandSpanID()
}

return gen.newRandIDs()
}

Expand Down

0 comments on commit 7920389

Please sign in to comment.