Skip to content

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

Open
123liuziming wants to merge 10 commits intoopen-telemetry:mainfrom
123liuziming:main
Open

flask: Clear context at the end of the request in non-streaming scenarios.#4341
123liuziming wants to merge 10 commits intoopen-telemetry:mainfrom
123liuziming:main

Conversation

@123liuziming
Copy link

@123liuziming 123liuziming commented Mar 18, 2026

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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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.
image

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

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

Copilot AI and others added 4 commits March 18, 2026 02:36
…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: Iea7711d86dcd6f4da7a3af92cb68db2fe3db345f
Co-developed-by: Cursor <noreply@cursor.com>
@123liuziming 123liuziming requested a review from a team as a code owner March 18, 2026 03:23
Change-Id: Ie89cac244ade8d04768503112db8673f91d81756
Co-developed-by: Cursor <noreply@cursor.com>
@123liuziming
Copy link
Author

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
pypy3-test-instrumentation-tornado: FAIL code 1 (11.88=setup[6.22]+cmd[5.66] seconds)
evaluation failed :( (12.87 seconds)
Error: Process completed with exit code 1. I am sure that this test failure has nothing to do with this PR, may be we can retrigger the CI later.

@xrmx xrmx moved this to Ready for review in Python PR digest Mar 18, 2026
@tammy-baylis-swi
Copy link
Contributor

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
pypy3-test-instrumentation-tornado: FAIL code 1 (11.88=setup[6.22]+cmd[5.66] seconds)
evaluation failed :( (12.87 seconds)
Error: Process completed with exit code 1. I am sure that this test failure has nothing to do with this PR, may be we can retrigger the CI later.

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 tox -e precommit to fix some formatting.

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

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

4 participants