Skip to content

Commit

Permalink
feat: add WithSpan logrus helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-jonas committed May 27, 2024
1 parent d0c9e7a commit 920df43
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions logrusx/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ func (l *Logger) WithRequest(r *http.Request) *Logger {
return ll
}

func (l *Logger) WithSpan(sc trace.Span) *Logger {
if sc == nil {
return l
}
spanCtx := sc.SpanContext()
if !spanCtx.IsValid() {
return l
}

traces := map[string]string{}
if spanCtx.HasTraceID() {
traces["trace_id"] = spanCtx.TraceID().String()
}
if spanCtx.HasSpanID() {
traces["span_id"] = spanCtx.SpanID().String()
}
return l.WithField("otel", traces)
}

func (l *Logger) Logf(level logrus.Level, format string, args ...interface{}) {
if !l.leakSensitive {
for i, arg := range args {
Expand Down

0 comments on commit 920df43

Please sign in to comment.