-
Notifications
You must be signed in to change notification settings - Fork 34
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
Request failure logging in middleware cannot be hit #19
Comments
In case it is not an exception the request will be logged there django-structlog/django_structlog/middlewares/request.py Lines 60 to 62 in c91eb00
However it is logged as an info which may not be adequate. We may want to log info for 2XX/3XX, warning for 4XX, and error for 5XX, what do you think? You can create a separate Issue for django-structlog not working when using django commands. |
@jrobichaud I think there may be a misunderstanding here, I'm not clear exactly what you mean by your response, but currently I don't believe it's possible to hit this condition: django-structlog/django_structlog/middlewares/request.py Lines 48 to 58 in c91eb00
Django catches all exceptions from This is an issue because the Here's an example of what we've used instead: https://gist.github.com/danpalmer/16cdd5aa2941fa9706a44bb28c54729b |
I will investigate this, thank you. |
Ok, with Your implementation works with both cases. Do you mind if I use the gist you provided to implement it correctly? |
@danpalmer can you take a quick look at #20 and tell me if it makes sense to you? Thank you again for your help, this is really appreciated. |
From the Django documentation...
https://docs.djangoproject.com/en/2.2/topics/http/middleware/#exception-handling
Currently the middleware in this package depends on thrown exceptions to log request failures, but this never happens.
We can reproduce this under
runserver
andgunicorn
. It should be noted that withdjango-extensions
and therunserver_plus
command, this doesn't apply and the middleware does work.The most obvious solution I can think of is to check the status code for an error code and mark request failure from that. This doesn't capture an exception though, and there may be a better way of doing this that will capture the exception.
The text was updated successfully, but these errors were encountered: