feat(logs): add OTEL_LOG_LEVEL support#5115
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 |
|
Ah, I see the problem - Adding We need to move it somewhere else, but then we'll lose the automatic resolution we wanted by putting it in init. Maybe put it back in _internal/init and add it to |
MikeGoldsmith
left a comment
There was a problem hiding this comment.
Moving to request changes until we fix the resolution problem.
Thanks for letting me know. switched to Towncrier changelog fragment instead. |
|
This PR and the auto-instrumentation PR (open-telemetry/opentelemetry-python-contrib#4542) should not conflict but noting that |
Python has no TRACE level; the OTel declarative config schema includes "trace" as a valid log level value, so mapping it to DEBUG aligns with the config model.
|
Hi @MikeGoldsmith @emdneto @pmcollins - this PR has been open for a while and I believe all the feedback has been addressed. Would appreciate a final review & merge when you get a chance. Thanks! |
Did we you fix the namespace issue that Mike mentioned above? |
Yes @aabmass, that issue is fixed now. I moved |
|
This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. |
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: