diff --git a/src/instana/instrumentation/httpx.py b/src/instana/instrumentation/httpx.py index b8eb29df..2f030d95 100644 --- a/src/instana/instrumentation/httpx.py +++ b/src/instana/instrumentation/httpx.py @@ -82,15 +82,22 @@ 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:", exc_info=True + ) + try: response = wrapped(*args, **kwargs) - _set_response_span_attributes(span, response) except Exception as e: span.record_exception(e) - else: - return response + raise + + _set_response_span_attributes(span, response) # Has its own try-except + + return response @wrapt.patch_function_wrapper("httpx", "AsyncHTTPTransport.handle_async_request") async def handle_async_request_with_instana( @@ -111,15 +118,23 @@ 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_async_request_with_instana pre-request:", + exc_info=True, + ) + try: response = await wrapped(*args, **kwargs) - _set_response_span_attributes(span, response) except Exception as e: span.record_exception(e) - else: - return response + raise + + _set_response_span_attributes(span, response) # Has its own try-except + + return response logger.debug("Instrumenting httpx")