Home | Related |
---|---|
Home | otelslog, otelzerolog |
Package otellogrus
provides a function to extend structured logs using logrus with the Open Telemetry trace related context.
The github.com/sirupsen/logrus
logrus
logs are decorated with standard metadata extracted from the trace.SpanContext
, a traceID, spanID and additional information is injected into a log.
The initialization uses file level configuration to set defaults for the function to use. SetLogOptions
can overwrite the defaults.
When the configuration is done AddTracingContext
and AddTracingContextWithAttributes
decorate logrus
logs with data from the trace context.
Adding trace context ata to logs can be achieved by using logrus.WithFields(AddTracingContext(span)).Info("test")
for example.
func SetLogOptions(options ...LogOption)
func WithTraceID(traceID string) LogOption
func WithSpanID(spanID string) LogOption
func WithServiceName(serviceName string) LogOption
func WithAttributePrefix(prefix string) LogOption
func WithAttributes(attributes ...attribute.KeyValue) LogOption
func AddTracingContext(span trace.Span, err ...error) logrus.Fields
func AddTracingContextWithAttributes(span trace.Span, attributes []attribute.KeyValue, err ...error) logrus.Fields
func WithLevel(level logrus.Level) LoggerOption
func WithFormatter(formatter logrus.Formatter) LoggerOption
func New(options ...LoggerOption) *Logger
func (l Logger) WithTracingContext(span trace.Span, err ...error) *logrus.Entry
func (l Logger) WithTracingContextAndAttributes(span trace.Span, attributes []attribute.KeyValue, err ...error) *logrus.Entry
type LogOption func(*logConfig)
type logConfig struct {
attributes []attribute.KeyValue
serviceName string
traceId string
spanId string
attributePrefix string
}
type Logger struct {
*logrus.Logger
}
type loggerConfig struct {
formatter *logrus.Formatter
level logrus.Level
}