From 0a3a8e790c065eaf65cd927ddb13b3ecfd454590 Mon Sep 17 00:00:00 2001 From: "Shi, Stone" Date: Thu, 1 Aug 2024 12:51:36 +0800 Subject: [PATCH] fix issue 2698 Signed-off-by: Shi, Stone --- .../opentelemetry/instrumentation/asgi/__init__.py | 12 ++++++------ .../tests/test_asgi_middleware.py | 6 ------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py index 34211ccb06..bc67056f31 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py @@ -225,6 +225,7 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A _set_http_url, _set_http_user_agent, _set_status, + set_string_attribute, ) from opentelemetry.instrumentation.asgi.types import ( ClientRequestHook, @@ -354,13 +355,12 @@ def collect_request_attributes( result, path, path, query_string, sem_conv_opt_in_mode ) if http_url: - if _report_old(sem_conv_opt_in_mode) or ( - sem_conv_opt_in_mode == _HTTPStabilityMode.HTTP_DUP - ): - _set_http_url( - result, remove_url_credentials(http_url), sem_conv_opt_in_mode + if _report_old(sem_conv_opt_in_mode): + set_string_attribute( + result, + SpanAttributes.HTTP_URL, + remove_url_credentials(http_url), ) - http_method = scope.get("method", "") if http_method: _set_http_method( diff --git a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py index b399ccad07..45409543a6 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py @@ -58,7 +58,6 @@ SERVER_PORT, ) from opentelemetry.semconv.attributes.url_attributes import ( - URL_FULL, URL_PATH, URL_QUERY, URL_SCHEME, @@ -446,7 +445,6 @@ def validate_outputs( SERVER_ADDRESS: "127.0.0.1", NETWORK_PROTOCOL_VERSION: "1.0", URL_PATH: "/", - URL_FULL: "http://127.0.0.1/", CLIENT_ADDRESS: "127.0.0.1", CLIENT_PORT: 32767, HTTP_RESPONSE_STATUS_CODE: 200, @@ -719,7 +717,6 @@ def update_expected_server(expected): SpanAttributes.HTTP_URL: "http://0.0.0.0/", SERVER_ADDRESS: "0.0.0.0", SERVER_PORT: 80, - URL_FULL: "http://0.0.0.0/", } ) return expected @@ -1092,7 +1089,6 @@ def test_websocket_both_semconv(self): SERVER_ADDRESS: self.scope["server"][0], NETWORK_PROTOCOL_VERSION: self.scope["http_version"], URL_PATH: self.scope["path"], - URL_FULL: f'{self.scope["scheme"]}://{self.scope["server"][0]}{self.scope["path"]}', CLIENT_ADDRESS: self.scope["client"][0], CLIENT_PORT: self.scope["client"][1], HTTP_RESPONSE_STATUS_CODE: 200, @@ -1672,7 +1668,6 @@ def test_request_attributes_both_semconv(self): SERVER_ADDRESS: "127.0.0.1", URL_PATH: "/", URL_QUERY: "foo=bar", - URL_FULL: "http://127.0.0.1/?foo=bar", SERVER_PORT: 80, URL_SCHEME: "http", NETWORK_PROTOCOL_VERSION: "1.0", @@ -1701,7 +1696,6 @@ def test_query_string_both_semconv(self): self.scope, _HTTPStabilityMode.HTTP_DUP, ) - self.assertEqual(attrs[URL_FULL], "http://127.0.0.1/?foo=bar") self.assertEqual( attrs[SpanAttributes.HTTP_URL], "http://127.0.0.1/?foo=bar" )