Skip to content

LoggingHandler can be initialized in a bad state, has type checking problems #4582

Open
@DylanRussell

Description

@DylanRussell

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions