Skip to content

feat(config): wire top-level log_level field in declarative configuration#5351

Open
ocelotl wants to merge 3 commits into
open-telemetry:mainfrom
ocelotl:diego/config-log-level-wiring
Open

feat(config): wire top-level log_level field in declarative configuration#5351
ocelotl wants to merge 3 commits into
open-telemetry:mainfrom
ocelotl:diego/config-log-level-wiring

Conversation

@ocelotl

@ocelotl ocelotl commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

The declarative configuration schema has a top-level log_level field that controls the SDK's internal diagnostic logging verbosity. It was parsed and validated by the schema loader but never read by configure_sdk — so setting it in a config file had no observable effect.

This PR wires log_level into configure_sdk: when the field is present, it maps the OTel SeverityNumber value to a Python logging level and sets it on the opentelemetry root logger. All numbered severity variants (e.g. debug2, warn3) collapse to the same Python tier.

Mapping:

OTel severity Python level
trace, trace2–4 DEBUG
debug, debug2–4 DEBUG
info, info2–4 INFO
warn, warn2–4 WARNING
error, error2–4 ERROR
fatal, fatal2–4 CRITICAL

When log_level is absent the logger is untouched, preserving existing behaviour.

Fixes the gap noted in #5347 (log_level ❌ — No tracker yet).

Type of change

  • Bug fix / gap closure (non-breaking change that makes existing behaviour match the spec)

How Has This Been Tested?

Three new unit tests in test_sdk.py:

  • test_sets_opentelemetry_logger_level — verifies a specific severity sets the expected level
  • test_absent_log_level_leaves_logger_unchanged — verifies no mutation when field is absent
  • test_severity_number_variants_map_correctly — exhaustive subTest over all tiers (trace, debug, info, warn, error, fatal + their *4 variants)

Does This PR Require a Contrib Repo Change?

  • Yes.
  • No.

Checklist

  • Followed the style guidelines of this project
  • Changelogs have been updated (will add once PR number is known)
  • Unit tests have been added
  • Documentation has been updated (spec-conformance.md row will change from ❌ to ✅)

🤖 Generated with Claude Code

@ocelotl ocelotl requested a review from a team as a code owner June 25, 2026 01:08
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 25, 2026

Copy link
Copy Markdown

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

ocelotl added a commit to ocelotl/opentelemetry-python that referenced this pull request Jun 25, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ocelotl ocelotl marked this pull request as draft June 25, 2026 01:24

@MikeGoldsmith MikeGoldsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generally looks pretty good. I've left one suggestion regarding default level.

Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_sdk.py Outdated
ocelotl and others added 3 commits June 26, 2026 15:35
Map the top-level `log_level` field from declarative configuration to
the `opentelemetry` root logger level so SDK internal diagnostics
respect the configured severity.
Co-authored-by: Mike Goldsmith <goldsmith.mike@gmail.com>
@ocelotl ocelotl force-pushed the diego/config-log-level-wiring branch from 97cc820 to e64f998 Compare June 26, 2026 21:36
@ocelotl ocelotl marked this pull request as ready for review June 26, 2026 21:54

Copilot AI left a comment

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.

Pull request overview

This PR wires the top-level declarative configuration log_level field into configure_sdk so that SDK internal diagnostic logging verbosity can be controlled via config, aligning behavior with the declarative configuration schema.

Changes:

  • Add an OTel SeverityNumber → Python logging level mapping and apply it to the opentelemetry logger when log_level is present.
  • Add unit tests covering logger-level mutation behavior (set vs absent) and severity variant mapping.
  • Add a changelog fragment describing the new behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_sdk.py Applies config.log_level by mapping SeverityNumber to Python logging tiers and setting the opentelemetry logger level.
opentelemetry-sdk/tests/_configuration/test_sdk.py Adds unit tests for log_level behavior and severity mapping.
.changelog/5351.added Documents the feature/gap closure in the changelog fragments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +93 to +95
if config.log_level is not None:
level = _SEVERITY_TO_LOGGING_LEVEL.get(config.log_level, logging.INFO)
logging.getLogger("opentelemetry").setLevel(level)
Comment on lines +128 to +133
def setUp(self):
# Reset the opentelemetry logger level before each test.
logging.getLogger("opentelemetry").setLevel(logging.NOTSET)

def tearDown(self):
logging.getLogger("opentelemetry").setLevel(logging.NOTSET)
Comment on lines +164 to +177
cases = [
(SeverityNumber.trace, logging.DEBUG),
(SeverityNumber.trace4, logging.DEBUG),
(SeverityNumber.debug, logging.DEBUG),
(SeverityNumber.debug4, logging.DEBUG),
(SeverityNumber.info, logging.INFO),
(SeverityNumber.info4, logging.INFO),
(SeverityNumber.warn, logging.WARNING),
(SeverityNumber.warn4, logging.WARNING),
(SeverityNumber.error, logging.ERROR),
(SeverityNumber.error4, logging.ERROR),
(SeverityNumber.fatal, logging.CRITICAL),
(SeverityNumber.fatal4, logging.CRITICAL),
]
Comment thread .changelog/5351.added
@@ -0,0 +1 @@
`opentelemetry-sdk`: wire the top-level `log_level` field in declarative configuration — when set, maps the OTel `SeverityNumber` value to a Python logging level and applies it to the `opentelemetry` root logger so SDK internal diagnostics respect the configured severity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

4 participants