[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 a user sets up auto-instrumentation and sets
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED
to true, any calls tologging.basicConfig()
will be no-ops. This means that if console logging was previously enabled viabasicConfig
and logs were printed to the console, after turning on logging auto-instrumentation, logs will be exported to OTel and will no longer be printed to the console.This proposal is: if under auto-instrumentation, the OTel SDK will explicitly set up a console/stream logger by reading a new environment variable,
OTEL_PYTHON_LOG_FORMAT
. If the user requests logging auto-instrumentation, the SDK will read the environment variable: if it's set and not empty, the SDK will use that as a custom format; if explicitly empty, the SDK will skip setting up a console logger altogether. This could give users a smoother experience when setting up logging auto instrumentation as their logs will appear on the console by default under auto-instrumentation, but they'll still have control over the format, including the ability to turn console logging off.A possible drawback is if a user does not have console logging turned on and they turn on logging auto-instrumentation, they will start getting logs printed to the console when they didn't have any before. They would have to turn it off explicitly by setting
OTEL_PYTHON_LOG_FORMAT=""
.Addresses #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.