Skip to content

Commit 1f5b7bd

Browse files
committed
add comment
1 parent 06fddf2 commit 1f5b7bd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/loop/logger.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ func NewLogger() (logger.Logger, error) {
173173
})
174174
}
175175

176+
// NewOtelLogger returns a logger with two cores:
177+
// 1. The primary JSON core configured via cfgFn (encoder keys changed to @level, @message, @timestamp).
178+
// 2. The otel core (otelzap.NewCore) which receives the raw zap.Entry and fields.
179+
//
180+
// Important:
181+
// The cfgFn only mutates the encoder config used to build the first core inside logger.NewWithCore.
182+
// otelzap.NewCore implements zapcore.Core and does NOT use that encoder; it derives attributes from the zap.Entry
183+
// (Message, Level, Time, etc.) and zap.Fields directly. Therefore changing encoder keys here does NOT affect how
184+
// the otel core extracts data, and only the first core's JSON output format is altered.
185+
// This preserves backward compatibility for OTEL export while allowing hclog-compatible key names in the primary output.
176186
func NewOtelLogger(otelLogger otellog.Logger) (logger.Logger, error) {
177187
cfgFn := func(cfg *zap.Config) {
178188
cfg.Level.SetLevel(zap.DebugLevel)

0 commit comments

Comments
 (0)