Skip to content

Commit

Permalink
Merge pull request #45 from CoderPoet/fix/log-span
Browse files Browse the repository at this point in the history
fix(logger): check span context
  • Loading branch information
CoderPoet authored Jan 17, 2024
2 parents e7127e1 + 2d6005f commit a7ae768
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions logging/logrus/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ func (h *TraceHook) Fire(entry *logrus.Entry) error {

span := trace.SpanFromContext(entry.Context)

// 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() {
Expand Down

0 comments on commit a7ae768

Please sign in to comment.