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.
feat(backend): instrument prometheus for internal services (#11114)
Zamil Majdyf3900127d7e7
diff --git a/autogpt_platform/backend/backend/util/service.py b/autogpt_platform/backend/backend/util/service.pyindex 1cbdf2ecf4..2f580fe49e 100644--- a/autogpt_platform/backend/backend/util/service.py+++ b/autogpt_platform/backend/backend/util/service.py@@ -28,6 +28,7 @@ from fastapi import FastAPI, Request, responsesfrom pydantic import BaseModel, TypeAdapter, create_modelimport backend.util.exceptions as exceptions+from backend.monitoring.instrumentation import instrument_fastapifrom backend.util.json import to_dictfrom backend.util.metrics import sentry_initfrom backend.util.process import AppProcess, get_service_name@@ -283,6 +284,24 @@ class AppService(BaseAppService, ABC):super().run()self.fastapi_app = FastAPI()+ # Add Prometheus instrumentation to all services+ try:+ instrument_fastapi(+ self.fastapi_app,+ service_name=self.service_name,+ expose_endpoint=True,+ endpoint="/metrics",+ include_in_schema=False,+ )+ except ImportError:+ logger.warning(+ f"Prometheus instrumentation not available for {self.service_name}"+ )+ except Exception as e:+ logger.error(+ f"Failed to instrument {self.service_name} with Prometheus: {e}"+ )+# Register the exposed API routes.for attr_name, attr in vars(type(self)).items():if getattr(attr, EXPOSED_FLAG, False):