Add baggage propagation tests for Flask and WSGI instrumentations - #4869
Open
jojinkb wants to merge 1 commit into
Open
Add baggage propagation tests for Flask and WSGI instrumentations#4869jojinkb wants to merge 1 commit into
jojinkb wants to merge 1 commit into
Conversation
|
|
The Flask instrumentation and the WSGI OpenTelemetryMiddleware extract W3C baggage from incoming request headers (via the default composite propagator used by _start_internal_or_server_span) and make it active for the duration of the request, but this behavior had no test coverage. Add tests asserting that baggage entries from the incoming `baggage` header (including percent-encoded values) are available via baggage.get_all() inside the wrapped WSGI app / Flask handler, and that the extracted context is detached once the request ends. Tests-only change, no functional changes. Fixes open-telemetry#268 Signed-off-by: Jojin <jojin.kb@gmail.com>
jojinkb
force-pushed
the
test-baggage-propagation
branch
from
July 25, 2026 07:13
1cbcdbb to
56e15b2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Flask instrumentation and the WSGI
OpenTelemetryMiddlewareextract W3C baggage fromincoming request headers (through the default composite propagator used by
_start_internal_or_server_span) and make it active for the duration of the request. Thishas worked for a long time, but there was no unit test covering it — neither package
referenced baggage anywhere in its tests.
This PR adds the tests requested in the issue:
test_wsgi_middleware.py):test_baggage_extracted_and_active_in_wrapped_app: baggage entries from the incomingbaggageheader (including a percent-encoded value) are available viabaggage.get_all()inside the wrapped WSGI application.test_baggage_detached_after_response_is_consumed: the extracted context is detachedafter the response iterable is consumed, so baggage does not leak past the request.
base_test.py,test_programmatic.py):test_baggage_extracted_and_active_in_handler: baggage from the incoming requestheader is available via
baggage.get_all()inside the route handler (new/baggagetest route), and the context is detached once the request has ended.
Tests-only change, no functional changes — no changelog fragment (Skip Changelog).
The
# pylint: disable=too-many-public-methodsonTestWsgiApplicationwas neededbecause the class was already at the 20-method limit; the same disable is already used on
TestWsgiAttributesin the same file.Fixes #268
Type of change
How Has This Been Tested?
tox -e py312-test-instrumentation-wsgiequivalent: full WSGI suite — 54 passed(52 baseline + 2 new).
tox -e py312-test-instrumentation-flask-3equivalent: full Flask suite — 61 passed,1 skipped (60 baseline + 1 new); also re-run against the oldest tested versions
(
Flask==2.1.3,Werkzeug==2.3.8, the flask-0 pins) — 61 passed, 1 skipped.OTEL_PROPAGATORS=tracecontext(baggage propagator removed fromthe composite), both new extraction tests fail — confirming they guard the behavior.
ruff check/ruff format --check(v0.14.1) clean on changed files;pylint --rcfile .pylintrc(v4.0.5) 10.00/10 on both packages.Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.
Skip Changeloglabel)