From 50a533a2761ecff32dc68c54a5ae5d418c30df4e Mon Sep 17 00:00:00 2001 From: igorpeshansky <7594381+igorpeshansky@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:11:42 -0500 Subject: [PATCH] [otelcol] Tell all loggers to encode timestamps in ISO8601. (#10543) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### Description OTel collector log messages in Windows are currently displayed in scientific notation, e.g.: ``` 1.7194132367192364e+09 error scraperhelper/scrapercontroller.go:197 Error scraping metrics … ``` This fix will cause the log messages to use ISO8601 timestamps instead. #### Testing Manual testing. #### Documentation The previous behavior was undocumented, so no documentation changes needed. --------- Co-authored-by: Daniel Jaglowski --- ...orpeshansky-windows-logger-timestamps.yaml | 28 +++++++++++++++++++ otelcol/collector_windows.go | 1 + service/telemetry/logger.go | 4 ++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .chloggen/igorpeshansky-windows-logger-timestamps.yaml diff --git a/.chloggen/igorpeshansky-windows-logger-timestamps.yaml b/.chloggen/igorpeshansky-windows-logger-timestamps.yaml new file mode 100644 index 000000000000..f41e95ee95aa --- /dev/null +++ b/.chloggen/igorpeshansky-windows-logger-timestamps.yaml @@ -0,0 +1,28 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: otelcol + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Change all logged timestamps to ISO8601. + +# One or more tracking issues or pull requests related to the change +issues: [10543] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: |- + This makes log timestamps human-readable (as opposed to epoch seconds in + scientific notation), but may break users trying to parse logged lines in the + old format. + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/otelcol/collector_windows.go b/otelcol/collector_windows.go index 7e9099e02a94..ce52a4647d43 100644 --- a/otelcol/collector_windows.go +++ b/otelcol/collector_windows.go @@ -225,6 +225,7 @@ func withWindowsCore(elog *eventlog.Log, serviceConfig **service.Config) func(za // Use the Windows Event Log encoderConfig := zap.NewProductionEncoderConfig() encoderConfig.LineEnding = "\r\n" + encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder return windowsEventLogCore{core, elog, zapcore.NewConsoleEncoder(encoderConfig)} } } diff --git a/service/telemetry/logger.go b/service/telemetry/logger.go index a47584985fbc..d1f06b34fd9f 100644 --- a/service/telemetry/logger.go +++ b/service/telemetry/logger.go @@ -13,11 +13,13 @@ import ( // newLogger creates a Logger and a LoggerProvider from Config. func newLogger(set Settings, cfg Config) (*zap.Logger, log.LoggerProvider, error) { // Copied from NewProductionConfig. + ec := zap.NewProductionEncoderConfig() + ec.EncodeTime = zapcore.ISO8601TimeEncoder zapCfg := &zap.Config{ Level: zap.NewAtomicLevelAt(cfg.Logs.Level), Development: cfg.Logs.Development, Encoding: cfg.Logs.Encoding, - EncoderConfig: zap.NewProductionEncoderConfig(), + EncoderConfig: ec, OutputPaths: cfg.Logs.OutputPaths, ErrorOutputPaths: cfg.Logs.ErrorOutputPaths, DisableCaller: cfg.Logs.DisableCaller,