From d155540038068ee58c0f56b0a075208614acac0c Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Tue, 17 Dec 2024 18:43:22 +0100 Subject: [PATCH] httpx: update type hints to `RequestInfo`/`ResponseInfo` (#3105) --- CHANGELOG.md | 5 +++++ docs/nitpick-exceptions.ini | 2 ++ .../src/opentelemetry/instrumentation/httpx/__init__.py | 8 +++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b8d39ff0e..106d9408c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +- `opentelemetry-instrumentation-httpx` Fix `RequestInfo`/`ResponseInfo` type hints + ([#3105](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3105)) + ## Version 1.29.0/0.50b0 (2024-12-11) ### Added diff --git a/docs/nitpick-exceptions.ini b/docs/nitpick-exceptions.ini index 4b1b06f95b..e27bee26bb 100644 --- a/docs/nitpick-exceptions.ini +++ b/docs/nitpick-exceptions.ini @@ -29,6 +29,8 @@ py-class= httpx.SyncByteStream httpx.AsyncByteStream httpx.Response + httpx.URL + httpx.Headers aiohttp.web_request.Request yarl.URL cimpl.Producer 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 195c784408..d4e7571f61 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py @@ -192,6 +192,8 @@ async def async_response_hook(span, request, response): --- """ +from __future__ import annotations + import logging import typing from asyncio import iscoroutinefunction @@ -249,8 +251,8 @@ async def async_response_hook(span, request, response): class RequestInfo(typing.NamedTuple): method: bytes - url: URL - headers: typing.Optional[Headers] + url: httpx.URL + headers: httpx.Headers | None stream: typing.Optional[ typing.Union[httpx.SyncByteStream, httpx.AsyncByteStream] ] @@ -259,7 +261,7 @@ class RequestInfo(typing.NamedTuple): class ResponseInfo(typing.NamedTuple): status_code: int - headers: typing.Optional[Headers] + headers: httpx.Headers | None stream: typing.Iterable[bytes] extensions: typing.Optional[dict]