feat(logs): add OTEL_LOG_LEVEL support#5115
feat(logs): add OTEL_LOG_LEVEL support#5115grvmishra788 wants to merge 11 commits intoopen-telemetry:mainfrom
Conversation
22fd4b2 to
7c01660
Compare
MikeGoldsmith
left a comment
There was a problem hiding this comment.
Thanks @grvmishra788. I think we need to move this so the main sdk/__init__.py so we don't need users to import another module.
MikeGoldsmith
left a comment
There was a problem hiding this comment.
Thanks @grvmishra788 - looks really good. Just a few final tweaks for an errant new line and update to the changelog.
|
Hi @MikeGoldsmith! Could you please take a look at the PR now? It has been in review for a while. |
MikeGoldsmith
left a comment
There was a problem hiding this comment.
Sorry for the delay, thanks @grvmishra788 🚀
|
@MikeGoldsmith One of the CI checks failed |
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.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: