open-telemetry / open-telemetry/opentelemetry-python-contrib
HTTPX instrumentation - document how to log request payload and response on response_hook
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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