Skip to content

Commit 59eb7ee

Browse files
committed
.
1 parent 5dd1a14 commit 59eb7ee

File tree

8 files changed

+25
-21
lines changed

8 files changed

+25
-21
lines changed

sentry_sdk/integrations/_wsgi_common.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ def _request_headers_to_span_attributes(headers):
230230
for header, value in headers.items():
231231
if isinstance(value, AnnotatedValue):
232232
value = SENSITIVE_DATA_SUBSTITUTE
233-
else:
234-
value = value.lower()
235-
attributes[f"http.request.header.{header}"] = value
233+
attributes[f"http.request.header.{header.lower()}"] = value
236234

237235
return attributes
238236

sentry_sdk/integrations/wsgi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ def _prepopulate_attributes(wsgi_environ, use_x_forwarded_for=False):
345345
query = wsgi_environ.get("QUERY_STRING")
346346
attributes["url.full"] = f"{url}?{query}"
347347

348-
attributes.update(_request_headers_to_span_attributes(_get_headers(wsgi_environ)))
348+
attributes.update(
349+
_request_headers_to_span_attributes(dict(_get_headers(wsgi_environ)))
350+
)
349351

350352
return attributes

tests/integrations/aiohttp/test_aiohttp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ async def kangaroo_handler(request):
309309
app.router.add_get("/tricks/kangaroo", kangaroo_handler)
310310

311311
client = await aiohttp_client(app)
312-
await client.get("/tricks/kangaroo?jump=high")
312+
await client.get(
313+
"/tricks/kangaroo?jump=high", headers={"Custom-Header": "Custom Value"}
314+
)
313315

314316
assert traces_sampler.call_count == 1
315317
sampling_context = traces_sampler.call_args_list[0][0][0]
@@ -324,6 +326,7 @@ async def kangaroo_handler(request):
324326
assert sampling_context["http.request.method"] == "GET"
325327
assert sampling_context["server.address"] == "127.0.0.1"
326328
assert sampling_context["server.port"].isnumeric()
329+
assert sampling_context["http.request.header.custom-header"] == "Custom Value"
327330

328331

329332
@pytest.mark.asyncio

tests/integrations/asgi/test_asgi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ def dummy_traces_sampler(sampling_context):
733733
assert sampling_context["http.request.method"] == "GET"
734734
assert sampling_context["network.protocol.version"] == "1.1"
735735
assert sampling_context["network.protocol.name"] == "http"
736+
assert sampling_context["http.request.header.custom-header"] == "Custom Value"
736737

737738
sentry_init(
738739
traces_sampler=dummy_traces_sampler,
@@ -742,4 +743,4 @@ def dummy_traces_sampler(sampling_context):
742743
app = SentryAsgiMiddleware(asgi3_app)
743744

744745
async with TestClient(app) as client:
745-
await client.get("/test?hello=there")
746+
await client.get("/test?hello=there", headers={"Custom-Header": "Custom Value"})

tests/integrations/aws_lambda/test_aws.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ def test_handler(event, context):
625625
"url.full": "http://x.io/sit/stay/rollover?repeat=twice",
626626
"network.protocol.name": "http",
627627
"server.address": "x.io",
628+
"http.request.header.custom-header": "Custom Value",
628629
}
629630
)
630631
)
@@ -643,7 +644,7 @@ def test_handler(event, context):
643644
)
644645
"""
645646
),
646-
b'{"httpMethod": "GET", "path": "/sit/stay/rollover", "query_string": {"repeat": "again"}, "headers": {"Host": "x.io", "X-Forwarded-Proto": "http"}}',
647+
b'{"httpMethod": "GET", "path": "/sit/stay/rollover", "query_string": {"repeat": "again"}, "headers": {"Host": "x.io", "X-Forwarded-Proto": "http", "Custom-Header": "Custom Value"}}',
647648
)
648649

649650
assert response["Payload"]["AssertionError raised"] is False

tests/integrations/gcp/test_gcp.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ def test_traces_sampler_gets_correct_values_in_sampling_context(
293293
dedent(
294294
"""
295295
functionhandler = None
296-
event = {
297-
"type": "chase",
298-
"chasers": ["Maisey", "Charlie"],
299-
"num_squirrels": 2,
300-
}
296+
297+
from collections import namedtuple
298+
GCPEvent = namedtuple("GCPEvent", ["headers"])
299+
event = GCPEvent(headers={"Custom-Header": "Custom Value"})
300+
301301
def cloud_function(functionhandler, event):
302302
# this runs after the transaction has started, which means we
303303
# can make assertions about traces_sampler
@@ -310,14 +310,15 @@ def cloud_function(functionhandler, event):
310310
"gcp.function.entry_point": "cloud_function",
311311
"gcp.function.project": "SquirrelChasing",
312312
"cloud.provider": "gcp",
313+
"http.request.header.custom-header": "Custom Value",
313314
})
314315
)
315316
except AssertionError:
316317
# catch the error and return it because the error itself will
317318
# get swallowed by the SDK as an "internal exception"
318-
return {"AssertionError raised": True,}
319+
return {"AssertionError raised": True}
319320
320-
return {"AssertionError raised": False,}
321+
return {"AssertionError raised": False}
321322
"""
322323
)
323324
+ FUNCTIONS_PRELUDE

tests/integrations/tornado/test_tornado.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ def traces_sampler(sampling_context):
467467
assert sampling_context["server.port"].isnumeric()
468468
assert sampling_context["network.protocol.name"] == "HTTP"
469469
assert sampling_context["network.protocol.version"] == "1.1"
470+
assert sampling_context["http.request.header.custom-header"] == "Custom Value"
470471

471472
return True
472473

@@ -476,4 +477,4 @@ def traces_sampler(sampling_context):
476477
)
477478

478479
client = tornado_testcase(Application([(r"/hi", HelloHandler)]))
479-
client.fetch("/hi?foo=bar")
480+
client.fetch("/hi?foo=bar", headers={"Custom-Header": "Custom Value"})

tests/integrations/wsgi/test_wsgi.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from collections import Counter
2-
from datetime import datetime
32
from unittest import mock
43

54
import pytest
@@ -327,10 +326,7 @@ def dogpark(environ, start_response):
327326
assert error_event["contexts"]["trace"]["trace_id"] == trace_id
328327

329328

330-
def test_traces_sampler_gets_correct_values_in_sampling_context(
331-
sentry_init,
332-
DictionaryContaining, # noqa:N803
333-
):
329+
def test_traces_sampler_gets_correct_values_in_sampling_context(sentry_init):
334330
def app(environ, start_response):
335331
start_response("200 OK", [])
336332
return ["Go get the ball! Good dog!"]
@@ -343,13 +339,14 @@ def traces_sampler(sampling_context):
343339
assert (
344340
sampling_context["url.full"] == "http://localhost/dogs/are/great/?cats=too"
345341
)
342+
assert sampling_context["http.request.header.custom-header"] == "Custom Value"
346343
return True
347344

348345
sentry_init(send_default_pii=True, traces_sampler=traces_sampler)
349346
app = SentryWsgiMiddleware(app)
350347
client = Client(app)
351348

352-
client.get("/dogs/are/great/?cats=too")
349+
client.get("/dogs/are/great/?cats=too", headers={"Custom-Header": "Custom Value"})
353350

354351

355352
def test_session_mode_defaults_to_request_mode_in_wsgi_handler(

0 commit comments

Comments
 (0)