mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-09-26 08:33:51 +00:00
feat: include error message in HaystackError telemetry events(#3543)
* 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>
This commit is contained in:
parent
3319ef6d1c
commit
005025bd14
@ -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 @@ class PipelineConfigError(PipelineError):
|
||||
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 @@ class DuplicateDocumentError(DocumentStoreError, ValueError):
|
||||
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 @@ class AudioNodeError(NodeError):
|
||||
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
|
||||
|
@ -294,6 +294,7 @@ class NonPrivateParameters:
|
||||
"uptime",
|
||||
"run_total",
|
||||
"run_total_window",
|
||||
"message",
|
||||
]
|
||||
|
||||
@classmethod
|
||||
|
Loading…
x
Reference in New Issue
Block a user