Skip to content

opentelemetry-instrumentation-wsgi: capture Content-Type and Content-Length request headers - #5321

Open
ghdtjdwn wants to merge 2 commits into
open-telemetry:mainfrom
ghdtjdwn:wsgi/capture-content-headers
Open

ghdtjdwn wants to merge 2 commits into
open-telemetry:mainfrom
ghdtjdwn:wsgi/capture-content-headers

Conversation

@ghdtjdwn

Copy link
Copy Markdown
Contributor

Description

collect_custom_request_headers_attributes only looks at the HTTP_* keys of the environ. PEP 3333 passes Content-Type and Content-Length as CONTENT_TYPE and CONTENT_LENGTH, so they are never captured, although the module docs use content-type as the example for OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST. The ASGI instrumentation does capture them.

Add the two keys to the headers passed to the sanitizer when they are not empty. If a server sets HTTP_CONTENT_TYPE as well, the unprefixed value wins, which is what werkzeug does. Flask, Falcon, Pyramid and Django (WSGI) collect their headers through this function, so they get the fix too.

One thing to be aware of: some servers fill in CONTENT_TYPE when the client did not send one (wsgiref uses text/plain), and that value is captured as well.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

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

  • I am a human and not a bot
  • I have run tox -e precommit
  • I have run tox -e typecheck
  • I have run the relevant tests and linting tox environments
  • This requires the following PR in core: none

…Length request headers

PEP 3333 passes these two headers as CONTENT_TYPE and CONTENT_LENGTH,
without the HTTP_ prefix, so they were never matched by
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST.
@ghdtjdwn
ghdtjdwn requested a review from a team as a code owner November 11, 2026 01:31
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-11-11 14:50 UTC

Respond to 2 review items (e.g. link a commit, explain why not, ask a follow-up):

  • Top-level threads: 1, 2
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the WSGI content-header capture fix.

No open issues 🎉

What changed in this PR

Fixes WSGI request-header capture to include Content-Type and Content-Length from their standard, unprefixed environment keys. Frameworks using the shared WSGI helper also benefit.

Changes:

  • Adds non-empty CONTENT_TYPE and CONTENT_LENGTH values to the existing sanitization pipeline, taking precedence over prefixed equivalents.
  • Adds regression coverage for capture, precedence, and empty-value handling.
  • Documents the fix in a changelog entry.
File Description
instrumentation/​opentelemetry-instrumentation-wsgi/​tests/​test_wsgi_middleware.py Tests content-header capture, precedence, and empty-length omission.
instrumentation/​opentelemetry-instrumentation-wsgi/​src/​opentelemetry/​instrumentation/​wsgi/​__init__.py Includes unprefixed content headers in request-header capture.
.changelog/​5321.fixed Records the WSGI header-capture fix.

Review effort: Balanced

@xrmx xrmx left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but for completeness we should probably also update WSGIGetter methods to handle these fields.

@xrmx xrmx moved this to Reviewed PRs that need fixes in Python PR digest Nov 11, 2026
@xrmx

xrmx commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Also would be nice to have docker tests added to the current django and flask ones for these fields and also something HTTP_ prefixed

This branch has not been deployed

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

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

3 participants