From bce9bd126e245edcac02a24137dc88c9dfdbe6a5 Mon Sep 17 00:00:00 2001 From: thenav56 Date: Wed, 27 Dec 2023 11:19:19 +0545 Subject: [PATCH] Update logger extra for sentry-logging --- apps/analysis/serializers.py | 2 +- apps/deepl_integration/handlers.py | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/analysis/serializers.py b/apps/analysis/serializers.py index 4f2d6972fb..4220b43911 100644 --- a/apps/analysis/serializers.py +++ b/apps/analysis/serializers.py @@ -834,7 +834,7 @@ def validate(self, data): if snaphost_file is None: logger.error( f'Failed to generate snapshot for report-pk: {report.id}', - extra={'context': errors} + extra={'data': {'errors': errors}}, ) raise serializers.ValidationError('Failed to generate snapshot') data['report_data_file'] = snaphost_file diff --git a/apps/deepl_integration/handlers.py b/apps/deepl_integration/handlers.py index d26b19cbaf..5d127bb982 100644 --- a/apps/deepl_integration/handlers.py +++ b/apps/deepl_integration/handlers.py @@ -182,24 +182,27 @@ def send_trigger_request_to_extractor(cls, draft_entry): 'authoring_organization': author_organizations, 'callback_url': cls.get_callback_url(), } + response_content = None try: response = requests.post( DeeplServiceEndpoint.ASSISTED_TAGGING_ENTRY_PREDICT_ENDPOINT, headers=cls.REQUEST_HEADERS, json=payload ) + response_content = response.content if response.status_code == 202: return True except Exception: logger.error('Assisted tagging send failed, Exception occurred!!', exc_info=True) draft_entry.prediction_status = DraftEntry.PredictionStatus.SEND_FAILED draft_entry.save(update_fields=('prediction_status',)) - _response = locals().get('response') logger.error( 'Assisted tagging send failed!!', extra={ - 'payload': payload, - 'response': _response.content if _response else None + 'data': { + 'payload': payload, + 'response': response_content, + }, }, ) @@ -365,12 +368,14 @@ def auto_trigger_request_to_extractor(cls, lead): ], "callback_url": cls.get_callback_url() } + response_content = None try: response = requests.post( url=DeeplServiceEndpoint.ENTRY_EXTRACTION_CLASSIFICATION, headers=cls.REQUEST_HEADERS, json=payload ) + response_content = response.content if response.status_code == 202: lead.auto_entry_extraction_status = Lead.AutoExtractionStatus.PENDING lead.save(update_fields=('auto_entry_extraction_status',)) @@ -380,12 +385,13 @@ def auto_trigger_request_to_extractor(cls, lead): logger.error('Entry Extraction send failed, Exception occurred!!', exc_info=True) lead.auto_entry_extraction_status = Lead.AutoExtractionStatus.FAILED lead.save(update_fields=('auto_entry_extraction_status',)) - _response = locals().get('response') logger.error( 'Entry Extraction send failed!!', extra={ - 'payload': payload, - 'response': _response.content if _response else None + 'data': { + 'payload': payload, + 'response': response_content, + }, }, ) @@ -566,23 +572,24 @@ def send_trigger_request_to_extractor( 'callback_url': callback_url, 'request_type': NlpRequestType.USER if high_priority else NlpRequestType.SYSTEM, } + response_content = None try: response = requests.post( DeeplServiceEndpoint.DOCS_EXTRACTOR_ENDPOINT, headers=cls.REQUEST_HEADERS, data=json.dumps(payload) ) + response_content = response.content if response.status_code == 202: return True except Exception: logger.error('Lead Extraction Failed, Exception occurred!!', exc_info=True) - _response = locals().get('response') logger.error( 'Lead Extraction Request Failed!!', extra={ 'data': { 'payload': payload, - 'response': _response.content if _response else None + 'response': response_content } }, ) @@ -871,7 +878,9 @@ def send_trigger_request_to_extractor(cls, obj: DeeplTrackBaseModel): logger.error( f'{cls.model.__name__} send failed!!', extra={ - 'context': error_extra_context + 'data': { + 'context': error_extra_context + } } ) obj.status = cls.model.Status.SEND_FAILED