Skip to content

Commit f2b2288

Browse files
author
Ashutosh Goel
committed
Passing response headers in correct format in pyramid
Fixing lint errors
1 parent 57126e2 commit f2b2288

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def trace_tween(request):
161161
otel_wsgi.add_response_attributes(
162162
span,
163163
response_or_exception.status,
164-
response_or_exception.headers,
164+
response_or_exception.headerlist,
165165
)
166166

167167
propagator = get_global_response_propagator()

instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ def capture_custom_request_headers(environ, attributes):
229229
)
230230
for header_name in custom_request_headers:
231231
wsgi_env_var = header_name.upper().replace("-", "_")
232-
header_values = environ.get(
233-
"HTTP_{wsgi_env_var}".format(wsgi_env_var=wsgi_env_var)
234-
)
232+
header_values = environ.get(f"HTTP_{wsgi_env_var}")
235233

236234
if header_values:
237235
key = normalise_request_header_name(header_name)

util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,13 @@ def remove_url_credentials(url: str) -> str:
104104

105105

106106
def normalise_request_header_name(header):
107-
return "http.request.header.{key}".format(
108-
key=header.lower().replace("-", "_")
109-
)
107+
key = header.lower().replace("-", "_")
108+
return f"http.request.header.{key}"
110109

111110

112111
def normalise_response_header_name(header):
113-
return "http.response.header.{key}".format(
114-
key=header.lower().replace("-", "_")
115-
)
112+
key = header.lower().replace("-", "_")
113+
return f"http.response.header.{key}"
116114

117115

118116
def get_custom_headers(env_var):

util/opentelemetry-util-http/tests/test_capture_custom_headers.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def test_get_custom_request_header(self):
3333
custom_headers_to_capture = get_custom_headers(
3434
OTEL_PYTHON_CAPTURE_REQUEST_HEADERS
3535
)
36-
assert custom_headers_to_capture == ["User-Agent", "Test-Header"]
36+
self.assertEqual(
37+
custom_headers_to_capture, ["User-Agent", "Test-Header"]
38+
)
3739

3840
@patch.dict(
3941
"os.environ",
@@ -45,16 +47,19 @@ def test_get_custom_response_header(self):
4547
custom_headers_to_capture = get_custom_headers(
4648
OTEL_PYTHON_CAPTURE_RESPONSE_HEADERS
4749
)
48-
assert custom_headers_to_capture == [
49-
"content-type",
50-
"content-length",
51-
"test-header",
52-
]
50+
self.assertEqual(
51+
custom_headers_to_capture,
52+
[
53+
"content-type",
54+
"content-length",
55+
"test-header",
56+
],
57+
)
5358

5459
def test_normalise_request_header_name(self):
5560
key = normalise_request_header_name("Test-Header")
56-
assert key == "http.request.header.test_header"
61+
self.assertEqual(key, "http.request.header.test_header")
5762

5863
def test_normalise_response_header_name(self):
5964
key = normalise_response_header_name("Test-Header")
60-
assert key == "http.response.header.test_header"
65+
self.assertEqual(key, "http.response.header.test_header")

0 commit comments

Comments
 (0)