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 duplicate promethues metrics

Swifty7b93600973dd
diff --git a/autogpt_platform/backend/backend/monitoring/instrumentation.py b/autogpt_platform/backend/backend/monitoring/instrumentation.py
index 898324deaa..bd384b4ad2 100644
--- a/autogpt_platform/backend/backend/monitoring/instrumentation.py
+++ b/autogpt_platform/backend/backend/monitoring/instrumentation.py
@@ -143,6 +143,9 @@ def instrument_fastapi(
)
# Create instrumentator with default metrics
+ # Use service-specific inprogress_name to avoid duplicate registration
+ # when multiple FastAPI apps are instrumented in the same process
+ service_subsystem = service_name.replace("-", "_")
instrumentator = Instrumentator(
should_group_status_codes=True,
should_ignore_untemplated=True,
@@ -150,7 +153,7 @@ def instrument_fastapi(
should_instrument_requests_inprogress=True,
excluded_handlers=excluded_handlers or ["/health", "/readiness"],
env_var_name="ENABLE_METRICS",
- inprogress_name="autogpt_http_requests_inprogress",
+ inprogress_name=f"autogpt_{service_subsystem}_http_requests_inprogress",
inprogress_labels=True,
)