-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[otelcol] Allow confmap to write logs using configured logger #10008
Changes from 1 commit
562baaf
31b4ef9
d23b50a
47b5f0c
8f3211e
8f25cb3
8e9bce4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
|
||
"go.uber.org/multierr" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zaptest/observer" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/confmap" | ||
|
@@ -109,14 +110,17 @@ type Collector struct { | |
signalsChannel chan os.Signal | ||
// asyncErrorChannel is used to signal a fatal error from any component. | ||
asyncErrorChannel chan error | ||
|
||
ol *observer.ObservedLogs | ||
} | ||
|
||
// NewCollector creates and returns a new instance of Collector. | ||
func NewCollector(set CollectorSettings) (*Collector, error) { | ||
var err error | ||
configProvider := set.ConfigProvider | ||
|
||
set.ConfigProviderSettings.ResolverSettings.ProviderSettings = confmap.ProviderSettings{Logger: zap.NewNop()} | ||
core, ol := observer.New(zap.DebugLevel) | ||
set.ConfigProviderSettings.ResolverSettings.ProviderSettings = confmap.ProviderSettings{Logger: zap.New(core)} | ||
set.ConfigProviderSettings.ResolverSettings.ConverterSettings = confmap.ConverterSettings{} | ||
mx-psi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if configProvider == nil { | ||
|
@@ -137,6 +141,7 @@ func NewCollector(set CollectorSettings) (*Collector, error) { | |
signalsChannel: make(chan os.Signal, 3), | ||
asyncErrorChannel: make(chan error), | ||
configProvider: configProvider, | ||
ol: ol, | ||
}, nil | ||
} | ||
|
||
|
@@ -202,6 +207,12 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error { | |
return err | ||
} | ||
|
||
if col.ol != nil { | ||
for _, log := range col.ol.All() { | ||
col.service.Logger().Log(log.Level, log.Message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering if we should use the core directly here via its Do you think it's worth the effort? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would having out-of-order timestamps be a problem? I dont think stacktraces is a valid scenario bc currently if the confmap errors its logs will not get written. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't get what you mean by this. What I meant is that instead of having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at #10056 this is actually necessary since we are not logging the fields (if you compare the screenshots, with this PR you don't know what env var is unset) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't like the idea of duplicating functionality that exists in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I can fix the field issue by passing in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To be clear: it does not exist in zapcore, it exists in |
||
} | ||
} | ||
|
||
if !col.set.SkipSettingGRPCLogger { | ||
grpclog.SetLogger(col.service.Logger(), cfg.Service.Telemetry.Logs.Level) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bringing in a test import here seems a bit strange. from the observer docs:
I worry that this package may change in the future causing issue, but maybe it's not a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're certainly using the package in a use case I think they didn't intend. I still think the simplicity of #10007 is most appropriate as it is the collector making logging decisions before being told how to log. It keeps the logs in proper order as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that should be a problem since (i) the fact that we use this package is an implementation detail and (ii) even if the package disappeared we could rebuild it ourselves (it does not depend on any internal bits of zap)