Skip to content

Commit

Permalink
feat: include error message in HaystackError telemetry events(#3543)
Browse files Browse the repository at this point in the history
* Telemetry: add message to all HaystackError(s)

* do not send message for DocumentStoreError and API node errors

* change default payload from None to {}

* add default send_message_in_event to NodeError and type annotations

* black

Co-authored-by: Julian Risch <julian.risch@deepset.ai>
  • Loading branch information
vblagoje and julian-risch authored Nov 10, 2022
1 parent 3319ef6 commit 005025b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
33 changes: 21 additions & 12 deletions haystack/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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


Expand All @@ -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
1 change: 1 addition & 0 deletions haystack/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class NonPrivateParameters:
"uptime",
"run_total",
"run_total_window",
"message",
]

@classmethod
Expand Down

0 comments on commit 005025b

Please sign in to comment.