[Proposal] Ensure a console logging handler is set when using auto-instrumentation #4436
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
If you set up auto-instrumentation and set
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED
to true, calls tologging.basicConfig()
will be a no-op. This means that if you enabled console logging viabasicConfig
before and had logs printed to the console, after setting logging auto instrumentation to true, your logs will no longer be printed to the console, as they will be exported to OTel instead, which may be unexpected.This proposal, if auto-instrumentation is selected, causes the OTel SDK to set up a console (Stream) logger by reading a new environment variable (currently named
OTEL_PYTHON_LOG_FORMAT
) and using that to set up a console logger. Via the env var, you can change the console format from its default value oflogging.BASIC_FORMAT
or disable console logging altogether by making it empty.Fixes #4427
I have tested this manually but haven't added unit tests to this PR yet -- looking to get feedback on the general approach first.