diff --git a/engine/apps/mobile_app/views.py b/engine/apps/mobile_app/views.py index 0e5b172d47..18f5303241 100644 --- a/engine/apps/mobile_app/views.py +++ b/engine/apps/mobile_app/views.py @@ -206,6 +206,10 @@ def _proxy_request(self, request: Request, *args, **kwargs) -> Response: raise NotFound(f"Downstream backend {downstream_backend} not supported") downstream_url = self._get_downstream_url(user.organization, downstream_backend, downstream_path) + + log_msg_common = f"{downstream_backend} request to {method} {downstream_url}" + logger.info(f"Proxying {log_msg_common}") + downstream_request_handler = getattr(requests, method.lower()) try: @@ -216,6 +220,7 @@ def _proxy_request(self, request: Request, *args, **kwargs) -> Response: headers=self._get_downstream_headers(request, downstream_backend, user), ) + logger.info(f"Successfully proxied {log_msg_common}") return Response(status=downstream_response.status_code, data=downstream_response.json()) except ( requests.exceptions.RequestException, diff --git a/engine/common/cloud_auth_api/client.py b/engine/common/cloud_auth_api/client.py index 12b869612d..8cfc35982e 100644 --- a/engine/common/cloud_auth_api/client.py +++ b/engine/common/cloud_auth_api/client.py @@ -1,5 +1,6 @@ import enum import json +import logging import typing from urllib.parse import urljoin @@ -11,6 +12,9 @@ from apps.user_management.models import Organization +logger = logging.getLogger(__name__) + + class CloudAuthApiException(Exception): """A generic 400 or 500 level exception from the Cloud Auth API""" @@ -61,6 +65,9 @@ def request_signed_token( } url = urljoin(self.api_base_url, "v1/sign") + common_log_msg = f"org_id={org_id} stack_id={stack_id} url={url}" + logger.info(f"Requesting signed token from Cloud Auth API {common_log_msg}") + response = requests.post( url, headers=headers, @@ -74,5 +81,11 @@ def request_signed_token( ) if response.status_code != status.HTTP_200_OK: + logger.warning( + f"Got non-HTTP 200 when attempting to request signed token from Cloud Auth API {common_log_msg} " + f"status_code={response.status_code} response={response.text}" + ) raise CloudAuthApiException(response.status_code, url, response.text, method="POST") + + logger.info(f"Successfully requested signed token from Cloud Auth API {common_log_msg}") return response.json()["data"]["token"]