Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opentelemetry-instrumentation-httpx: make instrument_client a staticmethod again #3003

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `opentelemetry-instrumentation-httpx`: instrument_client is a static method again
([#3003](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3003))

### Breaking changes

- `opentelemetry-instrumentation-sqlalchemy` teach instruments version
Expand Down
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

@classmethod
def instrument_client(
self,
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(
self._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(
self._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(
self._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(
self._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,13 +910,20 @@ 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_called_on_the_class(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