Skip to content

Commit 19898df

Browse files
committed
Can be a classmethod
1 parent acf5fee commit 19898df

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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

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

939939
return response
940940

941-
@staticmethod
941+
@classmethod
942942
def instrument_client(
943+
cls,
943944
client: typing.Union[httpx.Client, httpx.AsyncClient],
944945
tracer_provider: TracerProvider = None,
945946
request_hook: typing.Union[
@@ -996,7 +997,7 @@ def instrument_client(
996997
client._transport,
997998
"handle_request",
998999
partial(
999-
HTTPXClientInstrumentor._handle_request_wrapper,
1000+
cls._handle_request_wrapper,
10001001
tracer=tracer,
10011002
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
10021003
request_hook=request_hook,
@@ -1008,7 +1009,7 @@ def instrument_client(
10081009
transport,
10091010
"handle_request",
10101011
partial(
1011-
HTTPXClientInstrumentor._handle_request_wrapper,
1012+
cls._handle_request_wrapper,
10121013
tracer=tracer,
10131014
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
10141015
request_hook=request_hook,
@@ -1021,7 +1022,7 @@ def instrument_client(
10211022
client._transport,
10221023
"handle_async_request",
10231024
partial(
1024-
HTTPXClientInstrumentor._handle_async_request_wrapper,
1025+
cls._handle_async_request_wrapper,
10251026
tracer=tracer,
10261027
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
10271028
async_request_hook=async_request_hook,
@@ -1033,7 +1034,7 @@ def instrument_client(
10331034
transport,
10341035
"handle_async_request",
10351036
partial(
1036-
HTTPXClientInstrumentor._handle_async_request_wrapper,
1037+
cls._handle_async_request_wrapper,
10371038
tracer=tracer,
10381039
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
10391040
async_request_hook=async_request_hook,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,14 +910,14 @@ def test_suppress_instrumentation_new_client(self):
910910

911911
self.assert_span(num_spans=0)
912912

913-
def test_instrument_client(self):
913+
def test_instrument_client_called_on_the_instance(self):
914914
client = self.create_client()
915915
HTTPXClientInstrumentor().instrument_client(client)
916916
result = self.perform_request(self.URL, client=client)
917917
self.assertEqual(result.text, "Hello!")
918918
self.assert_span(num_spans=1)
919919

920-
def test_instrument_client_a_static_method(self):
920+
def test_instrument_client_called_on_the_class(self):
921921
client = self.create_client()
922922
HTTPXClientInstrumentor.instrument_client(client)
923923
result = self.perform_request(self.URL, client=client)

0 commit comments

Comments
 (0)