Skip to content

Commit b9ff1bc

Browse files
[otelcol] Tell all loggers to encode timestamps in ISO8601. (#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]>
1 parent 4782ad0 commit b9ff1bc

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: otelcol
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Change all logged timestamps to ISO8601.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [10543]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |-
19+
This makes log timestamps human-readable (as opposed to epoch seconds in
20+
scientific notation), but may break users trying to parse logged lines in the
21+
old format.
22+
23+
# Optional: The change log or logs in which this entry should be included.
24+
# e.g. '[user]' or '[user, api]'
25+
# Include 'user' if the change is relevant to end users.
26+
# Include 'api' if there is a change to a library API.
27+
# Default: '[user]'
28+
change_logs: [user]

otelcol/collector_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func withWindowsCore(elog *eventlog.Log, serviceConfig **service.Config) func(za
225225
// Use the Windows Event Log
226226
encoderConfig := zap.NewProductionEncoderConfig()
227227
encoderConfig.LineEnding = "\r\n"
228+
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
228229
return windowsEventLogCore{core, elog, zapcore.NewConsoleEncoder(encoderConfig)}
229230
}
230231
}

service/telemetry/logger.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import (
1313
// newLogger creates a Logger and a LoggerProvider from Config.
1414
func newLogger(set Settings, cfg Config) (*zap.Logger, log.LoggerProvider, error) {
1515
// Copied from NewProductionConfig.
16+
ec := zap.NewProductionEncoderConfig()
17+
ec.EncodeTime = zapcore.ISO8601TimeEncoder
1618
zapCfg := &zap.Config{
1719
Level: zap.NewAtomicLevelAt(cfg.Logs.Level),
1820
Development: cfg.Logs.Development,
1921
Encoding: cfg.Logs.Encoding,
20-
EncoderConfig: zap.NewProductionEncoderConfig(),
22+
EncoderConfig: ec,
2123
OutputPaths: cfg.Logs.OutputPaths,
2224
ErrorOutputPaths: cfg.Logs.ErrorOutputPaths,
2325
DisableCaller: cfg.Logs.DisableCaller,

0 commit comments

Comments
 (0)