Skip to content

Commit be44afa

Browse files
committed
opentelemetry-instrumentation-httpx: make instrument_client a staticmethod again
1 parent a6e4a0c commit be44afa

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,8 @@ async def _handle_async_request_wrapper( # pylint: disable=too-many-locals
938938

939939
return response
940940

941+
@staticmethod
941942
def instrument_client(
942-
self,
943943
client: typing.Union[httpx.Client, httpx.AsyncClient],
944944
tracer_provider: TracerProvider = None,
945945
request_hook: typing.Union[
@@ -996,7 +996,7 @@ def instrument_client(
996996
client._transport,
997997
"handle_request",
998998
partial(
999-
self._handle_request_wrapper,
999+
HTTPXClientInstrumentor._handle_request_wrapper,
10001000
tracer=tracer,
10011001
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
10021002
request_hook=request_hook,
@@ -1008,7 +1008,7 @@ def instrument_client(
10081008
transport,
10091009
"handle_request",
10101010
partial(
1011-
self._handle_request_wrapper,
1011+
HTTPXClientInstrumentor._handle_request_wrapper,
10121012
tracer=tracer,
10131013
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
10141014
request_hook=request_hook,
@@ -1021,7 +1021,7 @@ def instrument_client(
10211021
client._transport,
10221022
"handle_async_request",
10231023
partial(
1024-
self._handle_async_request_wrapper,
1024+
HTTPXClientInstrumentor._handle_async_request_wrapper,
10251025
tracer=tracer,
10261026
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
10271027
async_request_hook=async_request_hook,
@@ -1033,7 +1033,7 @@ def instrument_client(
10331033
transport,
10341034
"handle_async_request",
10351035
partial(
1036-
self._handle_async_request_wrapper,
1036+
HTTPXClientInstrumentor._handle_async_request_wrapper,
10371037
tracer=tracer,
10381038
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
10391039
async_request_hook=async_request_hook,

instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,13 @@ def test_instrument_client(self):
917917
self.assertEqual(result.text, "Hello!")
918918
self.assert_span(num_spans=1)
919919

920+
def test_instrument_client_a_static_method(self):
921+
client = self.create_client()
922+
HTTPXClientInstrumentor.instrument_client(client)
923+
result = self.perform_request(self.URL, client=client)
924+
self.assertEqual(result.text, "Hello!")
925+
self.assert_span(num_spans=1)
926+
920927
def test_instrumentation_without_client(self):
921928
HTTPXClientInstrumentor().instrument()
922929
results = [

0 commit comments

Comments
 (0)