def _wrapper(request_func: Callable, method: str, url: str, **kwargs: Any) -> Response: try: timeout = kwargs.pop("timeout", REQUEST_TIMEOUT_IN_SECOND) response = request_func(method=method, url=url, timeout=timeout, **kwargs) json_logger.info( "External service called", extra={ "url": response.url, "statusCode": response.status_code, "duration": response.elapsed.total_seconds(), }, ) except Exception as exc: json_logger.exception("Call to external service failed with %s", exc, extra={ "method": method, "url": url }) raise exc return response
def id_check_application_update( body: serialization_beneficiaries.ApplicationUpdateRequest, ) -> serialization_beneficiaries.ApplicationUpdateResponse: try: application_id = int(body.id) except ValueError: raise ApiErrors({"id": "Not a number"}) # pylint: disable=raise-missing-from json_logger.info("Received an application to process", extra={ "category": "BeneficiaryAccount", "applicationId": application_id }) beneficiary_job.delay(application_id) return serialization_beneficiaries.ApplicationUpdateResponse()
def log_request_details( response: flask.wrappers.Response) -> flask.wrappers.Response: request_duration = datetime.utcnow() - g.start request_duration_in_milliseconds = round( request_duration.total_seconds() * 1000, 2) request_data = { "statusCode": response.status_code, "method": request.method, "route": request.url_rule, "path": request.path, "queryParams": request.query_string.decode("UTF-8"), "duration": request_duration_in_milliseconds, "size": response.headers.get("Content-Length", type=int), } json_logger.info("request details", extra=request_data) return response