From 409897fe2c3ddaaa129440c96b258321b8cc76e7 Mon Sep 17 00:00:00 2001 From: emdneto <9735060+emdneto@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:31:53 -0300 Subject: [PATCH] fixes --- CHANGELOG.md | 2 ++ .../instrumentation/httpx/__init__.py | 24 +++++++++---------- .../tests/test_httpx_integration.py | 5 ++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0fd2243dd..4c7fd69c48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#2616](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2616)) - `opentelemetry-instrumentation-confluent-kafka` Add support for produce purge ([#2638](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2638)) +- `opentelemetry-instrumentation-httpx` Implement new semantic convention opt-in with stable http semantic conventions + ([#2631](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2631)) ### Breaking changes diff --git a/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py b/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py index 05d99b205a..c79ac69c52 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py @@ -307,20 +307,18 @@ def _extract_response( ] ) -> typing.Tuple[int, Headers, httpx.SyncByteStream, dict, str]: if isinstance(response, httpx.Response): - return ( - response.status_code, - response.headers, - response.stream, - response.extensions, - response.http_version, - ) - - if isinstance(response, tuple): + status_code = response.status_code + headers = response.headers + stream = response.stream + extensions = response.extensions + http_version = response.http_version + else: status_code, headers, stream, extensions = response http_version = extensions.get("http_version", b"HTTP/1.1").decode( "ascii", errors="ignore" ) - return (status_code, headers, stream, extensions, http_version) + + return (status_code, headers, stream, extensions, http_version) def _apply_request_client_attributes_to_span( @@ -420,6 +418,7 @@ def __exit__( ) -> None: self._transport.__exit__(exc_type, exc_value, traceback) + # pylint: disable=R0914 def handle_request( self, *args, @@ -456,7 +455,7 @@ def handle_request( try: response = self._transport.handle_request(*args, **kwargs) - except Exception as exc: + except Exception as exc: # pylint: disable=W0703 exception = exc response = getattr(exc, "response", None) @@ -536,6 +535,7 @@ async def __aexit__( ) -> None: await self._transport.__aexit__(exc_type, exc_value, traceback) + # pylint: disable=R0914 async def handle_async_request(self, *args, **kwargs) -> typing.Union[ typing.Tuple[int, "Headers", httpx.AsyncByteStream, dict], httpx.Response, @@ -570,7 +570,7 @@ async def handle_async_request(self, *args, **kwargs) -> typing.Union[ response = await self._transport.handle_async_request( *args, **kwargs ) - except Exception as exc: + except Exception as exc: # pylint: disable=W0703 exception = exc response = getattr(exc, "response", None) diff --git a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py index bc7a1bf92d..fa4f4df74c 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=too-many-lines + import abc import asyncio import typing @@ -119,6 +121,9 @@ async def _async_no_update_request_hook(span: "Span", request: "RequestInfo"): return 123 +# pylint: disable=too-many-public-methods + + # Using this wrapper class to have a base class for the tests while also not # angering pylint or mypy when calling methods not in the class when only # subclassing abc.ABC.