Skip to content

Commit cc7b97e

Browse files
committed
Handle hooks in instrument_client
1 parent 06bc9b5 commit cc7b97e

File tree

1 file changed

+15
-0
lines changed
  • instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx

1 file changed

+15
-0
lines changed

instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ async def async_response_hook(span, request, response):
193193

194194
import logging
195195
import typing
196+
from asyncio import iscoroutinefunction
196197
from types import TracebackType
197198

198199
import httpx
@@ -929,6 +930,20 @@ def instrument_client(
929930
)
930931
return
931932

933+
if iscoroutinefunction(request_hook):
934+
self._async_request_hook = request_hook
935+
self._request_hook = None
936+
else:
937+
self._request_hook = request_hook
938+
self._async_request_hook = None
939+
940+
if iscoroutinefunction(response_hook):
941+
self._async_response_hook = response_hook
942+
self._response_hook = None
943+
else:
944+
self._response_hook = response_hook
945+
self._async_response_hook = None
946+
932947
if hasattr(client._transport, "handle_request"):
933948
wrap_function_wrapper(
934949
client._transport,

0 commit comments

Comments
 (0)