Skip to content

Commit

Permalink
opentelemetry-instrumentation-httpx: make instrument_client a staticm…
Browse files Browse the repository at this point in the history
…ethod again
  • Loading branch information
xrmx committed Nov 14, 2024
1 parent e3ba54b commit 2756081
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,8 @@ async def _handle_async_request_wrapper( # pylint: disable=too-many-locals

return response

@staticmethod
def instrument_client(
self,
client: typing.Union[httpx.Client, httpx.AsyncClient],
tracer_provider: TracerProvider = None,
request_hook: typing.Union[
Expand Down Expand Up @@ -996,7 +996,7 @@ def instrument_client(
client._transport,
"handle_request",
partial(
self._handle_request_wrapper,
HTTPXClientInstrumentor._handle_request_wrapper,
tracer=tracer,
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
request_hook=request_hook,
Expand All @@ -1008,7 +1008,7 @@ def instrument_client(
transport,
"handle_request",
partial(
self._handle_request_wrapper,
HTTPXClientInstrumentor._handle_request_wrapper,
tracer=tracer,
sem_conv_opt_in_mode=sem_conv_opt_in_mode,
request_hook=request_hook,
Expand All @@ -1021,7 +1021,7 @@ def instrument_client(
client._transport,
"handle_async_request",
partial(
self._handle_async_request_wrapper,
HTTPXClientInstrumentor._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 +1033,7 @@ def instrument_client(
transport,
"handle_async_request",
partial(
self._handle_async_request_wrapper,
HTTPXClientInstrumentor._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 @@ -917,6 +917,13 @@ def test_instrument_client(self):
self.assertEqual(result.text, "Hello!")
self.assert_span(num_spans=1)

def test_instrument_client_a_static_method(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_instrumentation_without_client(self):
HTTPXClientInstrumentor().instrument()
results = [
Expand Down

0 comments on commit 2756081

Please sign in to comment.