Skip to content

Commit ccf7938

Browse files
committed
pkg/tracing: remove direct use of github.com/sirupsen/logrus
While the hook is intended to be used with logrus, we don't need to have the direct import; use the aliases provided by the containerd/log module instead. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 4203e2d commit ccf7938

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

pkg/tracing/log.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,43 @@
1717
package tracing
1818

1919
import (
20-
"github.com/sirupsen/logrus"
20+
"github.com/containerd/log"
2121
"go.opentelemetry.io/otel/attribute"
2222
"go.opentelemetry.io/otel/trace"
2323
)
2424

25+
// allLevels is the equivalent to [logrus.AllLevels].
26+
//
27+
// [logrus.AllLevels]: https://github.com/sirupsen/logrus/blob/v1.9.3/logrus.go#L80-L89
28+
var allLevels = []log.Level{
29+
log.PanicLevel,
30+
log.FatalLevel,
31+
log.ErrorLevel,
32+
log.WarnLevel,
33+
log.InfoLevel,
34+
log.DebugLevel,
35+
log.TraceLevel,
36+
}
37+
2538
// NewLogrusHook creates a new logrus hook
2639
func NewLogrusHook() *LogrusHook {
2740
return &LogrusHook{}
2841
}
2942

30-
// LogrusHook is a logrus hook which adds logrus events to active spans.
31-
// If the span is not recording or the span context is invalid, the hook is a no-op.
43+
// LogrusHook is a [logrus.Hook] which adds logrus events to active spans.
44+
// If the span is not recording or the span context is invalid, the hook
45+
// is a no-op.
46+
//
47+
// [logrus.Hook]: https://github.com/sirupsen/logrus/blob/v1.9.3/hooks.go#L3-L11
3248
type LogrusHook struct{}
3349

3450
// Levels returns the logrus levels that this hook is interested in.
35-
func (h *LogrusHook) Levels() []logrus.Level {
36-
return logrus.AllLevels
51+
func (h *LogrusHook) Levels() []log.Level {
52+
return allLevels
3753
}
3854

3955
// Fire is called when a log event occurs.
40-
func (h *LogrusHook) Fire(entry *logrus.Entry) error {
56+
func (h *LogrusHook) Fire(entry *log.Entry) error {
4157
span := trace.SpanFromContext(entry.Context)
4258
if span == nil {
4359
return nil
@@ -57,7 +73,7 @@ func (h *LogrusHook) Fire(entry *logrus.Entry) error {
5773
return nil
5874
}
5975

60-
func logrusDataToAttrs(data logrus.Fields) []attribute.KeyValue {
76+
func logrusDataToAttrs(data map[string]any) []attribute.KeyValue {
6177
attrs := make([]attribute.KeyValue, 0, len(data))
6278
for k, v := range data {
6379
attrs = append(attrs, keyValue(k, v))

0 commit comments

Comments
 (0)