Skip to content

Add HTTPX hook access to request and response objects#4564

Open
Harshal96 wants to merge 3 commits into
open-telemetry:mainfrom
Harshal96:feat/httpx-hook-body-access
Open

Add HTTPX hook access to request and response objects#4564
Harshal96 wants to merge 3 commits into
open-telemetry:mainfrom
Harshal96:feat/httpx-hook-body-access

Conversation

@Harshal96
Copy link
Copy Markdown

Description

Add access to the original httpx.Request and httpx.Response objects from HTTPX request and response hook info while preserving the existing tuple fields. This lets hooks read request content and call response.response.read() or response.response.aread() so HTTPX caches response bodies for later application use.

Fixes #2556

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • uv run --no-sync --with tox tox -e py312-test-instrumentation-httpx-1-wrapt2
  • uv run --no-sync --with tox tox -e py312-test-instrumentation-httpx-0-wrapt2
  • uv run --no-sync --with tox tox -e lint-instrumentation-httpx
  • uv run --no-sync --with pre-commit pre-commit run ruff --files instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py instrumentation/opentelemetry-instrumentation-httpx/README.rst
  • uv run --no-sync --with pre-commit pre-commit run ruff-format --files instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py
  • uv run --no-sync --with pre-commit pre-commit run rstcheck --files instrumentation/opentelemetry-instrumentation-httpx/README.rst

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
  • Unit tests have been added
  • Documentation has been updated

@Harshal96 Harshal96 marked this pull request as ready for review May 10, 2026 19:47
@Harshal96 Harshal96 requested a review from a team as a code owner May 10, 2026 19:47
@Harshal96 Harshal96 marked this pull request as draft May 10, 2026 19:49
@emdneto
Copy link
Copy Markdown
Member

emdneto commented May 12, 2026

Thanks for the PR!

Just a heads-up: we no longer update CHANGELOG.md directly. The changelog is now generated from changelog fragments using Towncrier.

Please add the appropriate changelog fragment for this change instead of editing CHANGELOG.md manually. You can find the instructions and expected format in CONTRIBUTING.md.

Assisted-by: OpenAI Codex
@Harshal96 Harshal96 marked this pull request as ready for review May 14, 2026 02:10
@Harshal96
Copy link
Copy Markdown
Author

Done!

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.

HTTPX instrumentation - document how to log request payload and response on response_hook

2 participants