From 6ab342dc4e7d0a4958a1ff3fe6af200673b97ec6 Mon Sep 17 00:00:00 2001 From: "Shi, Stone" Date: Sun, 14 Jul 2024 14:09:22 +0800 Subject: [PATCH] fix issue to not set url.full attribute Signed-off-by: Shi, Stone --- .../src/opentelemetry/instrumentation/asgi/__init__.py | 7 ++++--- .../tests/test_asgi_middleware.py | 5 ----- 2 files changed, 4 insertions(+), 8 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 f006f9b0c9..9ca4fc8d98 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py @@ -354,9 +354,10 @@ def collect_request_attributes( result, path, path, query_string, sem_conv_opt_in_mode ) if http_url: - _set_http_url( - result, remove_url_credentials(http_url), sem_conv_opt_in_mode - ) + 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 + ) http_method = scope.get("method", "") if 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 ff266cb5bf..05cefbce74 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py @@ -410,7 +410,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, @@ -691,7 +690,6 @@ def update_expected_server(expected): { SERVER_ADDRESS: "0.0.0.0", SERVER_PORT: 80, - URL_FULL: "http://0.0.0.0/", } ) return expected @@ -1007,7 +1005,6 @@ def test_websocket_new_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, @@ -1578,7 +1575,6 @@ def test_request_attributes_new_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", @@ -1637,7 +1633,6 @@ def test_query_string_new_semconv(self): self.scope, _HTTPStabilityMode.HTTP, ) - self.assertEqual(attrs[URL_FULL], "http://127.0.0.1/?foo=bar") def test_query_string_both_semconv(self): self.scope["query_string"] = b"foo=bar"