Skip to content

Add baggage propagation tests for Flask and WSGI instrumentations - #4869

Open
jojinkb wants to merge 1 commit into
open-telemetry:mainfrom
jojinkb:test-baggage-propagation
Open

Add baggage propagation tests for Flask and WSGI instrumentations#4869
jojinkb wants to merge 1 commit into
open-telemetry:mainfrom
jojinkb:test-baggage-propagation

Conversation

@jojinkb

@jojinkb jojinkb commented Jul 25, 2026

Copy link
Copy Markdown

Description

The Flask instrumentation and the WSGI OpenTelemetryMiddleware extract W3C baggage from
incoming request headers (through the default composite propagator used by
_start_internal_or_server_span) and make it active for the duration of the request. This
has 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:

  • WSGI (test_wsgi_middleware.py):
    • test_baggage_extracted_and_active_in_wrapped_app: baggage entries from the incoming
      baggage header (including a percent-encoded value) are available via
      baggage.get_all() inside the wrapped WSGI application.
    • test_baggage_detached_after_response_is_consumed: the extracted context is detached
      after the response iterable is consumed, so baggage does not leak past the request.
  • Flask (base_test.py, test_programmatic.py):
    • test_baggage_extracted_and_active_in_handler: baggage from the incoming request
      header is available via baggage.get_all() inside the route handler (new /baggage
      test 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-methods on TestWsgiApplication was needed
because the class was already at the 20-method limit; the same disable is already used on
TestWsgiAttributes in the same file.

Fixes #268

Type of change

  • Tests only (no functional change)

How Has This Been Tested?

  • tox -e py312-test-instrumentation-wsgi equivalent: full WSGI suite — 54 passed
    (52 baseline + 2 new).
  • tox -e py312-test-instrumentation-flask-3 equivalent: 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.
  • Negative check: with OTEL_PROPAGATORS=tracecontext (baggage propagator removed from
    the composite), both new extraction tests fail — confirming they guard the behavior.
  • Lint: 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?

  • No.

Checklist:

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

  • Followed the style guidelines of this project
  • Changelogs have been updated (not needed — tests only, requesting Skip Changelog label)
  • Unit tests have been added
  • Documentation has been updated (not applicable)

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 25, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: jojinkb / name: Jojin (1cbcdbb)

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
jojinkb force-pushed the test-baggage-propagation branch from 1cbcdbb to 56e15b2 Compare July 25, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Baggage propagation tests are missing for Flask and WSGI

1 participant