-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
Unexpected side-effect to calling LoggerFactory() #230
Comments
Why ist that a problem to you? The class that replaces it is a subclass of Logger and should be fully compatible. The behavior is also documented:
|
Hey @hynek, It causes class name change for downstream applications' logger that run within a host app, which can be perplexing for maintainers of downstream apps. In my scnenario, the application supports dynamic updates and based on some config value, we set the logger type to |
This is causing issues with opentelemetry:
|
I'm sorry, but I don't know what to make of this and I don't have the time to go spelunking through the whole OTEL code base. Could you provide an Short, Self Contained, Correct, Example? |
I have the same problem, structlog is causing an error in the logs. |
My current fix to get this working with OpenTelemetry (and Websockets): from opentelemetry.sdk._logs import LoggingHandler
from opentelemetry.util.types import Attributes
class AttrFilteredLoggingHandler(LoggingHandler):
DROP_ATTRIBUTES = ["_logger", "websocket"]
@staticmethod
def _get_attributes(record: logging.LogRecord) -> Attributes:
attributes = LoggingHandler._get_attributes(record)
for attr in AttrFilteredLoggingHandler.DROP_ATTRIBUTES:
if attr in attributes:
del attributes[attr]
return attributes OTEL's LoggingHandler doesn't call the I believe the only way to fix this is a PR to the Python OpenTelemetry SDK |
I'm using structlog package 19.2.0 but I've validated the behavior to be the same in version 19.1.0.
Instantiating LoggerFactory causes all subsequent calls to logging.getLogger to be of type
structlog.stdlib._FixedFindCallerLogger
.prints
A minimal example (May not be appropriate usage. Only to illustrate)
prints
This is a rather unexpected side-effect and causes client's code to return an unexpected type for logging.getLogger calls if structlog LoggerFactory is ever instantiated in a parent application. Is this something that can be addressed?
The text was updated successfully, but these errors were encountered: