feat(config): wire top-level log_level field in declarative configuration#5351
Open
ocelotl wants to merge 3 commits into
Open
feat(config): wire top-level log_level field in declarative configuration#5351ocelotl wants to merge 3 commits into
ocelotl wants to merge 3 commits into
Conversation
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>
MikeGoldsmith
left a comment
Member
There was a problem hiding this comment.
Generally looks pretty good. I've left one suggestion regarding default level.
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>
97cc820 to
e64f998
Compare
herin049
approved these changes
Jun 30, 2026
Contributor
There was a problem hiding this comment.
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→ Pythonlogginglevel mapping and apply it to theopentelemetrylogger whenlog_levelis 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), | ||
| ] |
| @@ -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. | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The declarative configuration schema has a top-level
log_levelfield that controls the SDK's internal diagnostic logging verbosity. It was parsed and validated by the schema loader but never read byconfigure_sdk— so setting it in a config file had no observable effect.This PR wires
log_levelintoconfigure_sdk: when the field is present, it maps the OTelSeverityNumbervalue to a Pythonlogginglevel and sets it on theopentelemetryroot logger. All numbered severity variants (e.g.debug2,warn3) collapse to the same Python tier.Mapping:
trace,trace2–4DEBUGdebug,debug2–4DEBUGinfo,info2–4INFOwarn,warn2–4WARNINGerror,error2–4ERRORfatal,fatal2–4CRITICALWhen
log_levelis absent the logger is untouched, preserving existing behaviour.Fixes the gap noted in #5347 (
log_level ❌ — No tracker yet).Type of change
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 leveltest_absent_log_level_leaves_logger_unchanged— verifies no mutation when field is absenttest_severity_number_variants_map_correctly— exhaustive subTest over all tiers (trace, debug, info, warn, error, fatal + their*4variants)Does This PR Require a Contrib Repo Change?
Checklist
🤖 Generated with Claude Code