SIGN IN SIGN UP

flask: Clear context at the end of the request in non-streaming scenarios. (#4341)

* Initial plan

* Clean up _ENVIRON_ACTIVATION_KEY and _ENVIRON_TOKEN in _teardown_request to prevent duplicate execution

Add a finally block in _teardown_request to pop _ENVIRON_ACTIVATION_KEY and
_ENVIRON_TOKEN from flask.request.environ after teardown completes. This
prevents issues when _teardown_request is called multiple times, as the
second call will see activation as None and return early.

Co-authored-by: 123liuziming <32130965+123liuziming@users.noreply.github.com>

* Improve test to explicitly verify duplicate teardown calls don't cause errors

Co-authored-by: 123liuziming <32130965+123liuziming@users.noreply.github.com>

* fix lint

Change-Id: Iea7711d86dcd6f4da7a3af92cb68db2fe3db345f
Co-developed-by: Cursor <noreply@cursor.com>

* polish CHANGELOG

Change-Id: Ie89cac244ade8d04768503112db8673f91d81756
Co-developed-by: Cursor <noreply@cursor.com>

* Refactor request teardown to avoid duplicate cleanup

Remove redundant environment variable cleanup in finally block.

* Update test_flask_compatibility.py

* Uncomment FlaskInstrumentor import in test file

* Initial plan

* Fix ruff format errors in docker test files

Co-authored-by: 123liuziming <32130965+123liuziming@users.noreply.github.com>
Agent-Logs-Url: https://github.com/123liuziming/opentelemetry-python-contrib/sessions/9165702c-5648-474d-9291-dfa57008b0b6

* Initial plan

* Revert docker-test formatting changes that undo merged #4339 cleanup

Agent-Logs-Url: https://github.com/123liuziming/opentelemetry-python-contrib/sessions/25f73137-1606-4050-b879-ffc01d7ab803

Co-authored-by: 123liuziming <32130965+123liuziming@users.noreply.github.com>

* Update CHANGELOG.md

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
Co-authored-by: Mike Goldsmith <goldsmith.mike@gmail.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
L
Liu Ziming committed
9b5fdd0c46962a4186876658f56cf904192a5047
Parent: 0158026
Committed by GitHub <noreply@github.com> on 4/20/2026, 1:32:42 PM