Skip to content

Commit 7556daa

Browse files
authored
Merge pull request #255 from ecmwf-projects/COPDS-2777-dep-exc-logs
Ensure dependencies exceptions are correctly logged
2 parents 77ad0a3 + 21206bf commit 7556daa

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

cads_processing_api_service/clients.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ def get_processes(
8989
),
9090
cursor: str | None = fastapi.Query(None, include_in_schema=False),
9191
back: bool | None = fastapi.Query(None, include_in_schema=False),
92-
portals: tuple[str] | None = fastapi.Depends(utils.get_portals),
92+
portals: tuple[str] | None = fastapi.Depends(
93+
exceptions.exception_logger(utils.get_portals)
94+
),
9395
) -> ogc_api_processes_fastapi.models.ProcessList:
9496
"""Implement OGC API - Processes `GET /processes` endpoint.
9597
@@ -146,7 +148,9 @@ def get_process(
146148
self,
147149
response: fastapi.Response,
148150
process_id: str = fastapi.Path(..., description="Process identifier."),
149-
portals: tuple[str] | None = fastapi.Depends(utils.get_portals),
151+
portals: tuple[str] | None = fastapi.Depends(
152+
exceptions.exception_logger(utils.get_portals)
153+
),
150154
) -> ogc_api_processes_fastapi.models.ProcessDescription:
151155
"""Implement OGC API - Processes `GET /processes/{process_id}` endpoint.
152156
@@ -200,7 +204,9 @@ def post_process_execution(
200204
request: fastapi.Request,
201205
process_id: str = fastapi.Path(..., description="Process identifier."),
202206
execution_content: models.Execute = fastapi.Body(...),
203-
auth_info: models.AuthInfo = fastapi.Depends(auth.get_auth_info),
207+
auth_info: models.AuthInfo = fastapi.Depends(
208+
exceptions.exception_logger(auth.get_auth_info)
209+
),
204210
) -> models.StatusInfo:
205211
"""Implement OGC API - Processes `POST /processes/{process_id}/execution` endpoint.
206212
@@ -355,7 +361,9 @@ def get_jobs(
355361
),
356362
cursor: str | None = fastapi.Query(None, include_in_schema=False),
357363
back: bool | None = fastapi.Query(None, include_in_schema=False),
358-
auth_info: models.AuthInfo = fastapi.Depends(auth.get_auth_info),
364+
auth_info: models.AuthInfo = fastapi.Depends(
365+
exceptions.exception_logger(auth.get_auth_info)
366+
),
359367
) -> models.JobList:
360368
"""Implement OGC API - Processes `GET /jobs` endpoint.
361369
@@ -488,7 +496,9 @@ def get_job(
488496
alias="logStartTime",
489497
description="Datetime of the first log message to be returned.",
490498
),
491-
auth_info: models.AuthInfo = fastapi.Depends(auth.get_auth_info),
499+
auth_info: models.AuthInfo = fastapi.Depends(
500+
exceptions.exception_logger(auth.get_auth_info)
501+
),
492502
) -> models.StatusInfo:
493503
"""Implement OGC API - Processes `GET /jobs/{job_id}` endpoint.
494504
@@ -614,7 +624,9 @@ def get_job(
614624
def get_job_results(
615625
self,
616626
job_id: str = fastapi.Path(..., description="Job identifier."),
617-
auth_info: models.AuthInfo = fastapi.Depends(auth.get_auth_info),
627+
auth_info: models.AuthInfo = fastapi.Depends(
628+
exceptions.exception_logger(auth.get_auth_info)
629+
),
618630
) -> ogc_api_processes_fastapi.models.Results:
619631
"""Implement OGC API - Processes `GET /jobs/{job_id}/results` endpoint.
620632
@@ -677,7 +689,9 @@ def get_job_results(
677689
def delete_job(
678690
self,
679691
job_id: str = fastapi.Path(..., description="Job identifier."),
680-
auth_info: models.AuthInfo = fastapi.Depends(auth.get_auth_info),
692+
auth_info: models.AuthInfo = fastapi.Depends(
693+
exceptions.exception_logger(auth.get_auth_info)
694+
),
681695
) -> models.StatusInfo:
682696
"""Implement OGC API - Processes `DELETE /jobs/{job_id}` endpoint.
683697

cads_processing_api_service/endpoints.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
def apply_constraints(
3131
process_id: str = fastapi.Path(..., description="Process identifier."),
3232
execution_content: models.Execute = fastapi.Body(...),
33-
portals: tuple[str] | None = fastapi.Depends(utils.get_portals),
33+
portals: tuple[str] | None = fastapi.Depends(
34+
exceptions.exception_logger(utils.get_portals)
35+
),
3436
) -> dict[str, Any]:
3537
request = execution_content.model_dump()
3638
table = cads_catalogue.database.Resource
@@ -66,7 +68,9 @@ def estimate_cost(
6668
),
6769
mandatory_inputs: bool = fastapi.Query(False, include_in_schema=False),
6870
execution_content: models.Execute = fastapi.Body(...),
69-
portals: tuple[str] | None = fastapi.Depends(utils.get_portals),
71+
portals: tuple[str] | None = fastapi.Depends(
72+
exceptions.exception_logger(utils.get_portals)
73+
),
7074
) -> models.RequestCost:
7175
"""
7276
Estimate the cost with the highest cost/limit ratio of the request.
@@ -144,7 +148,9 @@ def get_api_request(
144148
@exceptions.exception_logger
145149
def delete_jobs(
146150
request: models.DeleteJobs = fastapi.Body(...),
147-
auth_info: models.AuthInfo = fastapi.Depends(auth.get_auth_info),
151+
auth_info: models.AuthInfo = fastapi.Depends(
152+
exceptions.exception_logger(auth.get_auth_info)
153+
),
148154
) -> models.JobList:
149155
"""Delete jobs from the processing queue.
150156

cads_processing_api_service/exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class RateLimitExceeded(ogc_api_processes_fastapi.exceptions.OGCAPIException):
6666

6767

6868
def exception_logger(f: Callable[..., Any]) -> Callable[..., Any]:
69+
"""Log exceptions raised by the decorated function.
70+
71+
Using this instead of logging exceptions in the exceptions handler avoids
72+
including starlette-related tracebacks in the logs, which are not useful
73+
and typically very long.
74+
"""
75+
6976
@functools.wraps(f)
7077
def wrapper(*args: Any, **kwargs: Any) -> Any:
7178
try:

0 commit comments

Comments
 (0)