feat(logs): add OTEL_LOG_LEVEL support#5115
Open
grvmishra788 wants to merge 3 commits intoopen-telemetry:mainfrom
Open
feat(logs): add OTEL_LOG_LEVEL support#5115grvmishra788 wants to merge 3 commits intoopen-telemetry:mainfrom
grvmishra788 wants to merge 3 commits intoopen-telemetry:mainfrom
Conversation
22fd4b2 to
7c01660
Compare
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
Fixes #1059: The
OTEL_LOG_LEVELenvironment 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_LEVELis read and applied tologging.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 aWARNINGto stderr and fall back toINFO.What
OTEL_LOG_LEVELcontrolsOTEL_LOG_LEVELis scoped to the SDK's own diagnostic output only. It does not filter OTel log records emitted by instrumented applications. This scope is:OTEL_LOG_LEVELis for setting the log level for the loggers used internally by SDK not for your application logs."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
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_valuesverifies the_OTEL_LOG_LEVEL_TO_PYTHONdict covers exactly the documented accepted values:{"debug", "info", "warn", "warning", "error", "critical"}.OTEL_LOG_LEVEL=debugbefore importing the SDK and confirm SDK debug messages appear; setOTEL_LOG_LEVEL=invalidand confirm aWARNINGis emitted with the valid values listed.Does This PR Require a Contrib Repo Change?
Checklist: