Documentation
¶
Overview ¶
Package otelzlog converters hold the functions that are needed to convert between zerolog and otel logging event types
Package otelzlog hook holds the hook that is attached to the zerolog logger ¶
Package otelzlog provides a bridge between zerolog and otel logging
Index ¶
- func New(name string, options ...Option) *zerolog.Logger
- type Hook
- type Option
- func WithAttachSpanEvent(attach bool) Option
- func WithAttributes(attributes ...attribute.KeyValue) Option
- func WithLoggerProvider(provider otelLog.LoggerProvider) Option
- func WithSchemaURL(schemaURL string) Option
- func WithSetSpanErrorStatus(set bool, level zerolog.Level) Option
- func WithSource(source bool, offset int) Option
- func WithStackHandling() Option
- func WithVersion(version string) Option
- func WithWriter(w io.Writer) Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New creates a new *zerolog.Logger.
Example ¶
// Make sure there's something that can receive your otel telemetry
// and set up your OTEL exporters
recorder := otelrecorder.NewRecorder()
defer recorder.Cleanup()
// Create your new logger
logger := New(
"test",
WithLoggerProvider(recorder.LogProvider),
)
// Start a span and send a log event.
tracer := otel.Tracer("test.service")
func() {
ctx, span := tracer.Start(context.Background(), "segment")
defer span.End()
// The context with the span is passed to the logger with the `Ctx` method.
logger.Info().Ctx(ctx).Msg("test message")
}()
// Check that the log event has made it to the telemetry
{
logs := recorder.GetLogs()
if len(logs) == 1 {
fmt.Println(logs[0].Body.AsString())
}
}
Output: test message
Types ¶
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook is the parent struct of the otelzlog handler
type Option ¶ added in v1.0.23
type Option interface {
// contains filtered or unexported methods
}
Option configures the zerolog hook.
func WithAttachSpanEvent ¶ added in v1.0.23
WithAttachSpanEvent returns an Option that configures the Hook to attach an event to the otel span the zerolog event.
func WithAttributes ¶ added in v1.0.23
WithAttributes returns an Option that configures the instrumentation scope attributes of the log.Logger used by a Hook.
func WithLoggerProvider ¶ added in v1.0.23
func WithLoggerProvider(provider otelLog.LoggerProvider) Option
WithLoggerProvider returns an Option that configures log.LoggerProvider used by a Hook to create its log.Logger.
By default if this Option is not provided, the Handler will use the global LoggerProvider.
func WithSchemaURL ¶ added in v1.0.23
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 WithSetSpanErrorStatus ¶ added in v1.0.24
WithSetSpanErrorStatus returns an Option that configures the Hook to set the span as errored when the provided level or higher is called.
func WithSource ¶ added in v1.0.23
WithSource returns an Option that configures the Hook to include the source location of the log record in log attributes. Offset should be increased if using a helper function to wrap the logger call.
func WithStackHandling ¶ added in v1.0.23
func WithStackHandling() Option
WithStackHandling returns an Option that sets zerolog.ErrorStackMarshaler in order to extract the stack when .Stack() is called on a .Error() event.
A Str(). called "stack" can also be passed in and will be set in the OTEL logs/traces accordingly.
func WithVersion ¶ added in v1.0.23
WithVersion returns an Option that configures the version of the log.Logger used by a [Hoo]. The version should be the version of the package that is being logged.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package otelrecorder provides a utility for recording OpenTelemetry logs and traces in tests.
|
Package otelrecorder provides a utility for recording OpenTelemetry logs and traces in tests. |