Skip to content

Conversation

@zmievsa
Copy link
Contributor

@zmievsa zmievsa commented Jan 14, 2026

Description

This is a duplicate of: #3848 but without the django version removal.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

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?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@zmievsa zmievsa requested a review from a team as a code owner January 14, 2026 21:30
max(duration_s, 0),
duration_attrs_new,
)
self._active_request_counter.add(-1, active_requests_count_attrs)
Copy link
Contributor Author

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
Copy link
Contributor Author

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(
Copy link
Contributor Author

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:
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@zmievsa
Copy link
Contributor Author

zmievsa commented Jan 14, 2026

Lint 0 / instrumentation-google-genai (pull_request)

This one broke because of this

@zmievsa
Copy link
Contributor Author

zmievsa commented Jan 14, 2026

@xrmx Pinging you here since you were involved in the original PR.
@rtpg Pinging you since you are the author of the original fix. Thank you very much for it btw, I tried to keep it as close to your version as possible

@xrmx
Copy link
Contributor

xrmx commented Jan 15, 2026

Please drop the google genai changes

@zmievsa
Copy link
Contributor Author

zmievsa commented Jan 15, 2026

@xrmx done!

@zmievsa
Copy link
Contributor Author

zmievsa commented Jan 15, 2026

I would appreciate someone testing it on their setup if possible. Seems to be fine on mine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants