Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

chore: add asyncio task tracking (#9920)

Kian Jones58f908aa849d
diff --git a/letta/monitoring/event_loop_watchdog.py b/letta/monitoring/event_loop_watchdog.py
index 4e3fccf2e..5ae5b6e1f 100644
--- a/letta/monitoring/event_loop_watchdog.py
+++ b/letta/monitoring/event_loop_watchdog.py
@@ -145,6 +145,12 @@ class EventLoopWatchdog:
except Exception:
pass
+ if task_count >= 0:
+ try:
+ MetricRegistry().asyncio_task_count_gauge.set(task_count)
+ except Exception:
+ pass
+
# ALWAYS log every check to prove watchdog is alive
logger.debug(
f"WATCHDOG_CHECK: heartbeat_age={time_since_heartbeat:.1f}s, current_lag={current_lag:.2f}s, "
diff --git a/letta/otel/metric_registry.py b/letta/otel/metric_registry.py
index 09dd2db48..3e9e35cb3 100644
--- a/letta/otel/metric_registry.py
+++ b/letta/otel/metric_registry.py
@@ -307,6 +307,18 @@ class MetricRegistry:
),
)
+ @property
+ def asyncio_task_count_gauge(self) -> Gauge:
+ return self._get_or_create_metric(
+ "asyncio_task_count",
+ partial(
+ self._meter.create_gauge,
+ name="asyncio_task_count",
+ description="Number of active asyncio tasks on the event loop.",
+ unit="1",
+ ),
+ )
+
# (includes operation)
@property
def redis_timeout_counter(self) -> Counter: