open-telemetry / open-telemetry/opentelemetry-python-contrib
opentelemetry-instrumentation-httpx - If awaiting an async request, span end is confusing.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
Versions:
Python 3.11
trio==0.22.2
httpx==0.25.2
opentelemetry-instrumentation-httpx==0.41b0
Set up a standard httpx.AsyncClient (I'm using trio for my async framework) and HTTPXClientInstrumentor.
Call like:
resp = await client.post(
"some_url"
)
Crossreferencing spans emitted with httpx trace extension output, looks like for the span emitted, the end is aligned with "receive_response_body.started" when it would be better to align at "receive_response_body.complete".
I understand this is a little subtle because some users of the async client might want to start doing stuff after the response body has started being received but before the response body has finished being received, and in that case the current spot for span end is probably reasonable...
See this example on Google Cloud Trace Explorer
- top span: a span wrapping
await client.post() - middle span: the client-instrumented span
- bottom span: span emitted by the other service that is called
+1.11s is when "receive_response_body.started" event, and also when the client-emitted span ends.
+1.264s is when "receive_response_body.complete" event. This is when I would prefer the client-emitted span to end (so it doesn't look like that time is being spent in my function calling client.post().)
I would also be happy with the client emitting 2 spans, an inner one from "send_request_body.complete" (or "receive_response_headers.started") -> "receive_response_headers.complete" which is timed from when you've finished sending the request until the first response packet, and an outer one from "send_request_headers.started" -> "response_closed.complete", which is the E2E client latency from when you start sending the request until you get back the entire 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 at HTTPXClientInstrumentor and reproduce the async client call with the listed Python, Trio, and HTTPX versions while comparing HTTPX trace-extension events. Check when the client-instrumented span ends relative to receive_response_body.started and receive_response_body.complete. Done means the span timing reflects the agreed response lifecycle, with tests or documented behavior covering the chosen timing model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100