diff --git a/CHANGELOG.md b/CHANGELOG.md index 37f3dde9ce..2375eaf1ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#2425](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2425)) - `opentelemetry-instrumentation-flask` Add `http.method` to `span.name` ([#2454](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2454)) -- Record repeated HTTP headers in lists, rather than a comma separate strings +- Record repeated HTTP headers in lists, rather than a comma separate strings for ASGI based web frameworks ([#2361](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2361)) ### Added @@ -75,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - AwsLambdaInstrumentor sets `cloud.account.id` span attribute ([#2367](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2367)) + ## Version 1.23.0/0.44b0 (2024-02-23) - Drop support for 3.7 diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py index 86ff3a78cd..d30a100b0e 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py @@ -1003,8 +1003,7 @@ def test_repeat_custom_response_header_added_in_server_span(self): "text/plain; charset=utf-8", ), "http.response.header.my_custom_header": ( - "my-custom-value-1", - "my-custom-header-2", + "my-custom-value-1,my-custom-header-2", ), } self.assertEqual(span.kind, trace.SpanKind.SERVER) 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 19065f7bcc..0a873d0fc3 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -210,9 +210,7 @@ def response_hook(span: Span, environ: WSGIEnvironment, status: str, response_he import functools import typing import wsgiref.util as wsgiref_util -from collections import defaultdict from timeit import default_timer -from typing import DefaultDict from opentelemetry import context, trace from opentelemetry.instrumentation._semconv import ( @@ -422,10 +420,14 @@ def collect_custom_response_headers_attributes(response_headers): OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS ) ) - response_headers_dict: DefaultDict[str, list[str]] = defaultdict(list) + response_headers_dict = {} if response_headers: for key, val in response_headers: - response_headers_dict[key.lower()].append(val) + key = key.lower() + if key in response_headers_dict: + response_headers_dict[key] += "," + val + else: + response_headers_dict[key] = val return sanitize.sanitize_header_values( response_headers_dict, diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index ed4afbd44e..2b26cbb5f9 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py @@ -1032,8 +1032,7 @@ def test_repeat_custom_response_headers_added_in_server_span(self): span = self.memory_exporter.get_finished_spans()[0] expected = { "http.response.header.my_custom_header": ( - "my-custom-value-1", - "my-custom-value-2", + "my-custom-value-1,my-custom-value-2", ), } self.assertSpanHasAttributes(span, expected)