Skip to content

Commit

Permalink
Added log prior to provider call for total time in system
Browse files Browse the repository at this point in the history
  • Loading branch information
k-macmillan committed Feb 7, 2025
1 parent 69912b9 commit 124115a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/clients/sms/aws_pinpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
NOTIFICATION_TEMPORARY_FAILURE,
NOTIFICATION_PERMANENT_FAILURE,
PINPOINT_PROVIDER,
SMS_TYPE,
STATUS_REASON_BLOCKED,
STATUS_REASON_INVALID_NUMBER,
STATUS_REASON_RETRYABLE,
Expand Down Expand Up @@ -83,13 +84,20 @@ def send_sms(
reference,
multi=True,
sender=None,
created_at=datetime.utcnow(),
**kwargs,
):
aws_phone_number = self.origination_number if sender is None else sender
recipient_number = str(to)

try:
start_time = monotonic()
# Log how long it spent in our system before we sent it
self.logger.info(
'Total time spent to send %s notification: %s',
SMS_TYPE,
(datetime.utcnow() - created_at).total_seconds(),
)
response = self._post_message_request(recipient_number, content, aws_phone_number)

except (botocore.exceptions.ClientError, Exception) as e:
Expand Down
9 changes: 9 additions & 0 deletions app/clients/sms/twilio.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
NOTIFICATION_SENDING,
NOTIFICATION_SENT,
NOTIFICATION_TEMPORARY_FAILURE,
SMS_TYPE,
STATUS_REASON_BLOCKED,
STATUS_REASON_INVALID_NUMBER,
STATUS_REASON_RETRYABLE,
Expand Down Expand Up @@ -185,6 +186,7 @@ def send_sms(
to,
content,
reference,
created_at=datetime.utcnow(),
**kwargs,
) -> str:
"""
Expand Down Expand Up @@ -226,6 +228,13 @@ def send_sms(

self.logger.info('Twilio sender has sms_sender_specifics')

# Log how long it spent in our system before we sent it
self.logger.info(
'Total time spent to send %s notification: %s',
SMS_TYPE,
(datetime.utcnow() - created_at).total_seconds(),
)

if messaging_service_sid is None:
# Make a request using a sender phone number.
message = self._client.messages.create(
Expand Down
7 changes: 7 additions & 0 deletions app/delivery/send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def send_sms_to_provider(
sender=notification.reply_to_text,
service_id=notification.service_id,
sms_sender_id=sms_sender_id,
created_at=notification.created_at,
)
except Exception as e:
notification.billable_units = template.fragment_count
Expand Down Expand Up @@ -150,6 +151,12 @@ def send_email_to_provider(notification: Notification):
else:
email_reply_to = notification.reply_to_text

# Log how long it spent in our system before we sent it
current_app.logger.info(
'Total time spent to send %s notification: %s',
EMAIL_TYPE,
(datetime.utcnow() - notification.created_at).total_seconds(),
)
reference = client.send_email(
source=compute_source_email_address(service, client),
to_addresses=validate_and_format_email_address(notification.to),
Expand Down

0 comments on commit 124115a

Please sign in to comment.