From e8f90ed599f14b92c59a8aa0e52a60cb92edbd4a Mon Sep 17 00:00:00 2001 From: Viswas Haridas <37623357+JustARatherRidiculouslyLongUsername@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:32:05 +0530 Subject: [PATCH 1/2] fix: add loggers for GET and DELETE requests (#222) * fix: travelperk not loading all invoice profiles integrate with the travelperk pagination API to fetch invoice profiles from all pages * refactor: move `get_all_generator` to `ApiBase` and rename variable * fix: generalise the `get_all_generator` method for all onject types and create an implementation in `InvoiceProfiles` * refactor: clarity * fix: apply travelperk sync fix to all existing accounts * test: add request and response logs to the travelperk api * fix: add loggers for GET and DELETE requests as well --- connectors/travelperk/apis/api_base.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/connectors/travelperk/apis/api_base.py b/connectors/travelperk/apis/api_base.py index c110a9d..7747d13 100644 --- a/connectors/travelperk/apis/api_base.py +++ b/connectors/travelperk/apis/api_base.py @@ -66,17 +66,24 @@ def _get_request(self, object_type: str, api_url: str, params: dict = {}) -> Lis 'Api-Version': '1' } + endpoint = '{0}{1}'.format(self.__server_url, api_url) + logger.debug(f"GET {endpoint}") + logger.debug(f"Params for GET request: {params}") response = requests.get( - '{0}{1}'.format(self.__server_url, api_url), + endpoint, headers=api_headers, params=params ) if response.status_code == 200: result = json.loads(response.text) + logger.debug(f"GET response: {result}") return result[object_type] else: - raise self._get_error(response.status_code, response.text) + error = self._get_error(response.status_code, response.text) + logger.info(f"GET request failed: {response.status_code} | {error.message}") + logger.info(f"GET response: {error.response}") + raise error def _get_all_generator(self, object_type: str, api_url: str): """ @@ -154,13 +161,18 @@ def _delete_request(self, api_url: str) -> Dict: 'Api-Version': '1' } + endpoint = '{0}{1}'.format(self.__server_url, api_url) + logger.debug(f"DELETE {endpoint}") response = requests.delete( - '{0}{1}'.format(self.__server_url, api_url), + endpoint, headers=api_headers ) if response.status_code == 200: + logger.debug(f"DELETE response: {response.text}") return response.text - else: - raise self._get_error(response.status_code, response.text) + error = self._get_error(response.status_code, response.text) + logger.info(f"DELETE request failed: {response.status_code} | {error.message}") + logger.info(f"DELETE response: {error.response}") + raise error From 1b66aca15966929ca0ac70cf1c09f516b1803234 Mon Sep 17 00:00:00 2001 From: Viswas Haridas <37623357+JustARatherRidiculouslyLongUsername@users.noreply.github.com> Date: Mon, 4 Nov 2024 10:51:54 +0530 Subject: [PATCH 2/2] fix: remove sentry transaction sampling (#221) * fix: remove sentry transaction sampling * test: check if removing transaction sampling works as expected * refactor: remove error logger --- admin_settings/sentry.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/admin_settings/sentry.py b/admin_settings/sentry.py index dafd069..976e5ca 100644 --- a/admin_settings/sentry.py +++ b/admin_settings/sentry.py @@ -14,7 +14,6 @@ def init(): send_default_pii=True, integrations=[DjangoIntegration()], environment=os.environ.get('SENTRY_ENV'), - traces_sampler=Sentry.traces_sampler, attach_stacktrace=True, before_send=Sentry.before_send, request_bodies='small', @@ -27,15 +26,6 @@ def init(): ], ) - @staticmethod - def traces_sampler(sampling_context): - # avoiding ready APIs in performance tracing - if sampling_context.get('wsgi_environ') is not None: - if 'ready/' in sampling_context['wsgi_environ']['PATH_INFO']: - return 0 - - return 1 - @staticmethod def before_send(event, hint): if 'exc_info' in hint: