Skip to content

wip: configure SDK internal logger from log_level#8413

Draft
CtrlSpice wants to merge 3 commits intoopen-telemetry:mainfrom
CtrlSpice:otelconf-add-log-level
Draft

wip: configure SDK internal logger from log_level#8413
CtrlSpice wants to merge 3 commits intoopen-telemetry:mainfrom
CtrlSpice:otelconf-add-log-level

Conversation

@CtrlSpice
Copy link
Copy Markdown

Description

Implements support for the log_level configuration field to configure the SDK's internal logger via otel.SetLogger().

The log level maps to stdr verbosity as follows:

log_level Verbosity SDK messages shown
trace, debug 8 Debug, Info, Warn
info 4 Info, Warn
warn 1 Warn only
error, fatal 0 Errors only

Numeric suffixes (e.g., debug2, trace4) are accepted and mapped to their base level, since Go's logr doesn't have that granularity.

Closes #8210

Changes

  • Added setInternalLogger() function in config.go
  • Added unit tests for setInternalLogger()
  • Added integration test case for invalid log_level in TestNewSDK

Testing

All existing tests pass. New tests cover:

  • Valid log levels: info, debug, debug2, warn, error, trace, trace4, fatal
  • Invalid log levels return errors
  • nil (unset) is handled gracefully

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Jan 16, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

Copy link
Copy Markdown
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Thanks @CtrlSpice! Added some comments

case "error", "fatal":
stdr.SetVerbosity(0)
default:
return fmt.Errorf("invalid log_level %q", *logLevel)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can return a newErrInvalid here

return noopSDK, nil
}

if err := setInternalLogger(o.opentelemetryConfig.LogLevel); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would love some thoughts from @open-telemetry/go-approvers on whether this should set a logger here or if it should provide a method to return a configured logger that can be set by the caller of this function.

Since the rest of this code is not modifying the global context, i suspect the latter, even though setting the logger here is nice

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Happy to refactor to return a configured logger if that's more consistent!

CHANGELOG.md Outdated
Comment on lines 13 to 14
- Add support for `log_level` configuration to set the SDK's internal logger verbosity in `go.opentelemetry.io/contrib/otelconf`. (#8210)
- `WithMetricAttributesFn` option in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` to define dynamic attributes on auto-instrumented metrics. (#8191)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Add support for `log_level` configuration to set the SDK's internal logger verbosity in `go.opentelemetry.io/contrib/otelconf`. (#8210)
- `WithMetricAttributesFn` option in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` to define dynamic attributes on auto-instrumented metrics. (#8191)
- `WithMetricAttributesFn` option in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` to define dynamic attributes on auto-instrumented metrics. (#8191)
- Add support for `log_level` configuration to set the SDK's internal logger verbosity in `go.opentelemetry.io/contrib/otelconf`. (#8210)

@CtrlSpice CtrlSpice force-pushed the otelconf-add-log-level branch from 81fd4c9 to 40cc037 Compare January 19, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

otelconf: add support for log_level

2 participants