-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(log)!: intoduce log v2 with OpenTelemetry and slog #25701
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25701 +/- ##
==========================================
- Coverage 70.26% 70.04% -0.22%
==========================================
Files 835 843 +8
Lines 54361 55094 +733
==========================================
+ Hits 38196 38592 +396
- Misses 16165 16502 +337
🚀 New features to boost your workflow:
|
log/CHANGELOG.md
Outdated
|
|
||
| ## [Unreleased] | ||
|
|
||
| * [#25701](https://github.com/cosmos/cosmos-sdk/pull/25701) Introduce log v2, enabling OpenTelemetry logging with slog. The logging interface has been updated to accommodate Context logging methods, which allows correlation of logs with traces. |
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.
can we link to the upgrade guide for this?
log/logger.go
Outdated
| opt(&logCfg) | ||
| // newZerologLogger creates a Logger backed by zerolog directly. | ||
| // This is the fast path with zero allocations. | ||
| func newZerologLogger(dst io.Writer, cfg *Config) Logger { |
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.
previously we filled out the default config and overrode it. Why are we making this change and should cfg be nullable (a pointer)?
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 still do that, it's just pulled up to the top level NewLogger now. ill remove the pointers
| } | ||
| } | ||
|
|
||
| func TestVerboseMode(t *testing.T) { |
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.
did we remove this test accidentally?
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.
yes, adding back in
| // Impl returns the underlying zerolog logger. | ||
| // It can be used to use zerolog structured API directly instead of the wrapper. | ||
| func (l zeroLogWrapper) Impl() interface{} { | ||
| func (l *zeroLogWrapper) Impl() interface{} { |
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.
should return the concrete type here
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.
this would break the interface
| // nil = check LoggerProvider. | ||
| // true = force enable | ||
| // false = force disable | ||
| EnableOTEL *bool |
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.
why pointer
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 wanted to have presence checking here. if set at all, we know that this was explicitly set with the WithOTEL or WIthoutOTEL options. if unset, we can make a decision based on if they had a provider set in their otel configuration.
on second thought though, perhaps we just enable it if they have otel set at all. not actually sure its useful to have this expression here.
| // this test ensures that when the With and WithContext methods are called, | ||
| // that the log wrapper is properly copied with all of its associated options | ||
| // otherwise, verbose mode will fail | ||
| func TestLoggerWith(t *testing.T) { |
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.
seems like this test would be fine to still include?
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.
added back, but removed the wrapper3 case because the return type changed, making that test case invalid.
server/cmd/execute.go
Outdated
| ctx := CreateExecuteContext(context.Background()) | ||
|
|
||
| rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:<level>,<key>:<level>')") | ||
| rootCmd.PersistentFlags().String(flags.FlagLogLevel, "info", "The logging level (debug|info|warn|error|disabled or '*:<level>,<key>:<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.
can we not use the library values from slog etc or something?
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.
yeah added slog.InfoLevel.String() here instead of "info"
server/util.go
Outdated
| viper.New(), | ||
| cmtcfg.DefaultConfig(), | ||
| log.NewLogger(os.Stdout), | ||
| log.NewLogger("cosmos-sdk", log.WithConsoleWriter(os.Stdout)), |
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.
should we define a constant for this name? or a default somehow?
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.
added it to a const block
| @@ -1,373 +0,0 @@ | |||
| //go:build !app_v1 | |||
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.
why did this need to be removed (not opposed)
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.
oops. meant to add back after testing.
Description
Closes: SDK-430
refactors the log package to add support for OpenTelemetry trace correlation. notable changes:
log.With<Option>rather thanlog.SomeOption