Skip to content

Commit 68daff8

Browse files
authored
Merge branch 'main' into feature/eli-138-fix-cohort-label
2 parents 0093992 + 00b7b85 commit 68daff8

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/eligibility_signposting_api/views/eligibility.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030

3131
@eligibility_blueprint.before_request
3232
def before_request() -> None:
33+
logger.info(
34+
"request details",
35+
extra={
36+
"X-Request-ID": request.headers.get("X-Request-ID"),
37+
"X-Correlation-ID": request.headers.get("X-Correlation-ID"),
38+
},
39+
)
3340
AuditContext.add_request_details(request)
3441

3542

tests/unit/views/test_eligibility.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,3 +687,43 @@ def test_build_response_include_values_that_are_not_null(client: FlaskClient):
687687
assert action["description"] == "Contact GP"
688688
assert action["urlLink"] == "https://example.dummy/"
689689
assert action["urlLabel"] == "GP contact"
690+
691+
692+
@pytest.mark.parametrize(
693+
("headers", "expected_request_id"),
694+
[
695+
({"X-Request-ID": "test-request-id-123"}, "test-request-id-123"),
696+
(
697+
{"X-Request-ID": ""},
698+
"",
699+
),
700+
(
701+
{}, # No headers provided
702+
None,
703+
),
704+
],
705+
)
706+
def test_request_id_from_header_logging_variants(
707+
app: Flask, client: FlaskClient, caplog, headers: dict[str, str], expected_request_id: str
708+
):
709+
"""
710+
This test checks that the x-request-ID is logged so that it can be used to correlate logs
711+
with that of the logs from api-gateway
712+
"""
713+
with (
714+
get_app_container(app).override.service(EligibilityService, new=FakeEligibilityService()),
715+
get_app_container(app).override.service(AuditService, new=FakeAuditService()),
716+
):
717+
with caplog.at_level(logging.INFO):
718+
response = client.get("/patient-check/12345", headers=headers)
719+
720+
request_id_logged = False
721+
for record in caplog.records:
722+
request_id = getattr(record, "X-Request-ID", None)
723+
724+
if request_id == expected_request_id:
725+
request_id_logged = True
726+
break
727+
728+
assert request_id_logged
729+
assert response.status_code == HTTPStatus.OK

0 commit comments

Comments
 (0)