Skip to content

Commit 78cc725

Browse files
committed
Don't normalize headers with "hyphen -> underscore"
1 parent 490580d commit 78cc725

File tree

21 files changed

+253
-264
lines changed

21 files changed

+253
-264
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,10 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
128128
export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST=".*"
129129
130130
The name of the added span attribute will follow the format ``http.request.header.<header_name>`` where ``<header_name>``
131-
is the normalized HTTP header name (lowercase, with ``-`` replaced by ``_``). The value of the attribute will be a
132-
list containing the header values.
131+
is the normalized HTTP header name (lowercase). The value of the attribute will be a list containing the header values.
133132
134133
For example:
135-
``http.request.header.custom_request_header = ["<value1>", "<value2>"]``
134+
``http.request.header.custom-request-header = ["<value1>", "<value2>"]``
136135
137136
Response headers
138137
****************
@@ -162,11 +161,10 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
162161
export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE=".*"
163162
164163
The name of the added span attribute will follow the format ``http.response.header.<header_name>`` where ``<header_name>``
165-
is the normalized HTTP header name (lowercase, with ``-`` replaced by ``_``). The value of the attribute will be a
166-
list containing the header values.
164+
is the normalized HTTP header name (lowercase). The value of the attribute will be a list containing the header values.
167165
168166
For example:
169-
``http.response.header.custom_response_header = ["<value1>", "<value2>"]``
167+
``http.response.header.custom-response-header = ["<value1>", "<value2>"]``
170168
171169
Sanitizing headers
172170
******************

instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_custom_headers.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,19 @@ async def test_http_custom_request_headers_in_span_attributes(self):
153153
await self.get_all_output()
154154
span_list = self.exporter.get_finished_spans()
155155
expected = {
156-
"http.request.header.custom_test_header_1": (
156+
"http.request.header.custom-test-header-1": (
157157
"test-header-value-1",
158158
),
159-
"http.request.header.custom_test_header_2": (
159+
"http.request.header.custom-test-header-2": (
160160
"test-header-value-2",
161161
),
162-
"http.request.header.regex_test_header_1": ("Regex Test Value 1",),
163-
"http.request.header.regex_test_header_2": (
162+
"http.request.header.regex-test-header-1": ("Regex Test Value 1",),
163+
"http.request.header.regex-test-header-2": (
164164
"RegexTestValue2,RegexTestValue3",
165165
),
166-
"http.request.header.non_utf8_header": ("Moto Z²",),
167-
"http.request.header.moto_z²_non_utf8_header_key": ("Moto Z²",),
168-
"http.request.header.my_secret_header": ("[REDACTED]",),
166+
"http.request.header.non-utf8-header": ("Moto Z²",),
167+
"http.request.header.moto-z²-non-utf8-header-key": ("Moto Z²",),
168+
"http.request.header.my-secret-header": ("[REDACTED]",),
169169
}
170170
for span in span_list:
171171
if span.kind == SpanKind.SERVER:
@@ -183,7 +183,7 @@ async def test_http_repeat_request_headers_in_span_attributes(self):
183183
await self.get_all_output()
184184
span_list = self.exporter.get_finished_spans()
185185
expected = {
186-
"http.request.header.custom_test_header_1": (
186+
"http.request.header.custom-test-header-1": (
187187
"test-header-value-1",
188188
"test-header-value-2",
189189
),
@@ -202,12 +202,12 @@ async def test_http_custom_request_headers_not_in_span_attributes(self):
202202
await self.get_all_output()
203203
span_list = self.exporter.get_finished_spans()
204204
expected = {
205-
"http.request.header.custom_test_header_1": (
205+
"http.request.header.custom-test-header-1": (
206206
"test-header-value-1",
207207
),
208208
}
209209
not_expected = {
210-
"http.request.header.custom_test_header_2": (
210+
"http.request.header.custom-test-header-2": (
211211
"test-header-value-2",
212212
),
213213
}
@@ -228,21 +228,21 @@ async def test_http_custom_response_headers_in_span_attributes(self):
228228
await self.get_all_output()
229229
span_list = self.exporter.get_finished_spans()
230230
expected = {
231-
"http.response.header.custom_test_header_1": (
231+
"http.response.header.custom-test-header-1": (
232232
"test-header-value-1",
233233
),
234-
"http.response.header.custom_test_header_2": (
234+
"http.response.header.custom-test-header-2": (
235235
"test-header-value-2",
236236
),
237-
"http.response.header.my_custom_regex_header_1": (
237+
"http.response.header.my-custom-regex-header-1": (
238238
"my-custom-regex-value-1,my-custom-regex-value-2",
239239
),
240-
"http.response.header.my_custom_regex_header_2": (
240+
"http.response.header.my-custom-regex-header-2": (
241241
"my-custom-regex-value-3,my-custom-regex-value-4",
242242
),
243-
"http.response.header.my_secret_header": ("[REDACTED]",),
244-
"http.response.header.non_utf8_header": ("Moto Z²",),
245-
"http.response.header.moto_z²_non_utf8_header_key": ("Moto Z²",),
243+
"http.response.header.my-secret-header": ("[REDACTED]",),
244+
"http.response.header.non-utf8-header": ("Moto Z²",),
245+
"http.response.header.moto-z²-non-utf8-header-key": ("Moto Z²",),
246246
}
247247
for span in span_list:
248248
if span.kind == SpanKind.SERVER:
@@ -259,7 +259,7 @@ async def test_http_repeat_response_headers_in_span_attributes(self):
259259
await self.get_all_output()
260260
span_list = self.exporter.get_finished_spans()
261261
expected = {
262-
"http.response.header.custom_test_header_1": (
262+
"http.response.header.custom-test-header-1": (
263263
"test-header-value-1",
264264
"test-header-value-2",
265265
),
@@ -278,7 +278,7 @@ async def test_http_custom_response_headers_not_in_span_attributes(self):
278278
await self.get_all_output()
279279
span_list = self.exporter.get_finished_spans()
280280
not_expected = {
281-
"http.response.header.custom_test_header_3": (
281+
"http.response.header.custom-test-header-3": (
282282
"test-header-value-3",
283283
),
284284
}
@@ -312,17 +312,17 @@ async def test_websocket_custom_request_headers_in_span_attributes(self):
312312
await self.get_all_output()
313313
span_list = self.exporter.get_finished_spans()
314314
expected = {
315-
"http.request.header.custom_test_header_1": (
315+
"http.request.header.custom-test-header-1": (
316316
"test-header-value-1",
317317
),
318-
"http.request.header.custom_test_header_2": (
318+
"http.request.header.custom-test-header-2": (
319319
"test-header-value-2",
320320
),
321-
"http.request.header.regex_test_header_1": ("Regex Test Value 1",),
322-
"http.request.header.regex_test_header_2": (
321+
"http.request.header.regex-test-header-1": ("Regex Test Value 1",),
322+
"http.request.header.regex-test-header-2": (
323323
"RegexTestValue2,RegexTestValue3",
324324
),
325-
"http.request.header.my_secret_header": ("[REDACTED]",),
325+
"http.request.header.my-secret-header": ("[REDACTED]",),
326326
}
327327
for span in span_list:
328328
if span.kind == SpanKind.SERVER:
@@ -352,7 +352,7 @@ async def test_websocket_custom_request_headers_not_in_span_attributes(
352352
await self.get_all_output()
353353
span_list = self.exporter.get_finished_spans()
354354
not_expected = {
355-
"http.request.header.custom_test_header_3": (
355+
"http.request.header.custom-test-header-3": (
356356
"test-header-value-3",
357357
),
358358
}
@@ -384,19 +384,19 @@ async def test_websocket_custom_response_headers_in_span_attributes(self):
384384
await self.get_all_output()
385385
span_list = self.exporter.get_finished_spans()
386386
expected = {
387-
"http.response.header.custom_test_header_1": (
387+
"http.response.header.custom-test-header-1": (
388388
"test-header-value-1",
389389
),
390-
"http.response.header.custom_test_header_2": (
390+
"http.response.header.custom-test-header-2": (
391391
"test-header-value-2",
392392
),
393-
"http.response.header.my_custom_regex_header_1": (
393+
"http.response.header.my-custom-regex-header-1": (
394394
"my-custom-regex-value-1,my-custom-regex-value-2",
395395
),
396-
"http.response.header.my_custom_regex_header_2": (
396+
"http.response.header.my-custom-regex-header-2": (
397397
"my-custom-regex-value-3,my-custom-regex-value-4",
398398
),
399-
"http.response.header.my_secret_header": ("[REDACTED]",),
399+
"http.response.header.my-secret-header": ("[REDACTED]",),
400400
}
401401
for span in span_list:
402402
if span.kind == SpanKind.SERVER:
@@ -427,7 +427,7 @@ async def test_websocket_custom_response_headers_not_in_span_attributes(
427427
await self.get_all_output()
428428
span_list = self.exporter.get_finished_spans()
429429
not_expected = {
430-
"http.response.header.custom_test_header_3": (
430+
"http.response.header.custom-test-header-3": (
431431
"test-header-value-3",
432432
),
433433
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,10 @@ def response_hook(span, request, response):
173173
export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST=".*"
174174
175175
The name of the added span attribute will follow the format ``http.request.header.<header_name>`` where ``<header_name>``
176-
is the normalized HTTP header name (lowercase, with ``-`` replaced by ``_``). The value of the attribute will be a
177-
single item list containing all the header values.
176+
is the normalized HTTP header name (lowercase). The value of the attribute will be a single item list containing all the header values.
178177
179178
For example:
180-
``http.request.header.custom_request_header = ["<value1>,<value2>"]``
179+
``http.request.header.custom-request-header = ["<value1>,<value2>"]``
181180
182181
Response headers
183182
****************
@@ -207,11 +206,11 @@ def response_hook(span, request, response):
207206
export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE=".*"
208207
209208
The name of the added span attribute will follow the format ``http.response.header.<header_name>`` where ``<header_name>``
210-
is the normalized HTTP header name (lowercase, with ``-`` replaced by ``_``). The value of the attribute will be a
209+
is the normalized HTTP header name (lowercase). The value of the attribute will be a
211210
single item list containing all the header values.
212211
213212
For example:
214-
``http.response.header.custom_response_header = ["<value1>,<value2>"]``
213+
``http.response.header.custom-response-header = ["<value1>,<value2>"]``
215214
216215
Sanitizing headers
217216
******************

instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,17 +1007,17 @@ def tearDownClass(cls):
10071007

10081008
def test_http_custom_request_headers_in_span_attributes(self):
10091009
expected = {
1010-
"http.request.header.custom_test_header_1": (
1010+
"http.request.header.custom-test-header-1": (
10111011
"test-header-value-1",
10121012
),
1013-
"http.request.header.custom_test_header_2": (
1013+
"http.request.header.custom-test-header-2": (
10141014
"test-header-value-2",
10151015
),
1016-
"http.request.header.regex_test_header_1": ("Regex Test Value 1",),
1017-
"http.request.header.regex_test_header_2": (
1016+
"http.request.header.regex-test-header-1": ("Regex Test Value 1",),
1017+
"http.request.header.regex-test-header-2": (
10181018
"RegexTestValue2,RegexTestValue3",
10191019
),
1020-
"http.request.header.my_secret_header": ("[REDACTED]",),
1020+
"http.request.header.my-secret-header": ("[REDACTED]",),
10211021
}
10221022
Client(
10231023
HTTP_CUSTOM_TEST_HEADER_1="test-header-value-1",
@@ -1036,7 +1036,7 @@ def test_http_custom_request_headers_in_span_attributes(self):
10361036

10371037
def test_http_custom_request_headers_not_in_span_attributes(self):
10381038
not_expected = {
1039-
"http.request.header.custom_test_header_2": (
1039+
"http.request.header.custom-test-header-2": (
10401040
"test-header-value-2",
10411041
),
10421042
}
@@ -1052,19 +1052,19 @@ def test_http_custom_request_headers_not_in_span_attributes(self):
10521052

10531053
def test_http_custom_response_headers_in_span_attributes(self):
10541054
expected = {
1055-
"http.response.header.custom_test_header_1": (
1055+
"http.response.header.custom-test-header-1": (
10561056
"test-header-value-1",
10571057
),
1058-
"http.response.header.custom_test_header_2": (
1058+
"http.response.header.custom-test-header-2": (
10591059
"test-header-value-2",
10601060
),
1061-
"http.response.header.my_custom_regex_header_1": (
1061+
"http.response.header.my-custom-regex-header-1": (
10621062
"my-custom-regex-value-1,my-custom-regex-value-2",
10631063
),
1064-
"http.response.header.my_custom_regex_header_2": (
1064+
"http.response.header.my-custom-regex-header-2": (
10651065
"my-custom-regex-value-3,my-custom-regex-value-4",
10661066
),
1067-
"http.response.header.my_secret_header": ("[REDACTED]",),
1067+
"http.response.header.my-secret-header": ("[REDACTED]",),
10681068
}
10691069
Client().get("/traced_custom_header/")
10701070
spans = self.exporter.get_finished_spans()
@@ -1077,7 +1077,7 @@ def test_http_custom_response_headers_in_span_attributes(self):
10771077

10781078
def test_http_custom_response_headers_not_in_span_attributes(self):
10791079
not_expected = {
1080-
"http.response.header.custom_test_header_3": (
1080+
"http.response.header.custom-test-header-3": (
10811081
"test-header-value-3",
10821082
),
10831083
}

instrumentation/opentelemetry-instrumentation-django/tests/test_middleware_asgi.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -735,17 +735,17 @@ def tearDownClass(cls):
735735

736736
async def test_http_custom_request_headers_in_span_attributes(self):
737737
expected = {
738-
"http.request.header.custom_test_header_1": (
738+
"http.request.header.custom-test-header-1": (
739739
"test-header-value-1",
740740
),
741-
"http.request.header.custom_test_header_2": (
741+
"http.request.header.custom-test-header-2": (
742742
"test-header-value-2",
743743
),
744-
"http.request.header.regex_test_header_1": ("Regex Test Value 1",),
745-
"http.request.header.regex_test_header_2": (
744+
"http.request.header.regex-test-header-1": ("Regex Test Value 1",),
745+
"http.request.header.regex-test-header-2": (
746746
"RegexTestValue2,RegexTestValue3",
747747
),
748-
"http.request.header.my_secret_header": ("[REDACTED]",),
748+
"http.request.header.my-secret-header": ("[REDACTED]",),
749749
}
750750
await self.async_client.get(
751751
"/traced/",
@@ -767,7 +767,7 @@ async def test_http_custom_request_headers_in_span_attributes(self):
767767

768768
async def test_http_custom_request_headers_not_in_span_attributes(self):
769769
not_expected = {
770-
"http.request.header.custom_test_header_2": (
770+
"http.request.header.custom-test-header-2": (
771771
"test-header-value-2",
772772
),
773773
}
@@ -788,19 +788,19 @@ async def test_http_custom_request_headers_not_in_span_attributes(self):
788788

789789
async def test_http_custom_response_headers_in_span_attributes(self):
790790
expected = {
791-
"http.response.header.custom_test_header_1": (
791+
"http.response.header.custom-test-header-1": (
792792
"test-header-value-1",
793793
),
794-
"http.response.header.custom_test_header_2": (
794+
"http.response.header.custom-test-header-2": (
795795
"test-header-value-2",
796796
),
797-
"http.response.header.my_custom_regex_header_1": (
797+
"http.response.header.my-custom-regex-header-1": (
798798
"my-custom-regex-value-1,my-custom-regex-value-2",
799799
),
800-
"http.response.header.my_custom_regex_header_2": (
800+
"http.response.header.my-custom-regex-header-2": (
801801
"my-custom-regex-value-3,my-custom-regex-value-4",
802802
),
803-
"http.response.header.my_secret_header": ("[REDACTED]",),
803+
"http.response.header.my-secret-header": ("[REDACTED]",),
804804
}
805805
await self.async_client.get("/traced_custom_header/")
806806
spans = self.exporter.get_finished_spans()
@@ -813,7 +813,7 @@ async def test_http_custom_response_headers_in_span_attributes(self):
813813

814814
async def test_http_custom_response_headers_not_in_span_attributes(self):
815815
not_expected = {
816-
"http.response.header.custom_test_header_3": (
816+
"http.response.header.custom-test-header-3": (
817817
"test-header-value-3",
818818
),
819819
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,10 @@ def response_hook(span, req, resp):
121121
export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST=".*"
122122
123123
The name of the added span attribute will follow the format ``http.request.header.<header_name>`` where ``<header_name>``
124-
is the normalized HTTP header name (lowercase, with ``-`` replaced by ``_``). The value of the attribute will be a
125-
single item list containing all the header values.
124+
is the normalized HTTP header name (lowercase). The value of the attribute will be a single item list containing all the header values.
126125
127126
For example:
128-
``http.request.header.custom_request_header = ["<value1>,<value2>"]``
127+
``http.request.header.custom-request-header = ["<value1>,<value2>"]``
129128
130129
Response headers
131130
****************
@@ -155,11 +154,10 @@ def response_hook(span, req, resp):
155154
export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE=".*"
156155
157156
The name of the added span attribute will follow the format ``http.response.header.<header_name>`` where ``<header_name>``
158-
is the normalized HTTP header name (lowercase, with ``-`` replaced by ``_``). The value of the attribute will be a
159-
single item list containing all the header values.
157+
is the normalized HTTP header name (lowercase). The value of the attribute will be a single item list containing all the header values.
160158
161159
For example:
162-
``http.response.header.custom_response_header = ["<value1>,<value2>"]``
160+
``http.response.header.custom-response-header = ["<value1>,<value2>"]``
163161
164162
Sanitizing headers
165163
******************

0 commit comments

Comments
 (0)