Documentation ¶
Overview ¶
Package otellogrus provides a Hook, a logrus.Hook implementation that can be used to bridge between the github.com/sirupsen/logrus API and OpenTelemetry.
Record Conversion ¶
The logrus.Entry records are converted to OpenTelemetry log.Record in the following way:
- Time is set as the Timestamp.
- Message is set as the Body using a log.StringValue.
- Level is transformed and set as the Severity. The SeverityText is not set.
- Fields are transformed and set as the attributes.
The Level is transformed by using the static offset to the OpenTelemetry Severity types. For example:
- [slog.LevelDebug] is transformed to log.SeverityDebug
- [slog.LevelInfo] is transformed to log.SeverityInfo
- [slog.LevelWarn] is transformed to log.SeverityWarn
- [slog.LevelError] is transformed to log.SeverityError
Attribute values are transformed based on their type into log attributes, or into a string value if there is no matching type.
Example ¶
package main import ( "github.com/sirupsen/logrus" "go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/otel/log/noop" ) func main() { // Use a working LoggerProvider implementation instead e.g. using go.opentelemetry.io/otel/sdk/log. provider := noop.NewLoggerProvider() // Create an *otellogrus.Hook and use it in your application. hook := otellogrus.NewHook("my/pkg/name", otellogrus.WithLoggerProvider(provider)) // Set the newly created hook as a global logrus hook logrus.AddHook(hook) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook is a logrus.Hook that sends all logging records it receives to OpenTelemetry. See package documentation for how conversions are made.
func NewHook ¶
NewHook returns a new Hook to be used as a logrus.Hook.
If WithLoggerProvider is not provided, the returned Hook will use the global LoggerProvider.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures a Hook.
func WithLevels ¶
WithLevels returns an Option that configures the log levels that will fire the configured Hook.
By default if this Option is not provided, the Hook will fire for all levels. LoggerProvider.
func WithLoggerProvider ¶
func WithLoggerProvider(provider log.LoggerProvider) Option
WithLoggerProvider returns an Option that configures log.LoggerProvider used by a Hook.
By default if this Option is not provided, the Hook will use the global LoggerProvider.
func WithSchemaURL ¶
WithSchemaURL returns an Option that configures the semantic convention schema URL of the log.Logger used by a Hook. The schemaURL should be the schema URL for the semantic conventions used in log records.
func WithVersion ¶
WithVersion returns an Option that configures the version of the log.Logger used by a Hook. The version should be the version of the package that is being logged.