Skip to content
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ dev = [
"chardet==6.0.0.post1",
"coverage[toml]==7.10.6",
"cryptography==46.0.7",
"inline-snapshot>=0.34.2",
"logfire>=4.37.0",
"pytest>=9.0.3",
"pytest-codspeed>=4.1.1",
"pytest-httpbin==2.0.0",
Expand Down
9 changes: 7 additions & 2 deletions src/httpx2/httpx2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
request_context,
)
from ._models import Cookies, Headers, Request, Response
from ._opentelemetry import trace_request
from ._sse import EventSource
from ._status_codes import codes
from ._transports.base import AsyncBaseTransport, BaseTransport
Expand Down Expand Up @@ -1015,7 +1016,9 @@ def _send_single_request(self, request: Request) -> Response:
raise RuntimeError("Attempted to send an async request with a sync Client instance.")

with request_context(request=request):
response = transport.handle_request(request)
with trace_request(request) as trace:
response = transport.handle_request(request)
trace.set_response(response)

assert isinstance(response.stream, SyncByteStream)

Expand Down Expand Up @@ -1761,7 +1764,9 @@ async def _send_single_request(self, request: Request) -> Response:
raise RuntimeError("Attempted to send a sync request with an AsyncClient instance.")

with request_context(request=request):
response = await transport.handle_async_request(request)
with trace_request(request) as trace:
response = await transport.handle_async_request(request)
trace.set_response(response)

assert isinstance(response.stream, AsyncByteStream)
response.request = request
Expand Down
Loading
Loading