17
17
package tracing
18
18
19
19
import (
20
- "github.com/sirupsen/logrus "
20
+ "github.com/containerd/log "
21
21
"go.opentelemetry.io/otel/attribute"
22
22
"go.opentelemetry.io/otel/trace"
23
23
)
24
24
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
+
25
38
// NewLogrusHook creates a new logrus hook
26
39
func NewLogrusHook () * LogrusHook {
27
40
return & LogrusHook {}
28
41
}
29
42
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
32
48
type LogrusHook struct {}
33
49
34
50
// 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
37
53
}
38
54
39
55
// 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 {
41
57
span := trace .SpanFromContext (entry .Context )
42
58
if span == nil {
43
59
return nil
44
60
}
45
61
46
- if ! span .SpanContext (). IsValid () || ! span .IsRecording () {
62
+ if ! span .IsRecording () || ! span .SpanContext (). IsValid () {
47
63
return nil
48
64
}
49
65
@@ -57,10 +73,10 @@ func (h *LogrusHook) Fire(entry *logrus.Entry) error {
57
73
return nil
58
74
}
59
75
60
- func logrusDataToAttrs (data logrus. Fields ) []attribute.KeyValue {
76
+ func logrusDataToAttrs (data map [ string ] any ) []attribute.KeyValue {
61
77
attrs := make ([]attribute.KeyValue , 0 , len (data ))
62
78
for k , v := range data {
63
- attrs = append (attrs , any (k , v ))
79
+ attrs = append (attrs , keyValue (k , v ))
64
80
}
65
81
return attrs
66
82
}
0 commit comments