-
Notifications
You must be signed in to change notification settings - Fork 851
django: handle cancelled requests more cleanly #4102
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
base: main
Are you sure you want to change the base?
django: handle cancelled requests more cleanly #4102
Conversation
| max(duration_s, 0), | ||
| duration_attrs_new, | ||
| ) | ||
| self._active_request_counter.add(-1, active_requests_count_attrs) |
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.
counter decrement, activation.exit, and detach(token)
are now handled in call finally block to ensure cleanup
even when requests are cancelled
| if propagator: | ||
| propagator.inject(response) | ||
|
|
||
| # record any exceptions raised while processing the request |
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.
exception handling moved to call finally block
| activation = request.META.pop(self._environ_activation_key, None) | ||
| activation = request.META.get(self._environ_activation_key) | ||
| span = request.META.pop(self._environ_span_key, None) | ||
| active_requests_count_attrs = request.META.pop( |
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.
active_requests_count_attrs is popped in call finally block
| if token: | ||
| request.META[self._environ_token] = token | ||
|
|
||
| if _DjangoMiddleware._otel_request_hook: |
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.
request_hook is called in call after activation.enter()
| span.set_attribute(key, value) | ||
|
|
||
| activation = use_span(span, end_on_exit=True) | ||
| activation.__enter__() # pylint: disable=E1101 |
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.
activation.enter() is called in call to ensure
proper cleanup via finally block even on request cancellation
|
Lint 0 / instrumentation-google-genai (pull_request) This one broke because of this |
|
Please drop the google genai changes |
|
@xrmx done! |
|
I would appreciate someone testing it on their setup if possible. Seems to be fine on mine |
Description
This is a duplicate of: #3848 but without the django version removal.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Only the newly created unit test for now. Can test more later
Does This PR Require a Core Repo Change?
Checklist: