: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(llma): add evaluation runtime counts (#66332)
Radu Raicea0ff22118496c
diff --git a/posthog/tasks/ai_observability_usage_report.py b/posthog/tasks/ai_observability_usage_report.pyindex 7eb8739d85e0..504f02b8aedd 100644--- a/posthog/tasks/ai_observability_usage_report.py+++ b/posthog/tasks/ai_observability_usage_report.py@@ -78,6 +78,9 @@ class TeamMetrics:ai_evaluation_count: int = 0ai_is_error_count: int = 0ai_trial_evaluation_count: int = 0+ ai_llm_judge_evaluation_count: int = 0+ ai_hog_evaluation_count: int = 0+ ai_sentiment_evaluation_count: int = 0ai_trace_summary_count: int = 0ai_generation_summary_count: int = 0ai_trace_clusters_count: int = 0@@ -326,6 +329,11 @@ def _combine_all_metrics_results(results_list: list) -> dict[int, TeamMetrics]:# Trial evaluation count (index 27)metrics.ai_trial_evaluation_count += row[27] or 0+ # Evaluation runtime counts (indices 28-30)+ metrics.ai_llm_judge_evaluation_count += row[28] or 0+ metrics.ai_hog_evaluation_count += row[29] or 0+ metrics.ai_sentiment_evaluation_count += row[30] or 0+return team_metrics@@ -380,7 +388,11 @@ def get_all_ai_metrics(countIf(toFloat64OrNull(properties_group_ai['$ai_total_cost_usd']) = 0) as total_cost_zero_count,-- Error countcountIf(properties_group_ai['$ai_is_error'] = 'true') as ai_is_error_count,- countIf(event = '$ai_evaluation' AND properties_group_ai['$ai_evaluation_key_type'] = 'posthog') as ai_trial_evaluation_count+ -- Evaluation counts+ countIf(event = '$ai_evaluation' AND properties_group_ai['$ai_evaluation_key_type'] = 'posthog') as ai_trial_evaluation_count,+ countIf(event = '$ai_evaluation' AND properties_group_ai['$ai_evaluation_runtime'] = 'llm_judge') as ai_llm_judge_evaluation_count,+ countIf(event = '$ai_evaluation' AND properties_group_ai['$ai_evaluation_runtime'] = 'hog') as ai_hog_evaluation_count,+ countIf(event = '$ai_evaluation' AND properties_group_ai['$ai_evaluation_runtime'] = 'sentiment') as ai_sentiment_evaluation_countFROM eventsWHERE team_id IN %(team_ids)sAND event IN %(ai_events)s@@ -758,6 +770,9 @@ def _get_all_ai_observability_reports("ai_evaluation_count": 0,"ai_is_error_count": 0,"ai_trial_evaluation_count": 0,+ "ai_llm_judge_evaluation_count": 0,+ "ai_hog_evaluation_count": 0,+ "ai_sentiment_evaluation_count": 0,"ai_trace_summary_count": 0,"ai_generation_summary_count": 0,"ai_trace_clusters_count": 0,@@ -803,6 +818,9 @@ def _get_all_ai_observability_reports(report["ai_evaluation_count"] += metrics.ai_evaluation_countreport["ai_is_error_count"] += metrics.ai_is_error_countreport["ai_trial_evaluation_count"] += metrics.ai_trial_evaluation_count+ report["ai_llm_judge_evaluation_count"] += metrics.ai_llm_judge_evaluation_count+ report["ai_hog_evaluation_count"] += metrics.ai_hog_evaluation_count+ report["ai_sentiment_evaluation_count"] += metrics.ai_sentiment_evaluation_countreport["ai_trace_summary_count"] += metrics.ai_trace_summary_countreport["ai_generation_summary_count"] += metrics.ai_generation_summary_countreport["ai_trace_clusters_count"] += metrics.ai_trace_clusters_countdiff --git a/posthog/tasks/test/test_ai_observability_usage_report.py b/posthog/tasks/test/test_ai_observability_usage_report.pyindex e7f1e62c7a6b..e320f58d17a6 100644--- a/posthog/tasks/test/test_ai_observability_usage_report.py+++ b/posthog/tasks/test/test_ai_observability_usage_report.py@@ -91,12 +91,18 @@ class TestAIObservabilityUsageReport(APIBaseTest, ClickhouseTestMixin, Clickhousself._create_ai_events(self.team, distinct_id, "$ai_metric", 1)self._create_ai_events(self.team, distinct_id, "$ai_feedback", 4)self._create_ai_events(- self.team, distinct_id, "$ai_evaluation", 3, properties={"$ai_evaluation_key_type": "posthog"}+ self.team,+ distinct_id,+ "$ai_evaluation",+ 3,+ properties={"$ai_evaluation_key_type": "posthog", "$ai_evaluation_runtime": "llm_judge"},)self._create_ai_events(- self.team, distinct_id, "$ai_evaluation", 2, properties={"$ai_evaluation_key_type": "byok"}+ self.team, distinct_id, "$ai_evaluation", 2, properties={"$ai_evaluation_runtime": "hog"}+ )+ self._create_ai_events(+ self.team, distinct_id, "$ai_evaluation", 1, properties={"$ai_evaluation_runtime": "sentiment"})- self._create_ai_events(self.team, distinct_id, "$ai_evaluation", 1)self._create_ai_events(self.team, distinct_id, "$ai_trace_summary", 7)self._create_ai_events(self.team, distinct_id, "$ai_generation_summary", 12)self._create_ai_events(self.team, distinct_id, "$ai_trace_clusters", 2)@@ -141,6 +147,9 @@ class TestAIObservabilityUsageReport(APIBaseTest, ClickhouseTestMixin, Clickhousassert metrics.ai_feedback_count == 4assert metrics.ai_evaluation_count == 6assert metrics.ai_trial_evaluation_count == 3+ assert metrics.ai_llm_judge_evaluation_count == 3+ assert metrics.ai_hog_evaluation_count == 2+ assert metrics.ai_sentiment_evaluation_count == 1assert metrics.ai_trace_summary_count == 7assert metrics.ai_generation_summary_count == 12assert metrics.ai_trace_clusters_count == 2@@ -483,10 +492,17 @@ class TestAIObservabilityUsageReport(APIBaseTest, ClickhouseTestMixin, Clickhous# Create comprehensive AI events for team 1self._create_ai_events(self.team, distinct_id_1, "$ai_generation", 10)self._create_ai_events(- self.team, distinct_id_1, "$ai_evaluation", 3, properties={"$ai_evaluation_key_type": "posthog"}+ self.team,+ distinct_id_1,+ "$ai_evaluation",+ 3,+ properties={"$ai_evaluation_key_type": "posthog", "$ai_evaluation_runtime": "llm_judge"},+ )+ self._create_ai_events(+ self.team, distinct_id_1, "$ai_evaluation", 1, properties={"$ai_evaluation_runtime": "hog"})self._create_ai_events(- self.team, distinct_id_1, "$ai_evaluation", 2, properties={"$ai_evaluation_key_type": "byok"}+ self.team, distinct_id_1, "$ai_evaluation", 1, properties={"$ai_evaluation_runtime": "sentiment"})self._create_ai_events(self.team,@@ -558,6 +574,9 @@ class TestAIObservabilityUsageReport(APIBaseTest, ClickhouseTestMixin, Clickhousassert org_1_report["ai_generation_count"] == 13 # 10 + 3assert org_1_report["ai_evaluation_count"] == 5assert org_1_report["ai_trial_evaluation_count"] == 3+ assert org_1_report["ai_llm_judge_evaluation_count"] == 3+ assert org_1_report["ai_hog_evaluation_count"] == 1+ assert org_1_report["ai_sentiment_evaluation_count"] == 1assert org_1_report["ai_trace_summary_count"] == 6assert org_1_report["ai_generation_summary_count"] == 8assert org_1_report["ai_trace_clusters_count"] == 1@@ -589,6 +608,9 @@ class TestAIObservabilityUsageReport(APIBaseTest, ClickhouseTestMixin, Clickhousassert org_2_report["organization_name"] == org_2.nameassert org_2_report["ai_embedding_count"] == 7assert org_2_report["ai_generation_count"] == 2+ assert org_2_report["ai_llm_judge_evaluation_count"] == 0+ assert org_2_report["ai_hog_evaluation_count"] == 0+ assert org_2_report["ai_sentiment_evaluation_count"] == 0assert org_2_report["llm_prompt_fetched_count"] == 1assert org_2_report["total_ai_cost_usd"] == pytest.approx(0.050, rel=1e-6) # 2 * 0.025assert org_2_report["ai_trace_summary_count"] == 0@@ -664,6 +686,9 @@ class TestAIObservabilityUsageReport(APIBaseTest, ClickhouseTestMixin, Clickhousassert org_report["ai_metric_count"] == 0assert org_report["ai_feedback_count"] == 0assert org_report["ai_evaluation_count"] == 0+ assert org_report["ai_llm_judge_evaluation_count"] == 0+ assert org_report["ai_hog_evaluation_count"] == 0+ assert org_report["ai_sentiment_evaluation_count"] == 0assert org_report["ai_trace_summary_count"] == 0assert org_report["ai_generation_summary_count"] == 0assert org_report["ai_trace_clusters_count"] == 0@@ -686,10 +711,14 @@ class TestAIObservabilityUsageReport(APIBaseTest, ClickhouseTestMixin, Clickhousself._create_ai_events(self.team, distinct_id_1, "$ai_generation", 10)self._create_ai_events(team_2, distinct_id_2, "$ai_generation", 5)self._create_ai_events(- self.team, distinct_id_1, "$ai_evaluation", 3, properties={"$ai_evaluation_key_type": "posthog"}+ self.team,+ distinct_id_1,+ "$ai_evaluation",+ 3,+ properties={"$ai_evaluation_key_type": "posthog", "$ai_evaluation_runtime": "llm_judge"},)self._create_ai_events(- team_2, distinct_id_2, "$ai_evaluation", 2, properties={"$ai_evaluation_key_type": "posthog"}+ team_2, distinct_id_2, "$ai_evaluation", 2, properties={"$ai_evaluation_runtime": "sentiment"})# Generate reports@@ -702,7 +731,10 @@ class TestAIObservabilityUsageReport(APIBaseTest, ClickhouseTestMixin, Clickhous# Counts should be aggregated across both teamsassert org_report["ai_generation_count"] == 15 # 10 + 5assert org_report["ai_evaluation_count"] == 5 # 3 + 2- assert org_report["ai_trial_evaluation_count"] == 5 # 3 + 2+ assert org_report["ai_trial_evaluation_count"] == 3+ assert org_report["ai_llm_judge_evaluation_count"] == 3+ assert org_report["ai_hog_evaluation_count"] == 0+ assert org_report["ai_sentiment_evaluation_count"] == 2def test_dimension_breakdown_aggregation_across_teams(self) -> None:"""Test that dimension breakdowns are correctly aggregated across teams in the same org."""