From 4e3dc778e60fa9b0982c951fca9f192121cec284 Mon Sep 17 00:00:00 2001 From: Rafal Chrzanowski Date: Wed, 22 Apr 2026 10:23:13 +0200 Subject: [PATCH 1/3] fix: Added exception re-raise in httpx method overwrites Signed-off-by: Rafal Chrzanowski --- src/instana/instrumentation/httpx.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/instana/instrumentation/httpx.py b/src/instana/instrumentation/httpx.py index b8eb29df..84e24bb1 100644 --- a/src/instana/instrumentation/httpx.py +++ b/src/instana/instrumentation/httpx.py @@ -89,6 +89,7 @@ def handle_request_with_instana( _set_response_span_attributes(span, response) except Exception as e: span.record_exception(e) + raise else: return response @@ -118,6 +119,7 @@ async def handle_async_request_with_instana( _set_response_span_attributes(span, response) except Exception as e: span.record_exception(e) + raise else: return response From 08f02416afcfce615d98ba8836ae0c7f3e91cf72 Mon Sep 17 00:00:00 2001 From: Rafal Chrzanowski Date: Fri, 24 Apr 2026 08:48:17 +0200 Subject: [PATCH 2/3] refactor: CR adjustments Signed-off-by: Rafal Chrzanowski --- src/instana/instrumentation/httpx.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/instana/instrumentation/httpx.py b/src/instana/instrumentation/httpx.py index 84e24bb1..c08f468c 100644 --- a/src/instana/instrumentation/httpx.py +++ b/src/instana/instrumentation/httpx.py @@ -84,14 +84,21 @@ def handle_request_with_instana( request = args[0] _set_request_span_attributes(span, request) tracer.inject(span.context, Format.HTTP_HEADERS, request.headers) + except Exception: + logger.exception("httpx handle_request_with_instana pre-request:") + try: response = wrapped(*args, **kwargs) - _set_response_span_attributes(span, response) except Exception as e: span.record_exception(e) raise - else: - return response + + try: + _set_response_span_attributes(span, response) + except Exception: + logger.exception("httpx handle_request_with_instana post-request:") + + return response @wrapt.patch_function_wrapper("httpx", "AsyncHTTPTransport.handle_async_request") async def handle_async_request_with_instana( @@ -114,14 +121,21 @@ async def handle_async_request_with_instana( request = args[0] _set_request_span_attributes(span, request) tracer.inject(span.context, Format.HTTP_HEADERS, request.headers) + except Exception: + logger.exception("httpx handle_request_with_instana pre-request:") + try: response = await wrapped(*args, **kwargs) - _set_response_span_attributes(span, response) except Exception as e: span.record_exception(e) raise - else: - return response + + try: + _set_response_span_attributes(span, response) + except Exception: + logger.exception("httpx handle_request_with_instana post-request:") + + return response logger.debug("Instrumenting httpx") From e7984f08ef5387d4df129b03c18e3383912d16ae Mon Sep 17 00:00:00 2001 From: Rafal Chrzanowski Date: Fri, 24 Apr 2026 09:18:04 +0200 Subject: [PATCH 3/3] refactor: Removed unnecessary try-except Signed-off-by: Rafal Chrzanowski --- src/instana/instrumentation/httpx.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/instana/instrumentation/httpx.py b/src/instana/instrumentation/httpx.py index c08f468c..2f030d95 100644 --- a/src/instana/instrumentation/httpx.py +++ b/src/instana/instrumentation/httpx.py @@ -82,10 +82,12 @@ def handle_request_with_instana( ) as span: try: request = args[0] - _set_request_span_attributes(span, request) + _set_request_span_attributes(span, request) # Has its own try-except tracer.inject(span.context, Format.HTTP_HEADERS, request.headers) except Exception: - logger.exception("httpx handle_request_with_instana pre-request:") + logger.exception( + "httpx handle_request_with_instana pre-request:", exc_info=True + ) try: response = wrapped(*args, **kwargs) @@ -93,10 +95,7 @@ def handle_request_with_instana( span.record_exception(e) raise - try: - _set_response_span_attributes(span, response) - except Exception: - logger.exception("httpx handle_request_with_instana post-request:") + _set_response_span_attributes(span, response) # Has its own try-except return response @@ -119,10 +118,13 @@ async def handle_async_request_with_instana( ) as span: try: request = args[0] - _set_request_span_attributes(span, request) + _set_request_span_attributes(span, request) # Has its own try-except tracer.inject(span.context, Format.HTTP_HEADERS, request.headers) except Exception: - logger.exception("httpx handle_request_with_instana pre-request:") + logger.exception( + "httpx handle_async_request_with_instana pre-request:", + exc_info=True, + ) try: response = await wrapped(*args, **kwargs) @@ -130,10 +132,7 @@ async def handle_async_request_with_instana( span.record_exception(e) raise - try: - _set_response_span_attributes(span, response) - except Exception: - logger.exception("httpx handle_request_with_instana post-request:") + _set_response_span_attributes(span, response) # Has its own try-except return response