diff --git a/haystack/errors.py b/haystack/errors.py index 9fceb61482..b6fb4a5248 100644 --- a/haystack/errors.py +++ b/haystack/errors.py @@ -12,10 +12,15 @@ class HaystackError(Exception): This error wraps its source transparently in such a way that its attributes can be accessed directly: for example, if the original error has a `message` attribute, `HaystackError.message` will exist and have the expected content. + If send_message_in_event is set to True (default), the message will be sent as part of a telemetry event reporting the error. + The messages of errors that might contain user-specific information will not be sent, e.g., DocumentStoreError or OpenAIError. """ - def __init__(self, message: Optional[str] = None, docs_link: Optional[str] = None): - send_custom_event(event=f"{type(self).__name__} raised") + def __init__( + self, message: Optional[str] = None, docs_link: Optional[str] = None, send_message_in_event: bool = True + ): + payload = {"message": message} if send_message_in_event else {} + send_custom_event(event=f"{type(self).__name__} raised", payload=payload) super().__init__() if message: self.message = message @@ -72,8 +77,8 @@ def __init__( class DocumentStoreError(HaystackError): """Exception for issues that occur in a document store""" - def __init__(self, message: Optional[str] = None): - super().__init__(message=message) + def __init__(self, message: Optional[str] = None, send_message_in_event: bool = False): + super().__init__(message=message, send_message_in_event=send_message_in_event) class FilterError(DocumentStoreError): @@ -100,8 +105,8 @@ def __init__(self, message: Optional[str] = None): class NodeError(HaystackError): """Exception for issues that occur in a node""" - def __init__(self, message: Optional[str] = None): - super().__init__(message=message) + def __init__(self, message: Optional[str] = None, send_message_in_event: bool = True): + super().__init__(message=message, send_message_in_event=send_message_in_event) class AudioNodeError(NodeError): @@ -114,8 +119,10 @@ def __init__(self, message: Optional[str] = None): class OpenAIError(NodeError): """Exception for issues that occur in the OpenAI APIs""" - def __init__(self, message: Optional[str] = None, status_code: Optional[int] = None): - super().__init__(message=message) + def __init__( + self, message: Optional[str] = None, status_code: Optional[int] = None, send_message_in_event: bool = False + ): + super().__init__(message=message, send_message_in_event=send_message_in_event) self.status_code = status_code @@ -126,13 +133,15 @@ class OpenAIRateLimitError(OpenAIError): See https://help.openai.com/en/articles/5955598-is-api-usage-subject-to-any-rate-limits """ - def __init__(self, message: Optional[str] = None): - super().__init__(message=message, status_code=429) + def __init__(self, message: Optional[str] = None, send_message_in_event: bool = False): + super().__init__(message=message, status_code=429, send_message_in_event=send_message_in_event) class CohereError(NodeError): """Exception for issues that occur in the Cohere APIs""" - def __init__(self, message: Optional[str] = None, status_code: Optional[int] = None): - super().__init__(message=message) + def __init__( + self, message: Optional[str] = None, status_code: Optional[int] = None, send_message_in_event: bool = False + ): + super().__init__(message=message, send_message_in_event=send_message_in_event) self.status_code = status_code diff --git a/haystack/telemetry.py b/haystack/telemetry.py index d3abce6416..faf94fb0af 100644 --- a/haystack/telemetry.py +++ b/haystack/telemetry.py @@ -294,6 +294,7 @@ class NonPrivateParameters: "uptime", "run_total", "run_total_window", + "message", ] @classmethod