I've run into an issue with an 'extra' exception from my django app being sent to Sentry through the sentry_sdk, after configuring structlog to use the SentryProcessor from this lib (v2.0.3)
When raising an unhandled exception, or when making a call to structlog.logger.exception:
I can get the original exception data appearing in sentry, but there is also a secondary exception (only in sentry, and not in my local logs):
ValueError: EXCEPTION is not a valid log level
Here's the traceback - note that I'm using a celery task so I can easily trigger the exception, but this happens with exceptions outside of celery, too:
AttributeError: module 'logging' has no attribute 'EXCEPTION'
File "__init__.py", line 191, in _get_level_value
return getattr(logging, level_name)
ValueError: EXCEPTION is not a valid log level
File "myproject/celery.py", line 50, in debug_task
logger.exception("Test Exception")
File "structlog/stdlib.py", line 224, in exception
return self._proxy_to_logger("exception", event, *args, **kw)
File "structlog/stdlib.py", line 254, in _proxy_to_logger
return super()._proxy_to_logger(method_name, event=event, **event_kw)
File "structlog/_base.py", line 216, in _proxy_to_logger
args, kw = self._process_event(method_name, event, event_kw)
File "structlog/_base.py", line 167, in _process_event
event_dict = proc(self._logger, method_name, event_dict)
File "__init__.py", line 208, in __call__
level = self._get_level_value(event_dict["level"].upper())
File "__init__.py", line 199, in _get_level_value
raise ValueError(f"{level_name} is not a valid log level") from e
I believe this is an issue with how structlog-sentry handles logs at level exception.
The exception level/method name is hard-set in structlog after a call to .exception() ("structlog/stdlib.py", line 224) - this is in contrast to the standard logging library, which uses .exception() as convenience method - but I think that's inline with structlog's objective, as there they treat exceptions explicitly.
Standard logging doesn't actually have an 'exception' level, but that's the only thing that's being searched by structlog-sentry here - thus the error.
The expected behaviour is that structlog-sentry should be able to handle logs raised from both a structlog logger and the standard logger, and allow for exception info, without any additional config - I don't believe I need to define a custom log level for what is a widely available logging function.
I might be doing something wrong before the errors arrive at structlog, but the structlog config we have is quite standard, according to the django/structlog implementation guidelines:
My caveat is that I didn't personally set up this logging config, and so I might be fundamentally misunderstanding something about the interactions between these libraries - sorry if that's the case !
I've run into an issue with an 'extra' exception from my django app being sent to Sentry through the sentry_sdk, after configuring structlog to use the SentryProcessor from this lib (v2.0.3)
When raising an unhandled exception, or when making a call to structlog.logger.exception:
I can get the original exception data appearing in sentry, but there is also a secondary exception (only in sentry, and not in my local logs):
Here's the traceback - note that I'm using a celery task so I can easily trigger the exception, but this happens with exceptions outside of celery, too:
I believe this is an issue with how structlog-sentry handles logs at level exception. The
exception
level/method name is hard-set in structlog after a call to.exception()
("structlog/stdlib.py", line 224) - this is in contrast to the standard logging library, which uses.exception()
as convenience method - but I think that's inline with structlog's objective, as there they treat exceptions explicitly. Standard logging doesn't actually have an 'exception' level, but that's the only thing that's being searched by structlog-sentry here - thus the error.The expected behaviour is that structlog-sentry should be able to handle logs raised from both a structlog logger and the standard logger, and allow for exception info, without any additional config - I don't believe I need to define a custom log level for what is a widely available logging function.
I might be doing something wrong before the errors arrive at structlog, but the structlog config we have is quite standard, according to the django/structlog implementation guidelines:
My caveat is that I didn't personally set up this logging config, and so I might be fundamentally misunderstanding something about the interactions between these libraries - sorry if that's the case !