[release/v1.28.x-0.49bx] opentelemetry-instrumentation-httpx: make instrument_client a staticmethod again (#3003) (#3008)

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

* opentelemetry-instrumentation-httpx: make instrument_client a staticmethod again

* ADd changelog

* Can be a classmethod

---------

Co-authored-by: Leighton Chen <lechen@microsoft.com>

* Move changelog entry to Unreleased section

---------

Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
This commit is contained in:
Aaron Abbott
2024-11-15 11:08:57 -05:00
committed by GitHub
parent ec1c9ea8a8
commit 10b23cd9b4
3 changed files with 25 additions and 6 deletions

View File

@ -9,6 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
> The following components are released independently and maintain individual CHANGELOG files.
> Use [this search for a list of all CHANGELOG.md files in this repo](https://github.com/search?q=repo%3Aopen-telemetry%2Fopentelemetry-python-contrib+path%3A**%2FCHANGELOG.md&type=code).
## Unreleased
### Added
### Fixed
- `opentelemetry-instrumentation-httpx`: instrument_client is a static method again
([#3003](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3003))
### Breaking changes
## Version 1.28.1/0.49b1 (2024-11-08)
### Added

View File

@ -938,8 +938,9 @@ class HTTPXClientInstrumentor(BaseInstrumentor):
return response
@classmethod
def instrument_client(
self,
cls,
client: typing.Union[httpx.Client, httpx.AsyncClient],
tracer_provider: TracerProvider = None,
request_hook: typing.Union[
@ -996,7 +997,7 @@ class HTTPXClientInstrumentor(BaseInstrumentor):
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,
@ -1008,7 +1009,7 @@ class HTTPXClientInstrumentor(BaseInstrumentor):
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,
@ -1021,7 +1022,7 @@ class HTTPXClientInstrumentor(BaseInstrumentor):
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,
@ -1033,7 +1034,7 @@ class HTTPXClientInstrumentor(BaseInstrumentor):
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,

View File

@ -910,13 +910,20 @@ class BaseTestCases:
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 = [