From dafc560d73e65ec0706af5da9ce3f1eab3fa9dc1 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 19 May 2025 10:29:58 +0200 Subject: [PATCH] Fix ruff --- .../tests/test_fastapi_instrumentation.py | 48 +++++-------------- .../tests/test_requests_integration.py | 8 +--- 2 files changed, 15 insertions(+), 41 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py b/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py index eefd8bef30..5e041b1324 100644 --- a/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py @@ -56,7 +56,9 @@ HTTP_TARGET, HTTP_URL, ) -from opentelemetry.semconv._incubating.attributes.net_attributes import NET_HOST_PORT +from opentelemetry.semconv._incubating.attributes.net_attributes import ( + NET_HOST_PORT, +) from opentelemetry.semconv.attributes.http_attributes import ( HTTP_REQUEST_METHOD, HTTP_RESPONSE_STATUS_CODE, @@ -254,10 +256,7 @@ def test_sub_app_fastapi_call(self): spans_with_http_attributes = [ span for span in spans - if ( - HTTP_URL in span.attributes - or HTTP_TARGET in span.attributes - ) + if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes) ] # We expect only one span to have the HTTP attributes set (the SERVER span from the app itself) @@ -265,9 +264,7 @@ def test_sub_app_fastapi_call(self): self.assertEqual(1, len(spans_with_http_attributes)) for span in spans_with_http_attributes: - self.assertEqual( - "/sub/home", span.attributes[HTTP_TARGET] - ) + self.assertEqual("/sub/home", span.attributes[HTTP_TARGET]) self.assertEqual( "https://testserver:443/sub/home", span.attributes[HTTP_URL], @@ -318,19 +315,14 @@ def test_sub_app_fastapi_call(self): spans_with_http_attributes = [ span for span in spans - if ( - HTTP_URL in span.attributes - or HTTP_TARGET in span.attributes - ) + if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes) ] # We now expect spans with attributes from both the app and its sub app self.assertEqual(2, len(spans_with_http_attributes)) for span in spans_with_http_attributes: - self.assertEqual( - "/sub/home", span.attributes[HTTP_TARGET] - ) + self.assertEqual("/sub/home", span.attributes[HTTP_TARGET]) self.assertEqual( "https://testserver:443/sub/home", span.attributes[HTTP_URL], @@ -391,14 +383,10 @@ def test_fastapi_route_attribute_added(self): self.assertEqual(len(spans), 3) for span in spans: self.assertIn("GET /user/{username}", span.name) - self.assertEqual( - spans[-1].attributes[HTTP_ROUTE], "/user/{username}" - ) + self.assertEqual(spans[-1].attributes[HTTP_ROUTE], "/user/{username}") # ensure that at least one attribute that is populated by # the asgi instrumentation is successfully feeding though. - self.assertEqual( - spans[-1].attributes[HTTP_FLAVOR], "1.1" - ) + self.assertEqual(spans[-1].attributes[HTTP_FLAVOR], "1.1") def test_fastapi_excluded_urls(self): """Ensure that given fastapi routes are excluded.""" @@ -1213,19 +1201,14 @@ def test_sub_app_fastapi_call(self): spans_with_http_attributes = [ span for span in spans - if ( - HTTP_URL in span.attributes - or HTTP_TARGET in span.attributes - ) + if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes) ] # We now expect spans with attributes from both the app and its sub app self.assertEqual(2, len(spans_with_http_attributes)) for span in spans_with_http_attributes: - self.assertEqual( - "/sub/home", span.attributes[HTTP_TARGET] - ) + self.assertEqual("/sub/home", span.attributes[HTTP_TARGET]) self.assertEqual( "https://testserver:443/sub/home", span.attributes[HTTP_URL], @@ -1306,19 +1289,14 @@ def test_sub_app_fastapi_call(self): spans_with_http_attributes = [ span for span in spans - if ( - HTTP_URL in span.attributes - or HTTP_TARGET in span.attributes - ) + if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes) ] # We now expect spans with attributes from both the app and its sub app self.assertEqual(2, len(spans_with_http_attributes)) for span in spans_with_http_attributes: - self.assertEqual( - "/sub/home", span.attributes[HTTP_TARGET] - ) + self.assertEqual("/sub/home", span.attributes[HTTP_TARGET]) self.assertEqual( "https://testserver:443/sub/home", span.attributes[HTTP_URL], diff --git a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py index 7c2fdd1fd0..4850915494 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py +++ b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py @@ -376,9 +376,7 @@ def test_not_foundbasic(self): span = self.assert_span() - self.assertEqual( - span.attributes.get(HTTP_STATUS_CODE), 404 - ) + self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404) self.assertIs( span.status.status_code, @@ -417,9 +415,7 @@ def test_not_foundbasic_both_semconv(self): span = self.assert_span() - self.assertEqual( - span.attributes.get(HTTP_STATUS_CODE), 404 - ) + self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404) self.assertEqual(span.attributes.get(HTTP_RESPONSE_STATUS_CODE), 404) self.assertEqual(span.attributes.get(ERROR_TYPE), "404")