Skip to content

feat(logs): add OTEL_LOG_LEVEL support#5115

Open
grvmishra788 wants to merge 3 commits intoopen-telemetry:mainfrom
grvmishra788:worktree-issue-1059
Open

feat(logs): add OTEL_LOG_LEVEL support#5115
grvmishra788 wants to merge 3 commits intoopen-telemetry:mainfrom
grvmishra788:worktree-issue-1059

Conversation

@grvmishra788
Copy link
Copy Markdown

Description

Fixes #1059: The OTEL_LOG_LEVEL environment variable has been defined in the SDK since the SDK was first written, but reading and applying it was never implemented.

With this change, On SDK module load, OTEL_LOG_LEVEL is read and applied to logging.getLogger("opentelemetry.sdk") - the root SDK logger. As a result, all SDK sub-modules (trace, metrics, logs, exporters) inherit the configured level. Accepted values: debug, info, warn, warning, error, critical (case-insensitive). Invalid values emit a WARNING to stderr and fall back to INFO.

What OTEL_LOG_LEVEL controls

OTEL_LOG_LEVEL is scoped to the SDK's own diagnostic output only. It does not filter OTel log records emitted by instrumented applications. This scope is:

  • Specified in the SDK environment-variables spec: "Log level used by the SDK internal logger", linked to error-handling.md#self-diagnostics.
  • Confirmed by SIG member srikanthccv in issue #1059: "The OTEL_LOG_LEVEL is for setting the log level for the loggers used internally by SDK not for your application logs."
  • Confirmed by jeremydvoss in closed PR #4203: "OTEL_LOG_LEVEL: Exists in the SDK but unused. Speced out to be the level for the SDK's internal logger, not the LoggingHandler."

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • pytest opentelemetry-sdk/tests/logs/test_logs.py — all tests pass.
  • TestOtelLogLevelEnvVar.test_otel_log_level_to_python_mapping_accepted_values verifies the _OTEL_LOG_LEVEL_TO_PYTHON dict covers exactly the documented accepted values: {"debug", "info", "warn", "warning", "error", "critical"}.
  • Manual smoke test: set OTEL_LOG_LEVEL=debug before importing the SDK and confirm SDK debug messages appear; set OTEL_LOG_LEVEL=invalid and confirm a WARNING is emitted with the valid values listed.

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 16, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@grvmishra788 grvmishra788 changed the title Worktree issue 1059 feat(logs): add OTEL_LOG_LEVEL support Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Add support for OTEL_LOG_LEVEL env variable

1 participant