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 <github@gone.nl>
This commit is contained in:
parent
4203e2de8d
commit
ccf7938126
@ -17,27 +17,43 @@
|
|||||||
package tracing
|
package tracing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/containerd/log"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// allLevels is the equivalent to [logrus.AllLevels].
|
||||||
|
//
|
||||||
|
// [logrus.AllLevels]: https://github.com/sirupsen/logrus/blob/v1.9.3/logrus.go#L80-L89
|
||||||
|
var allLevels = []log.Level{
|
||||||
|
log.PanicLevel,
|
||||||
|
log.FatalLevel,
|
||||||
|
log.ErrorLevel,
|
||||||
|
log.WarnLevel,
|
||||||
|
log.InfoLevel,
|
||||||
|
log.DebugLevel,
|
||||||
|
log.TraceLevel,
|
||||||
|
}
|
||||||
|
|
||||||
// NewLogrusHook creates a new logrus hook
|
// NewLogrusHook creates a new logrus hook
|
||||||
func NewLogrusHook() *LogrusHook {
|
func NewLogrusHook() *LogrusHook {
|
||||||
return &LogrusHook{}
|
return &LogrusHook{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogrusHook is a logrus hook which adds logrus events to active spans.
|
// LogrusHook is a [logrus.Hook] which adds logrus events to active spans.
|
||||||
// If the span is not recording or the span context is invalid, the hook is a no-op.
|
// If the span is not recording or the span context is invalid, the hook
|
||||||
|
// is a no-op.
|
||||||
|
//
|
||||||
|
// [logrus.Hook]: https://github.com/sirupsen/logrus/blob/v1.9.3/hooks.go#L3-L11
|
||||||
type LogrusHook struct{}
|
type LogrusHook struct{}
|
||||||
|
|
||||||
// Levels returns the logrus levels that this hook is interested in.
|
// Levels returns the logrus levels that this hook is interested in.
|
||||||
func (h *LogrusHook) Levels() []logrus.Level {
|
func (h *LogrusHook) Levels() []log.Level {
|
||||||
return logrus.AllLevels
|
return allLevels
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire is called when a log event occurs.
|
// Fire is called when a log event occurs.
|
||||||
func (h *LogrusHook) Fire(entry *logrus.Entry) error {
|
func (h *LogrusHook) Fire(entry *log.Entry) error {
|
||||||
span := trace.SpanFromContext(entry.Context)
|
span := trace.SpanFromContext(entry.Context)
|
||||||
if span == nil {
|
if span == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -57,7 +73,7 @@ func (h *LogrusHook) Fire(entry *logrus.Entry) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func logrusDataToAttrs(data logrus.Fields) []attribute.KeyValue {
|
func logrusDataToAttrs(data map[string]any) []attribute.KeyValue {
|
||||||
attrs := make([]attribute.KeyValue, 0, len(data))
|
attrs := make([]attribute.KeyValue, 0, len(data))
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
attrs = append(attrs, keyValue(k, v))
|
attrs = append(attrs, keyValue(k, v))
|
||||||
|
Loading…
Reference in New Issue
Block a user