Skip to content

Conversation

@technicallyty
Copy link
Contributor

@technicallyty technicallyty commented Dec 16, 2025

Description

Closes: SDK-430

refactors the log package to add support for OpenTelemetry trace correlation. notable changes:

  • extended logging interface to add context methods - allows trace correlation.
  • logging constructor function signature changed
  • logging options all changed to be more standard i.e. log.With<Option> rather than log.SomeOption
  • if no opentelemetry configuration is set, we simply use zerolog as we did before.
  • if an OpenTelemetry configuration is set, we use slog, and all logs are output to console and forwarded to the configured logger provider (otel.yml).
  • New flag introduced, --log_no_console, to allow logs to ONLY go to otel, not to console. (performance related)
  • reduced log levels to align with slog. some zerolog levels won't be supported now

@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 40.15748% with 304 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.04%. Comparing base (fd82917) to head (0aff0fd).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
log/logger.go 22.94% 225 Missing ⚠️
telemetry/config.go 0.00% 22 Missing ⚠️
log/testing.go 75.32% 19 Missing ⚠️
log/options.go 50.00% 16 Missing ⚠️
server/util.go 70.00% 9 Missing ⚠️
server/cmd/execute.go 0.00% 3 Missing ⚠️
log/writer.go 0.00% 2 Missing ⚠️
client/pruning/main.go 0.00% 1 Missing ⚠️
client/snapshot/export.go 0.00% 1 Missing ⚠️
client/snapshot/restore.go 0.00% 1 Missing ⚠️
... and 5 more
Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
baseapp/abci.go 86.90% <100.00%> (ø)
client/flags/flags.go 81.81% <ø> (ø)
server/api/server.go 66.31% <100.00%> (ø)
client/pruning/main.go 0.00% <0.00%> (ø)
client/snapshot/export.go 0.00% <0.00%> (ø)
client/snapshot/restore.go 0.00% <0.00%> (ø)
log/level.go 95.00% <97.50%> (ø)
server/cmt_cmds.go 0.00% <0.00%> (ø)
server/start.go 18.57% <0.00%> (ø)
testutil/network/network.go 77.20% <0.00%> (ø)
... and 8 more

... and 6 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot removed the C:Store label Jan 6, 2026
@technicallyty technicallyty marked this pull request as ready for review January 6, 2026 19:46
@swift1337 swift1337 self-requested a review January 6, 2026 19:56
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.
Copy link
Contributor

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 {
Copy link
Contributor

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)?

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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{} {
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why pointer

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

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>')")
Copy link
Contributor

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?

Copy link
Contributor Author

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)),
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C:CLI C:Cosmovisor Issues and PR related to Cosmovisor C:log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants