Skip to content

Commit 6f953bb

Browse files
committed
SmsClient: Merge succeeded/failed log messages into finished message
We capture these messages at exactly the same time, down to the millisecond, but only annotate the "finished" message with notification_id and duration. Let's just merge them all together into a single message capturing everything.
1 parent 9b8581d commit 6f953bb

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

app/clients/sms/__init__.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,40 +47,30 @@ def __init__(self, current_app, statsd_client):
4747

4848
def send_sms(self, to, content, reference, international, sender):
4949
start_time = monotonic()
50+
status = "succeeded"
5051

5152
try:
5253
response = self.try_send_sms(to, content, reference, international, sender)
53-
self.current_app.logger.info(
54-
"Provider request for %s succeeded",
55-
self.name,
56-
extra={
57-
"provider_name": self.name,
58-
},
59-
)
6054
self.statsd_client.incr(f"clients.{self.name}.success")
6155
except SmsClientResponseException as e:
56+
status = "failed"
6257
self.statsd_client.incr(f"clients.{self.name}.error")
63-
self.current_app.logger.warning(
64-
"Provider request for %s failed",
65-
self.name,
66-
extra={
67-
"provider_name": self.name,
68-
},
69-
)
7058
raise e
7159
finally:
7260
elapsed_time = monotonic() - start_time
7361
self.statsd_client.timing(f"clients.{self.name}.request-time", elapsed_time)
7462
self.current_app.logger.info(
75-
"%s request for %s finished in %.4g",
63+
"Provider %s request for %s %s in %.4g",
7664
self.name,
7765
reference,
66+
status,
7867
elapsed_time,
7968
extra={
8069
"provider_name": self.name,
8170
# for SMS, we happen to use the notification id as the "reference" for the provider
8271
"notification_id": reference,
8372
"duration": elapsed_time,
73+
"status": status,
8474
},
8575
)
8676

0 commit comments

Comments
 (0)