open-telemetry / open-telemetry/opentelemetry-python-contrib

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

Open
#2,556 10 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request good first issue
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Is your feature request related to a problem?
After reading the httpx instrumentation docs it is clear I need a response_hook and how to use it. But it has no example how to really use this with the span, request, response attributes to log the payload from request and response.

After digging into __init__() I see both ResponseInfo and RequestInfo have a stream property that could potentially be the solution, but each of them are a different type:

class RequestInfo(typing.NamedTuple):
....
typing.Optional[
        typing.Union[httpx.SyncByteStream, httpx.AsyncByteStream]
    ]

class ResponseInfo(typing.NamedTuple):
...
    stream: typing.Iterable[bytes]

In those cases it is not very clear an easy way to log the information from the payload.

Describe the solution you'd like
A simple example of response_hook in the docs with logging of payload of request and response.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked HTTPX instrumentation documentation and inspect init(), including the RequestInfo and ResponseInfo stream properties. Document a response_hook example that shows how to access the span, request, and response and log request and response payloads, while clarifying the differing stream types.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.