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

opentelemetry.sdk._logs.LoggingHandler panics when exc_info is set to False for logger.error #2689

Closed
gen-xu opened this issue May 15, 2022 · 0 comments · Fixed by #2690
Closed
Labels
bug Something isn't working

Comments

@gen-xu
Copy link
Contributor

gen-xu commented May 15, 2022

Describe your environment Describe any aspect of your environment relevant to the problem, including your Python version, platform, version numbers of installed dependencies, information about your cloud hosting provider, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main.

Steps to reproduce
Describe exactly how to reproduce the error. Include a code sample if applicable.

import logging
from opentelemetry.sdk._logs import LogEmitter, LoggingHandler
from unittest.mock import Mock

logger = logging.getLogger(__name__)
log_emitter= Mock(spec=LogEmitter)
handler = LoggingHandler(level=logging.NOTSET, log_emitter=log_emitter)
logger.addHandler(handler)
logger.error("some message", exc_info=False) # will raise exception: cannot unpack non-iterable bool object

What is the expected behavior?
What did you expect to see?

It should log error message without throwing exception

What is the actual behavior?
What did you see instead?

It throws exception

Exception has occurred: TypeError
cannot unpack non-iterable bool object

Additional context
Python's logger interface allows non-Exception type to be passed in through exc_info see also

If exc_info does not evaluate as false, it causes exception information to be added to the logging message. If an exception tuple (in the format returned by sys.exc_info()) or an exception instance is provided, it is used; otherwise, sys.exc_info() is called to get the exception information.
Add any other context about the problem here.

So exc_info is replaced by logging module only if it evaluates True, but we only check if exc_info is not None here in handler, which would attemp to unpack variable that evaluated as False later, that is not replaced by logging module.

@gen-xu gen-xu added the bug Something isn't working label May 15, 2022
gen-xu added a commit to gen-xu/opentelemetry-python that referenced this issue May 15, 2022
gen-xu added a commit to gen-xu/opentelemetry-python that referenced this issue May 15, 2022
gen-xu added a commit to gen-xu/opentelemetry-python that referenced this issue May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant