generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gabe
committed
Apr 12, 2024
1 parent
b9fa889
commit 9673754
Showing
5 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package util | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
// TraceHook is a logrus hook that adds trace information to log entries | ||
type TraceHook struct{} | ||
|
||
func (h *TraceHook) Levels() []logrus.Level { | ||
return logrus.AllLevels | ||
} | ||
|
||
func (h *TraceHook) Fire(entry *logrus.Entry) error { | ||
ctx := entry.Context | ||
if ctx == nil { | ||
return nil | ||
} | ||
|
||
span := trace.SpanFromContext(ctx) | ||
if !span.SpanContext().IsValid() { | ||
return nil | ||
} | ||
|
||
traceID := span.SpanContext().TraceID().String() | ||
spanID := span.SpanContext().SpanID().String() | ||
|
||
entry.Data["traceID"] = traceID | ||
entry.Data["spanID"] = spanID | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters