Opentelemetry-go: Standardize logging practices within the SDK and plugins

Created on 18 Aug 2020  路  2Comments  路  Source: open-telemetry/opentelemetry-go

I'm working on a Cortex Exporter and noticed that there isn't much consistency as to what logging package is used across the various components (instrumentation plugins, exporters, etc.). As mentioned by @MrAlias on Gitter, this should probably be configurable by the end user. The standard log package would probably be a smart default, but I'd like to start a discussion on what the default package should be and how we can make this configurable. Thanks.

question after-ga

Most helpful comment

A pattern I've had success with in the past is to define a simple interface and provide accessors that fallback to the stdlib log package if no implementation is provided.

type Logger interface {
  Print(v ...interface{})
  Printf(format string, v ...interface{})
  // etc., maybe Fatal/Fatalf
}

func FromContext(ctx context.Context) Logger {...}

I'd really like to be able to attach labels/fields to a log entry, but I'm not sure there's any consistent interface that could be expected to be common between log, logrus, zap, and any other likely candidate for a Logger implementation.

All 2 comments

A pattern I've had success with in the past is to define a simple interface and provide accessors that fallback to the stdlib log package if no implementation is provided.

type Logger interface {
  Print(v ...interface{})
  Printf(format string, v ...interface{})
  // etc., maybe Fatal/Fatalf
}

func FromContext(ctx context.Context) Logger {...}

I'd really like to be able to attach labels/fields to a log entry, but I'm not sure there's any consistent interface that could be expected to be common between log, logrus, zap, and any other likely candidate for a Logger implementation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dackroyd picture dackroyd  路  3Comments

ThomsonTan picture ThomsonTan  路  3Comments

XSAM picture XSAM  路  3Comments

MrAlias picture MrAlias  路  5Comments

MrAlias picture MrAlias  路  7Comments