Skip to content

Commit

Permalink
Can be a classmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
xrmx committed Nov 14, 2024
1 parent b833df3 commit 2643507
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,9 @@ async def _handle_async_request_wrapper( # pylint: disable=too-many-locals

return response

@staticmethod
@classmethod
def instrument_client(
cls,
client: typing.Union[httpx.Client, httpx.AsyncClient],
tracer_provider: TracerProvider = None,
request_hook: typing.Union[
Expand Down Expand Up @@ -996,7 +997,7 @@ def instrument_client(
client._transport,
"handle_request",
partial(
HTTPXClientInstrumentor._handle_request_wrapper,
cls._handle_request_wrapper,
tracer=tracer,
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
request_hook=request_hook,
Expand All @@ -1008,7 +1009,7 @@ def instrument_client(
transport,
"handle_request",
partial(
HTTPXClientInstrumentor._handle_request_wrapper,
cls._handle_request_wrapper,
tracer=tracer,
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
request_hook=request_hook,
Expand All @@ -1021,7 +1022,7 @@ def instrument_client(
client._transport,
"handle_async_request",
partial(
HTTPXClientInstrumentor._handle_async_request_wrapper,
cls._handle_async_request_wrapper,
tracer=tracer,
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
async_request_hook=async_request_hook,
Expand All @@ -1033,7 +1034,7 @@ def instrument_client(
transport,
"handle_async_request",
partial(
HTTPXClientInstrumentor._handle_async_request_wrapper,
cls._handle_async_request_wrapper,
tracer=tracer,
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
async_request_hook=async_request_hook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,14 +910,14 @@ def test_suppress_instrumentation_new_client(self):

self.assert_span(num_spans=0)

def test_instrument_client(self):
def test_instrument_client_called_on_the_instance(self):
client = self.create_client()
HTTPXClientInstrumentor().instrument_client(client)
result = self.perform_request(self.URL, client=client)
self.assertEqual(result.text, "Hello!")
self.assert_span(num_spans=1)

def test_instrument_client_a_static_method(self):
def test_instrument_client_called_on_the_class(self):
client = self.create_client()
HTTPXClientInstrumentor.instrument_client(client)
result = self.perform_request(self.URL, client=client)
Expand Down

0 comments on commit 2643507

Please sign in to comment.