Skip to content

Commit

Permalink
add some more logging to mobile app proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyorlando committed Jan 26, 2024
1 parent baddc64 commit 19686a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions engine/apps/mobile_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions engine/common/cloud_auth_api/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import enum
import json
import logging
import typing
from urllib.parse import urljoin

Expand All @@ -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"""

Expand Down Expand Up @@ -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,
Expand All @@ -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"]

0 comments on commit 19686a9

Please sign in to comment.