diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index f1cbbfebd6..9253251eba 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -229,9 +229,7 @@ def capture_custom_request_headers(environ, attributes): ) for header_name in custom_request_headers: wsgi_env_var = header_name.upper().replace("-", "_") - header_values = environ.get( - "HTTP_{wsgi_env_var}".format(wsgi_env_var=wsgi_env_var) - ) + header_values = environ.get(f"HTTP_{wsgi_env_var}") if header_values: key = normalise_request_header_name(header_name) diff --git a/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py b/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py index 7d53898008..df051b85a5 100644 --- a/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py +++ b/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py @@ -104,15 +104,13 @@ def remove_url_credentials(url: str) -> str: def normalise_request_header_name(header): - return "http.request.header.{key}".format( - key=header.lower().replace("-", "_") - ) + key = header.lower().replace("-", "_") + return f"http.request.header.{key}" def normalise_response_header_name(header): - return "http.response.header.{key}".format( - key=header.lower().replace("-", "_") - ) + key=header.lower().replace("-", "_") + return f"http.response.header.{key}" def get_custom_headers(env_var): diff --git a/util/opentelemetry-util-http/tests/test_capture_custom_headers.py b/util/opentelemetry-util-http/tests/test_capture_custom_headers.py index b07f50eeaf..dd134c21b5 100644 --- a/util/opentelemetry-util-http/tests/test_capture_custom_headers.py +++ b/util/opentelemetry-util-http/tests/test_capture_custom_headers.py @@ -33,7 +33,7 @@ def test_get_custom_request_header(self): custom_headers_to_capture = get_custom_headers( OTEL_PYTHON_CAPTURE_REQUEST_HEADERS ) - assert custom_headers_to_capture == ["User-Agent", "Test-Header"] + self.assertEqual(custom_headers_to_capture, ["User-Agent", "Test-Header"]) @patch.dict( "os.environ", @@ -45,16 +45,16 @@ def test_get_custom_response_header(self): custom_headers_to_capture = get_custom_headers( OTEL_PYTHON_CAPTURE_RESPONSE_HEADERS ) - assert custom_headers_to_capture == [ + self.assertEqual(custom_headers_to_capture, [ "content-type", "content-length", "test-header", - ] + ]) def test_normalise_request_header_name(self): key = normalise_request_header_name("Test-Header") - assert key == "http.request.header.test_header" + self.assertEqual(key, "http.request.header.test_header") def test_normalise_response_header_name(self): key = normalise_response_header_name("Test-Header") - assert key == "http.response.header.test_header" + self.assertEqual(key, "http.response.header.test_header")