Skip to content

Commit

Permalink
Merge pull request #5315 from jsternberg/trace-id-in-log
Browse files Browse the repository at this point in the history
bklog: always enable trace id if it exists
  • Loading branch information
tonistiigi authored Sep 9, 2024
2 parents b2b8b1c + 366c355 commit c9d08dd
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions util/bklog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ var (
L = logrus.NewEntry(logrus.StandardLogger())
)

var (
logWithTraceID = false
)

func EnableLogWithTraceID(b bool) {
logWithTraceID = b
}

type (
loggerKey struct{}
)
Expand All @@ -51,13 +43,11 @@ func GetLogger(ctx context.Context) (l *logrus.Entry) {
l = L
}

if logWithTraceID {
if spanContext := trace.SpanFromContext(ctx).SpanContext(); spanContext.IsValid() {
return l.WithFields(logrus.Fields{
"traceID": spanContext.TraceID(),
"spanID": spanContext.SpanID(),
})
}
if spanContext := trace.SpanFromContext(ctx).SpanContext(); spanContext.IsValid() {
return l.WithFields(logrus.Fields{
"traceID": spanContext.TraceID(),
"spanID": spanContext.SpanID(),
})
}

return l
Expand Down

0 comments on commit c9d08dd

Please sign in to comment.