LoggingHandler can be initialized in a bad state, has type checking problems
Describe your environment
No response
What happened?
The SDK LoggingHandler can be initialized in a bad state by doing just handler = LoggingHandler().
When i do this:
from opentelemetry.sdk._logs import LoggingHandler
import logging
handler = LoggingHandler()
logging.getLogger().addHandler(handler)
logger1 = logging.getLogger("myapp.area1")
logger1.error("error !")
We end up in an endless recursive loop here and the program crashes.
It seems LoggingHandler should require that a SDK LoggerProvider is passed in, and not an API LoggerProvider. ?
Right now if nothing is passed to the LoggingHandler (like in my code above), it can default to the ProxyLoggerProvider which is an API LoggerProvider and it causes that endless recursive call..
Also LoggingHandler expects it’s provider to provide a resource here, which the API LoggerProvider does not have..
Aaron also mentioned that he ran into this and can probably provide more context on what exactly the issues are here and how to fix things
Steps to Reproduce
See above..
Expected Result
See above.
Actual Result
See above..
Additional context
No response
Would you like to implement a fix?
Yes
It seems
LoggingHandlershould require that a SDKLoggerProvideris passed in, and not an APILoggerProvider. ?Right now if nothing is passed to the
LoggingHandler(like in my code above), it can default to theProxyLoggerProviderwhich is an API LoggerProvider and it causes that endless recursive call..
I think it does assume this right now but it should not. Also see https://github.com/open-telemetry/opentelemetry-python/issues/4330
Also
LoggingHandlerexpects it’s provider to provide a resource here, which the API LoggerProvider does not have..
I think the underlying problem is that the LogRecord API should not have a resource. (the exporting format that is part of LogData is something different)
Ok so you're saying LoggingHandler should accept either a SDK / API LoggerProvider and then return either a SDK / API LogRecord ?
Yeah I see resource is the one field being populated that's in the SDK LogRecord and not in the API LogRecord