Skip to content

Commit

Permalink
[otelcol] Tell all loggers to encode timestamps in ISO8601. (open-tel…
Browse files Browse the repository at this point in the history
…emetry#10543)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### 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.

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Manual testing.

<!--Describe the documentation added.-->
#### Documentation
The previous behavior was undocumented, so no documentation changes
needed.

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Co-authored-by: Daniel Jaglowski <[email protected]>
  • Loading branch information
2 people authored and HongChenTW committed Dec 19, 2024
1 parent e5b63e4 commit 50a533a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .chloggen/igorpeshansky-windows-logger-timestamps.yaml
Original file line number Diff line number Diff line change
@@ -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]
1 change: 1 addition & 0 deletions otelcol/collector_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
}
}
4 changes: 3 additions & 1 deletion service/telemetry/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 50a533a

Please sign in to comment.