Skip to content

Commit

Permalink
Update logger extra for sentry-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Dec 27, 2023
1 parent 7538859 commit bce9bd1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/analysis/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 18 additions & 9 deletions apps/deepl_integration/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
)

Expand Down Expand Up @@ -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',))
Expand All @@ -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,
},
},
)

Expand Down Expand Up @@ -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
}
},
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bce9bd1

Please sign in to comment.