Skip to content

Commit d1594cd

Browse files
committed
Handle hooks in instrument_client
1 parent c429d65 commit d1594cd

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
@@ -192,6 +192,7 @@ async def async_response_hook(span, request, response):
192192
"""
193193
import logging
194194
import typing
195+
from asyncio import iscoroutinefunction
195196
from types import TracebackType
196197

197198
import httpx
@@ -926,6 +927,20 @@ def instrument_client(
926927
)
927928
return
928929

930+
if iscoroutinefunction(request_hook):
931+
self._async_request_hook = request_hook
932+
self._request_hook = None
933+
else:
934+
self._request_hook = request_hook
935+
self._async_request_hook = None
936+
937+
if iscoroutinefunction(response_hook):
938+
self._async_response_hook = response_hook
939+
self._response_hook = None
940+
else:
941+
self._response_hook = response_hook
942+
self._async_response_hook = None
943+
929944
if hasattr(client._transport, "handle_request"):
930945
wrap_function_wrapper(
931946
client._transport,

0 commit comments

Comments
 (0)