flask: Clear context at the end of the request in non-streaming scenarios.#4341
flask: Clear context at the end of the request in non-streaming scenarios.#4341123liuziming wants to merge 10 commits intoopen-telemetry:mainfrom
Conversation
…est 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>
…e errors Co-authored-by: 123liuziming <32130965+123liuziming@users.noreply.github.com>
Clean up environ keys in _teardown_request to prevent duplicate execution
Change-Id: Ie89cac244ade8d04768503112db8673f91d81756 Co-developed-by: Cursor <noreply@cursor.com>
Remove redundant environment variable cleanup in finally block.
|
pypy3-test-instrumentation-tornado: exit 1 (5.66 seconds) /home/runner/work/opentelemetry-python-contrib/opentelemetry-python-contrib> pytest /home/runner/work/opentelemetry-python-contrib/opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-tornado/tests -ra pid=2651 |
Agreed, that tornado test does occasionally fail with unrelated changes. Please could you describe a bit more about the setup that's giving the token error? I know Dify uses Flask but not sure about its streaming vs non-streaming modes. Please also do |
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
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
Using the latest Flask instrumentor to enhance dify-api 1.11.4 causes an error when calling workflows.

Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.