Skip to content

Commit

Permalink
fix(logger): check span context
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderPoet committed Jan 17, 2024
1 parent 9e070ce commit a9c3af2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions logging/logrus/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,21 @@ func (h *TraceHook) Fire(entry *logrus.Entry) error {

span := trace.SpanFromContext(entry.Context)

// non recording spans do not support modifying
if !span.IsRecording() {
// check span context
spanContext := span.SpanContext()
if !spanContext.IsValid() {
return nil
}

// attach span context to log entry data fields
entry.Data[traceIDKey] = span.SpanContext().TraceID()
entry.Data[spanIDKey] = span.SpanContext().SpanID()
entry.Data[traceFlagsKey] = span.SpanContext().TraceFlags()
entry.Data[traceIDKey] = spanContext.TraceID()
entry.Data[spanIDKey] = spanContext.SpanID()
entry.Data[traceFlagsKey] = spanContext.TraceFlags()

// non recording spans do not support modifying
if !span.IsRecording() {
return nil
}

if entry.Level <= h.cfg.errorSpanLevel {
// set span status
Expand Down

0 comments on commit a9c3af2

Please sign in to comment.