libinephany 1.1.1__py3-none-any.whl → 1.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,6 +58,8 @@ class ErrorLogger(AsyncioWorker):
58
58
  def __init__(
59
59
  self,
60
60
  service_name: str,
61
+ member_ids_to_mention: list[str] | None = None,
62
+ custom_error_message: str | None = None,
61
63
  minimum_severity: ErrorSeverities = ErrorSeverities.WARNING,
62
64
  error_classifier: ExceptionSeverityClassifier | None = None,
63
65
  max_time_accumulating_errors: float = 10.0,
@@ -66,6 +68,8 @@ class ErrorLogger(AsyncioWorker):
66
68
  """
67
69
  :param service_name: Name of the service deployed on the cloud errors sent to this error logger should be sent
68
70
  to.
71
+ :param member_ids_to_mention: List of member IDs to mention in the Slack message. If None, no members will be mentioned.
72
+ :param custom_error_message: Custom error message to include in the Slack message. If None, no custom message will be included.
69
73
  :param minimum_severity: Minimum error severity that can be sent to Slack.
70
74
  :param error_classifier: Optional callable used to alter how errors severities are classified. If this is None
71
75
  all errors are given the 'WARNING' severity.
@@ -77,6 +81,8 @@ class ErrorLogger(AsyncioWorker):
77
81
 
78
82
  self._slack_client, self._channel_id = self._get_slack_client()
79
83
 
84
+ self.member_mentions = self._form_member_mentions(member_ids_to_mention=member_ids_to_mention)
85
+ self.custom_error_message = custom_error_message
80
86
  self.service_name = service_name
81
87
  self.error_classifier = error_classifier if error_classifier is not None else default_error_classifier
82
88
  self.max_time_accumulating_errors = max_time_accumulating_errors
@@ -144,6 +150,7 @@ class ErrorLogger(AsyncioWorker):
144
150
  exception: Exception,
145
151
  frequency: int,
146
152
  frequency_time_window: float,
153
+ custom_error_message: str | None,
147
154
  ) -> str:
148
155
  """
149
156
  :param mention: Mention tag of the entire channel or a particular user ID.
@@ -152,19 +159,40 @@ class ErrorLogger(AsyncioWorker):
152
159
  :param exception: Exception that occurred.
153
160
  :param frequency: How frequently the exception occurred in the given time window.
154
161
  :param frequency_time_window: Time between the first and last instance of the exception.
162
+ :param custom_error_message: Custom error message to include in the Slack message. If None, no custom message will be included.
155
163
  :return: Formatted Slack message string.
156
164
  """
157
165
 
158
166
  frequency_line = f"{frequency} in {frequency_time_window}s" if frequency > 1 else f"{frequency}"
159
167
 
168
+ header = f"{notification_emoji} *{service_name} Error* {notification_emoji}\n"
169
+
170
+ if mention:
171
+ header += f"• *Alerting*: {mention}\n"
172
+
173
+ if custom_error_message is not None:
174
+ header += f"• *Custom Message*: {custom_error_message}\n"
175
+
160
176
  return (
161
- f"{mention}{notification_emoji} *{service_name} Error* {notification_emoji}\n"
177
+ f"{header}"
162
178
  f"• *Service*: {service_name}\n"
163
179
  f"• *Error Type*: {exception.__class__.__name__}\n"
164
180
  f"• *Frequency*: {frequency_line}\n"
165
181
  f"• *Traceback*: "
166
182
  )
167
183
 
184
+ @staticmethod
185
+ def _form_member_mentions(member_ids_to_mention: list[str] | None) -> str:
186
+ """
187
+ :param member_ids_to_mention: List of member IDs to mention in the Slack message.
188
+ :return: String of member mentions.
189
+ """
190
+
191
+ if not member_ids_to_mention:
192
+ return ""
193
+
194
+ return " ".join([f"<@{member_id}>" for member_id in member_ids_to_mention])
195
+
168
196
  def _get_traceback_file_name(self, exception: Exception, exception_timestamp: str) -> str:
169
197
  """
170
198
  :param exception: Exception being sent to Slack.
@@ -275,7 +303,10 @@ class ErrorLogger(AsyncioWorker):
275
303
  traceback_filename = self._get_traceback_file_name(exception=exception, exception_timestamp=formatted_timestamp)
276
304
 
277
305
  notification_emoji = SEVERITY_EMOJIS[severity]
278
- mention = "" if not ErrorSeverities.should_mention(severity=severity) else self.CHANNEL_MENTION
306
+ # Temporary since the bot is used in training and the API.
307
+ mention = (
308
+ self.member_mentions if not ErrorSeverities.should_mention(severity=severity) else self.CHANNEL_MENTION
309
+ )
279
310
 
280
311
  self._log_error_to_terminal(exception=exception)
281
312
 
@@ -291,6 +322,7 @@ class ErrorLogger(AsyncioWorker):
291
322
  exception=exception,
292
323
  frequency=frequency,
293
324
  frequency_time_window=frequency_time_window,
325
+ custom_error_message=self.custom_error_message,
294
326
  ),
295
327
  )
296
328
  except SlackApiError as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libinephany
3
- Version: 1.1.1
3
+ Version: 1.1.2
4
4
  Summary: Inephany library containing code commonly used by multiple subpackages.
5
5
  Author-email: Inephany <info@inephany.com>
6
6
  License: Apache 2.0
@@ -55,10 +55,10 @@ libinephany/utils/torch_utils.py,sha256=o5TsqrXe6Id04P6SqB_avGBRZutbu6IBB61llAHQ
55
55
  libinephany/utils/transforms.py,sha256=Ca4pbCs_FbCpXb8M8oPxrP5QOqOAwGSdGpKzy5YUubc,3503
56
56
  libinephany/utils/typing.py,sha256=rGbaPO3MaUndsWiC_wHzReD_TOLYqb43i01pKN-j7Xs,624
57
57
  libinephany/web_apps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
- libinephany/web_apps/error_logger.py,sha256=gAQIaqerqP4ornXZwFF1cghjnd2mMZEt3aVrTuUCr34,16653
58
+ libinephany/web_apps/error_logger.py,sha256=QpspO726Uoyyr6lBEEb3Q9XqhVOXUM4AaYE7vbnk31c,18153
59
59
  libinephany/web_apps/web_app_utils.py,sha256=qiq_lasPipgN1RgRudPJc342kYci8O_4RqppxmIX8NY,4095
60
- libinephany-1.1.1.dist-info/licenses/LICENSE,sha256=pogfDoMBP07ehIOvWymuWIar8pg2YLUhqOHsJQU3wdc,9250
61
- libinephany-1.1.1.dist-info/METADATA,sha256=Tuhz8AcpTpOjIu4XuUd7dJsI8874RRP3RWn4OlpK-Sc,8389
62
- libinephany-1.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
63
- libinephany-1.1.1.dist-info/top_level.txt,sha256=bYAOXQdJgIoLkO2Ui0kxe7pSYegS_e38u0dMscd7COQ,12
64
- libinephany-1.1.1.dist-info/RECORD,,
60
+ libinephany-1.1.2.dist-info/licenses/LICENSE,sha256=pogfDoMBP07ehIOvWymuWIar8pg2YLUhqOHsJQU3wdc,9250
61
+ libinephany-1.1.2.dist-info/METADATA,sha256=4wogF1PgydPU-kNDC5ijjAMbTM7TT_bRRPODhHsNe88,8389
62
+ libinephany-1.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
63
+ libinephany-1.1.2.dist-info/top_level.txt,sha256=bYAOXQdJgIoLkO2Ui0kxe7pSYegS_e38u0dMscd7COQ,12
64
+ libinephany-1.1.2.dist-info/RECORD,,