-
Notifications
You must be signed in to change notification settings - Fork 651
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
Django: Record status and http.status_code on exception #1257
Django: Record status and http.status_code on exception #1257
Conversation
722fbc4
to
405b7bb
Compare
@@ -184,13 +188,27 @@ def process_exception(self, request, exception): | |||
return | |||
|
|||
if self._environ_activation_key in request.META.keys(): | |||
status_code = 500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, the status_code always 500?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost! There are some special cases where a user can raise an exception to return a specific HTTP error. I've re-implemented it in a much better way that doesn't assume status code.
1a170d7
to
b922711
Compare
b922711
to
95a5b82
Compare
.../opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py
Show resolved
Hide resolved
Just curious, what are your thoughts on the behavior of record_exception? Should an event be added to the span for exceptions in this case? |
if self._excluded_urls.url_disabled(request.build_absolute_uri("?")): | ||
return | ||
|
||
if self._environ_activation_key in request.META.keys(): | ||
request.META[self._environ_activation_key].__exit__( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't this behavior already implemented here? How does moving the logic to process_response
change anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was but because we popped the activation key, process_response did not do anything. We recorded the exception but ignored the response meaning response code or metrics were not recorded for example. We could either duplicate the code here, take it out in a function and call from both places or just make the exception available to process_response so it can handle all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right makes sense. Doesn't add_response_attributes
already handle setting the status and http.status_code
though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it does but without this change it was never executed in case of an exception so status_code (and other response attrs) were never set in case of an exception.
Yes, IMO this should definitely record an event to log the exception. |
Yeah, i'll bring it up during the SIG meeting. Might be more complicated than it seems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Description
Update Django instrumentation to record http.status_code and span status on exception.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: