Skip to content

Commit

Permalink
Inbound email better logging (#5271)
Browse files Browse the repository at this point in the history
follow up to #5259
  • Loading branch information
vstpme authored Nov 21, 2024
1 parent 77364b4 commit 67604c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions engine/apps/email/inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def dispatch(self, request):
integration_token = self.get_integration_token_from_request(request)
if integration_token is None:
return HttpResponse(status=status.HTTP_400_BAD_REQUEST)
request.inbound_email_integration_token = integration_token # used in RequestTimeLoggingMiddleware
return super().dispatch(request, alert_channel_key=integration_token)

def post(self, request):
Expand Down Expand Up @@ -138,14 +139,15 @@ def message(self) -> AnymailInboundMessage | None:
try:
view.run_validators(self.request)
events = view.parse_events(self.request)
except (AnymailWebhookValidationFailure, AnymailAPIError) as e:
logger.info(f"inbound email webhook validation failed for ESP {esp}: {e}")
except (AnymailWebhookValidationFailure, AnymailAPIError):
continue

messages = [event.message for event in events if isinstance(event, AnymailInboundEvent)]
if messages:
logger.info(f"Received inbound email message from ESP: {esp}")
return messages[0]

logger.error("Failed to parse inbound email message")
return None

def check_inbound_email_settings_set(self):
Expand Down
2 changes: 1 addition & 1 deletion engine/engine/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def log_message(request, response, tag, message=""):
if len(split_path) >= 5:
integration_token = split_path[4]
else:
integration_token = None
integration_token = getattr(request, "inbound_email_integration_token", None)

message += f"integration_type={integration_type} integration_token={integration_token} "
logging.info(message)
Expand Down

0 comments on commit 67604c6

Please sign in to comment.