diff --git a/src/seer/anomaly_detection/anomaly_detection.py b/src/seer/anomaly_detection/anomaly_detection.py index 0417ef453..61a5f90ef 100644 --- a/src/seer/anomaly_detection/anomaly_detection.py +++ b/src/seer/anomaly_detection/anomaly_detection.py @@ -253,7 +253,9 @@ def store_data( "minimum_required": min_len, }, ) - raise Exception(f"Insufficient time series data for alert {request.alert.id}") + return StoreDataResponse( + success=False, message=f"Insufficient time series data for alert {request.alert.id}" + ) logger.info( "store_alert_request", @@ -264,14 +266,29 @@ def store_data( "num_datapoints": len(request.timeseries), }, ) - ts, anomalies = self._batch_detect(request.timeseries, request.config) - alert_data_accessor.save_alert( - organization_id=request.organization_id, - project_id=request.project_id, - external_alert_id=request.alert.id, - config=request.config, - timeseries=ts, - anomalies=anomalies, - anomaly_algo_data={"window_size": anomalies.window_size}, - ) - return StoreDataResponse(success=True) + try: + ts, anomalies = self._batch_detect(request.timeseries, request.config) + alert_data_accessor.save_alert( + organization_id=request.organization_id, + project_id=request.project_id, + external_alert_id=request.alert.id, + config=request.config, + timeseries=ts, + anomalies=anomalies, + anomaly_algo_data={"window_size": anomalies.window_size}, + ) + return StoreDataResponse(success=True) + except Exception as e: + sentry_sdk.capture_exception(e) + logger.error( + "error_saving_alert", + extra={ + "organization_id": request.organization_id, + "project_id": request.project_id, + "external_alert_id": request.alert.id, + "num_datapoints": len(request.timeseries), + "minimum_required": min_len, + }, + exc_info=e, + ) + return StoreDataResponse(success=False, message=str(e)) diff --git a/src/seer/anomaly_detection/models/external.py b/src/seer/anomaly_detection/models/external.py index 30cd553d3..5c224aeca 100644 --- a/src/seer/anomaly_detection/models/external.py +++ b/src/seer/anomaly_detection/models/external.py @@ -85,3 +85,4 @@ class StoreDataRequest(BaseModel): class StoreDataResponse(BaseModel): success: bool + message: Optional[str] = Field(None)