-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlogs_helper.py
More file actions
33 lines (26 loc) · 1.13 KB
/
logs_helper.py
File metadata and controls
33 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import logging
from collections.abc import Callable
from functools import wraps
from typing import Any
from mangum.types import LambdaContext, LambdaEvent
from eligibility_signposting_api.config.constants import CONSUMER_ID
logger = logging.getLogger(__name__)
def log_request_ids_from_headers() -> Callable:
def decorator(func: Callable) -> Callable:
@wraps(func)
def wrapper(event: LambdaEvent, context: LambdaContext) -> dict[str, Any] | None:
gateway_request_id = (event.get("requestContext") or {}).get("requestId")
headers = event.get("headers") or {}
logger.info(
"request trace metadata",
extra={
"x_request_id": headers.get("X-Request-ID"),
"x_correlation_id": headers.get("X-Correlation-ID"),
"gateway_request_id": gateway_request_id,
"nhse_product_id": headers.get(CONSUMER_ID),
"nhsd_application_id": headers.get("nhsd-application-id"),
},
)
return func(event, context)
return wrapper
return decorator