Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Ensure a console logging handler is set when using auto-instrumentation #4436

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pmcollins
Copy link
Member

@pmcollins pmcollins commented Feb 17, 2025

Description

If you set up auto-instrumentation and set OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED to true, calls to logging.basicConfig() will be a no-op. This means that if you enabled console logging via basicConfig 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 of logging.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.

level=logging.NOTSET, logger_provider=provider
logger = logging.getLogger()
logger.addHandler(
LoggingHandler(level=logging.NOTSET, logger_provider=provider)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to make the level configurable as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Problem] Logging integration with opentelemetry auto instrumentation
1 participant