Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend): Report process errors to Sentry before cleanup (#10873)

Nicholas Tindledc03ea718cc6
diff --git a/autogpt_platform/backend/backend/util/metrics.py b/autogpt_platform/backend/backend/util/metrics.py
index ff92537d4e..2fb0d53e7a 100644
--- a/autogpt_platform/backend/backend/util/metrics.py
+++ b/autogpt_platform/backend/backend/util/metrics.py
@@ -33,7 +33,7 @@ def sentry_init():
)
-def sentry_capture_error(error: Exception):
+def sentry_capture_error(error: BaseException):
sentry_sdk.capture_exception(error)
sentry_sdk.flush()
diff --git a/autogpt_platform/backend/backend/util/process.py b/autogpt_platform/backend/backend/util/process.py
index 4e37f960d8..d345d2d0f4 100644
--- a/autogpt_platform/backend/backend/util/process.py
+++ b/autogpt_platform/backend/backend/util/process.py
@@ -76,6 +76,14 @@ class AppProcess(ABC):
logger.warning(
f"[{self.service_name}] Termination request: {type(e).__name__}; {e} executing cleanup."
)
+ # Send error to Sentry before cleanup
+ if not isinstance(e, (KeyboardInterrupt, SystemExit)):
+ try:
+ from backend.util.metrics import sentry_capture_error
+
+ sentry_capture_error(e)
+ except Exception:
+ pass # Silently ignore if Sentry isn't available
finally:
self.cleanup()
logger.info(f"[{self.service_name}] Terminated.")