Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(flags): log find_flags_with_enriched_analytics failures (#71632)

Phil Haackf08f410617fd
diff --git a/posthog/tasks/tasks.py b/posthog/tasks/tasks.py
index f8c62ae029b0..47a3e893c151 100644
--- a/posthog/tasks/tasks.py
+++ b/posthog/tasks/tasks.py
@@ -945,7 +945,14 @@ def find_flags_with_enriched_analytics() -> None:
end = datetime.now()
begin = end - timedelta(hours=12)
- find_flags_with_enriched_analytics(begin, end)
+ try:
+ find_flags_with_enriched_analytics(begin, end)
+ except Exception as e:
+ logger.exception("Find flags with enriched analytics failed", error=e)
+ capture_exception(
+ e, additional_properties={"feature": "feature_flags", "task": "find_flags_with_enriched_analytics"}
+ )
+ raise
@shared_task(ignore_result=True)
diff --git a/posthog/test/test_feature_flag_analytics.py b/posthog/test/test_feature_flag_analytics.py
index f1b8818fbe6e..2eabe3b326e1 100644
--- a/posthog/test/test_feature_flag_analytics.py
+++ b/posthog/test/test_feature_flag_analytics.py
@@ -20,6 +20,7 @@ from django.core.cache import cache
from posthog import redis
from posthog.constants import FlagRequestType
from posthog.models.team.team import Team
+from posthog.tasks.tasks import find_flags_with_enriched_analytics as find_flags_with_enriched_analytics_task
from products.feature_flags.backend.api.feature_flag import _create_usage_dashboard
from products.feature_flags.backend.flag_analytics import (
@@ -1035,6 +1036,17 @@ class TestEnrichedAnalytics(BaseTest):
self.assertEqual(f1.usage_dashboard, None)
+class TestFindFlagsWithEnrichedAnalyticsTask(BaseTest):
+ @patch("products.feature_flags.backend.flag_analytics.find_flags_with_enriched_analytics")
+ def test_logs_and_reraises_on_failure(self, mock_find_flags: MagicMock) -> None:
+ mock_find_flags.side_effect = Exception("boom")
+
+ with patch("posthog.tasks.tasks.capture_exception") as mock_capture, self.assertRaises(Exception):
+ find_flags_with_enriched_analytics_task()
+
+ mock_capture.assert_called_once()
+
+
class TestCrossProjectEvaluations(ClickhouseTestMixin, APIBaseTest):
def test_returns_zero_when_no_events(self):
counts = get_evaluations_7d_by_team("some_key", [self.team.id])