Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions component/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"go.opentelemetry.io/collector/pdata/pcommon"
)
Expand All @@ -26,3 +27,12 @@ type TelemetrySettings struct {
// Resource contains the resource attributes for the collector's telemetry.
Resource pcommon.Resource
}

func (ts *TelemetrySettings) LoggerWithout(fields ...string) *zap.Logger {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this method does make usage cleaner for component authors, which is very nice.

That said, I think it is necessary to expose the interface in this package as well in order to allow reasonable type assertions elsewhere, such as testing the actual implementation of the logger.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, I think it is necessary to expose the interface in this package as well in order to allow reasonable type assertions elsewhere, such as testing the actual implementation of the logger.

Not sure about that, you can have the interface in other place if needed. Example in golang "errors", the Unwrap is not an interface, see

https://cs.opensource.google/go/go/+/refs/tags/go1.23.5:src/errors/wrap.go;l=17

I do believe that if we don't expose an interface, we need to have this as "optional", meaning we need to check if it implements what we want to implement, otherwise return the same logger probably...

return ts.Logger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
wc := core.(interface {
Without(fields ...string) zapcore.Core
})
return wc.Without(fields...)
Comment thread
bogdandrutu marked this conversation as resolved.
}))
}
2 changes: 2 additions & 0 deletions receiver/otlpreceiver/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type otlpReceiver struct {
// responsibility to invoke the respective Start*Reception methods as well
// as the various Stop*Reception methods to end it.
func newOtlpReceiver(cfg *Config, set *receiver.Settings) (*otlpReceiver, error) {
set.Logger = set.TelemetrySettings.LoggerWithout(componentattribute.SignalKey)
set.Logger.Debug("created signal-agnostic logger")
r := &otlpReceiver{
cfg: cfg,
nextTraces: nil,
Expand Down