: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
fix(usage-report): count group events with billable event exclusions (#114079)
Mike Warrenbd87feb88903
diff --git a/posthog/tasks/test/__snapshots__/test_usage_report.ambr b/posthog/tasks/test/__snapshots__/test_usage_report.ambrindex 876d0d71f60e..dbf4a52f00ed 100644--- a/posthog/tasks/test/__snapshots__/test_usage_report.ambr+++ b/posthog/tasks/test/__snapshots__/test_usage_report.ambr@@ -1070,10 +1070,12 @@'''SELECT team_id,- count(1) as count+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM eventsWHERE timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59'+ AND timestamp < '2022-01-10 02:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')AND ($group_0 != ''OR $group_1 != ''OR $group_2 != ''@@ -1086,10 +1088,17 @@'''SELECT team_id,- count() as count- FROM heatmaps- WHERE timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59'+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 02:00:00'+ AND timestamp < '2022-01-10 04:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')GROUP BY team_id'''# ---@@ -1097,22 +1106,17 @@'''SELECT team_id,- count(distinct session_id) as count- FROM- (SELECT any(team_id) as team_id,- session_id- FROM session_replay_events- WHERE min_first_timestamp >= '2022-01-10 00:00:00'- AND min_first_timestamp < '2022-01-10 23:59:59'- GROUP BY session_id- HAVING (ifNull(argMinMerge(snapshot_source), 'web') == 'mobile') == 0- AND max(is_deleted) = 0)- WHERE session_id NOT IN- (SELECT DISTINCT session_id- FROM session_replay_events- WHERE min_first_timestamp >= '2022-01-09 00:00:00'- AND min_first_timestamp < '2022-01-10 00:00:00'- GROUP BY session_id)+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 04:00:00'+ AND timestamp < '2022-01-10 06:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')GROUP BY team_id'''# ---@@ -1159,6 +1163,242 @@# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.60'''+ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 06:00:00'+ AND timestamp < '2022-01-10 08:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.61+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 08:00:00'+ AND timestamp < '2022-01-10 10:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.62+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 10:00:00'+ AND timestamp < '2022-01-10 12:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.63+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 12:00:00'+ AND timestamp < '2022-01-10 14:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.64+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 14:00:00'+ AND timestamp < '2022-01-10 16:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.65+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 16:00:00'+ AND timestamp < '2022-01-10 18:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.66+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 18:00:00'+ AND timestamp < '2022-01-10 20:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.67+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 20:00:00'+ AND timestamp < '2022-01-10 22:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.68+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events+ WHERE timestamp >= '2022-01-10 22:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND ($group_0 != ''+ OR $group_1 != ''+ OR $group_2 != ''+ OR $group_3 != ''+ OR $group_4 != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.69+ '''++ SELECT team_id,+ count() as count+ FROM heatmaps+ WHERE timestamp >= '2022-01-10 00:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.7+ '''++ SELECT team_id,+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,+ count(1) as count+ FROM events PREWHERE timestamp >= '2022-01-10 14:00:00'+ AND timestamp < '2022-01-10 16:00:00'+ WHERE (event LIKE 'helicone%'+ OR event LIKE 'langfuse%'+ OR event LIKE 'keywords_ai%'+ OR event LIKE 'traceloop%'+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',+ 'js',+ 'posthog-node',+ 'posthog-node-mcp',+ 'posthog-python-mcp',+ 'posthog-edge',+ 'posthog-convex',+ 'posthog-android',+ 'posthog-kmp',+ 'posthog-flutter',+ 'posthog-ios',+ 'posthog-go',+ 'posthog-java',+ 'posthog-server',+ 'posthog-react-native',+ 'posthog-ruby',+ 'posthog-rails',+ 'posthog-python',+ 'posthog-php',+ 'posthog-dotnet',+ 'posthog-aspnetcore',+ 'posthog-elixir',+ 'posthog-unity',+ 'posthog-rs'))+ GROUP BY team_id,+ metric+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.70+ '''++ SELECT team_id,+ count(distinct session_id) as count+ FROM+ (SELECT any(team_id) as team_id,+ session_id+ FROM session_replay_events+ WHERE min_first_timestamp >= '2022-01-10 00:00:00'+ AND min_first_timestamp < '2022-01-10 23:59:59'+ GROUP BY session_id+ HAVING (ifNull(argMinMerge(snapshot_source), 'web') == 'mobile') == 0+ AND max(is_deleted) = 0)+ WHERE session_id NOT IN+ (SELECT DISTINCT session_id+ FROM session_replay_events+ WHERE min_first_timestamp >= '2022-01-09 00:00:00'+ AND min_first_timestamp < '2022-01-10 00:00:00'+ GROUP BY session_id)+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.71+ '''+SELECT team_id,count(distinct session_id) as countFROM@@ -1179,7 +1419,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.61+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.72'''SELECT team_id,@@ -1203,7 +1443,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.62+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.73'''SELECT team_id,@@ -1226,7 +1466,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.63+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.74'''SELECT team_id,@@ -1250,7 +1490,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.64+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.75'''SELECT team_id,@@ -1273,7 +1513,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.65+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.76'''SELECT distinct_id as team,@@ -1287,7 +1527,7 @@GROUP BY team'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.66+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.77'''SELECT distinct_id as team,@@ -1301,7 +1541,7 @@GROUP BY team'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.67+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.78'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1320,7 +1560,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.68+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.79'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1339,33 +1579,14 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.69- '''- WITH JSONExtractInt(log_comment, 'team_id') as team_id,- JSONExtractString(log_comment, 'query_type') as query_type,- JSONExtractString(log_comment, 'access_method') as access_method- SELECT team_id,- sum(query_duration_ms) as count- FROM clusterAllReplicas(posthog, system.query_log)- WHERE (type = 'QueryFinish'- OR type = 'ExceptionWhileProcessing')- AND is_initial_query = 1- AND event_time >= 'today 00:00:00'- AND event_time < '2022-01-11 05:59:59'- AND query_start_time >= '2022-01-10 00:00:00'- AND query_start_time < '2022-01-10 23:59:59'- AND access_method = ''- GROUP BY team_id- '''-# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.7+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.8'''SELECT team_id,multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,count(1) as count- FROM events PREWHERE timestamp >= '2022-01-10 14:00:00'- AND timestamp < '2022-01-10 16:00:00'+ FROM events PREWHERE timestamp >= '2022-01-10 16:00:00'+ AND timestamp < '2022-01-10 18:00:00'WHERE (event LIKE 'helicone%'OR event LIKE 'langfuse%'OR event LIKE 'keywords_ai%'@@ -1398,7 +1619,26 @@metric'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.70+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.80+ '''+ WITH JSONExtractInt(log_comment, 'team_id') as team_id,+ JSONExtractString(log_comment, 'query_type') as query_type,+ JSONExtractString(log_comment, 'access_method') as access_method+ SELECT team_id,+ sum(query_duration_ms) as count+ FROM clusterAllReplicas(posthog, system.query_log)+ WHERE (type = 'QueryFinish'+ OR type = 'ExceptionWhileProcessing')+ AND is_initial_query = 1+ AND event_time >= 'today 00:00:00'+ AND event_time < '2022-01-11 05:59:59'+ AND query_start_time >= '2022-01-10 00:00:00'+ AND query_start_time < '2022-01-10 23:59:59'+ AND access_method = ''+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.81'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1417,7 +1657,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.71+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.82'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1436,7 +1676,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.72+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.83'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1455,7 +1695,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.73+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.84'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1475,7 +1715,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.74+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.85'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1495,7 +1735,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.75+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.86'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1515,7 +1755,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.76+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.87'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1535,7 +1775,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.77+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.88'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1555,7 +1795,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.78+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.89'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1575,38 +1815,14 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.79- '''-- SELECT team_id,- COUNT() as count- FROM events- WHERE event = 'survey sent'- AND timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59'- AND uuid IN- (SELECT argMax(uuid, timestamp)- FROM events- WHERE timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59'- AND event = 'survey sent'- GROUP BY team_id,- replaceRegexpAll(JSONExtractRaw(properties, '$survey_id'), '^"|"$', ''),- CASE- WHEN COALESCE(replaceRegexpAll(JSONExtractRaw(properties, '$survey_submission_id'), '^"|"$', ''), '') = '' THEN toString(uuid)- ELSE replaceRegexpAll(JSONExtractRaw(properties, '$survey_submission_id'), '^"|"$', '')- END)- GROUP BY team_id- '''-# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.8+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.9'''SELECT team_id,multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,count(1) as count- FROM events PREWHERE timestamp >= '2022-01-10 16:00:00'- AND timestamp < '2022-01-10 18:00:00'+ FROM events PREWHERE timestamp >= '2022-01-10 18:00:00'+ AND timestamp < '2022-01-10 20:00:00'WHERE (event LIKE 'helicone%'OR event LIKE 'langfuse%'OR event LIKE 'keywords_ai%'@@ -1639,7 +1855,31 @@metric'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.80+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.90+ '''++ SELECT team_id,+ COUNT() as count+ FROM events+ WHERE event = 'survey sent'+ AND timestamp >= '2022-01-10 00:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ AND uuid IN+ (SELECT argMax(uuid, timestamp)+ FROM events+ WHERE timestamp >= '2022-01-10 00:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ AND event = 'survey sent'+ GROUP BY team_id,+ replaceRegexpAll(JSONExtractRaw(properties, '$survey_id'), '^"|"$', ''),+ CASE+ WHEN COALESCE(replaceRegexpAll(JSONExtractRaw(properties, '$survey_submission_id'), '^"|"$', ''), '') = '' THEN toString(uuid)+ ELSE replaceRegexpAll(JSONExtractRaw(properties, '$survey_submission_id'), '^"|"$', '')+ END)+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.91'''SELECT team_id,@@ -1654,7 +1894,7 @@metric_name'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.81+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.92'''SELECT team_id,@@ -1668,7 +1908,7 @@metric_name'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.82+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.93'''SELECT team_id,@@ -1681,7 +1921,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.83+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.94'''SELECT team_id,@@ -1703,7 +1943,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.84+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.95'''SELECT team_id,@@ -1717,7 +1957,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.85+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.96'''SELECT team_id,@@ -1731,7 +1971,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.86+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.97'''SELECT team_id,@@ -1745,7 +1985,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.87+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.98'''SELECT team_id,@@ -1760,7 +2000,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.88+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.99'''SELECT team_id,@@ -1773,43 +2013,3 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.9- '''-- SELECT team_id,- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,- count(1) as count- FROM events PREWHERE timestamp >= '2022-01-10 18:00:00'- AND timestamp < '2022-01-10 20:00:00'- WHERE (event LIKE 'helicone%'- OR event LIKE 'langfuse%'- OR event LIKE 'keywords_ai%'- OR event LIKE 'traceloop%'- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',- 'js',- 'posthog-node',- 'posthog-node-mcp',- 'posthog-python-mcp',- 'posthog-edge',- 'posthog-convex',- 'posthog-android',- 'posthog-kmp',- 'posthog-flutter',- 'posthog-ios',- 'posthog-go',- 'posthog-java',- 'posthog-server',- 'posthog-react-native',- 'posthog-ruby',- 'posthog-rails',- 'posthog-python',- 'posthog-php',- 'posthog-dotnet',- 'posthog-aspnetcore',- 'posthog-elixir',- 'posthog-unity',- 'posthog-rs'))- GROUP BY team_id,- metric- '''-# ---diff --git a/posthog/tasks/test/__snapshots__/test_usage_report.new_events_schema.ambr b/posthog/tasks/test/__snapshots__/test_usage_report.new_events_schema.ambrindex 37221ac0c228..cf79a0e9b32a 100644--- a/posthog/tasks/test/__snapshots__/test_usage_report.new_events_schema.ambr+++ b/posthog/tasks/test/__snapshots__/test_usage_report.new_events_schema.ambr@@ -1015,10 +1015,12 @@'''SELECT team_id,- count(1) as count+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events_jsonWHERE timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59'+ AND timestamp < '2022-01-10 02:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')AND (properties.`$group_0` != ''OR properties.`$group_1` != ''OR properties.`$group_2` != ''@@ -1095,59 +1097,54 @@# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.50]'''- SELECT distinct_id as team,- sum(toInt64OrZero(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)), if(ascii(toString(properties.count)) IN (91, 123)- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count)), '[]'), '{}'), toString(properties.count))), ''))) as sum+ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events_json- WHERE team_id = 99999- AND event='decide usage'- AND timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59'- AND has(['correct'], ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)), if(ascii(toString(properties.token)) IN (91, 123)- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token)), '[]'), '{}'), toString(properties.token))), ''))- GROUP BY team+ WHERE timestamp >= '2022-01-10 02:00:00'+ AND timestamp < '2022-01-10 04:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')+ GROUP BY team_id'''# ---# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.51]'''- SELECT distinct_id as team,- sum(toInt64OrZero(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)), if(ascii(toString(properties.count)) IN (91, 123)- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count)), '[]'), '{}'), toString(properties.count))), ''))) as sum+ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events_json- WHERE team_id = 99999- AND event='local evaluation usage'- AND timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59'- AND has(['correct'], ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)), if(ascii(toString(properties.token)) IN (91, 123)- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token)), '[]'), '{}'), toString(properties.token))), ''))- GROUP BY team+ WHERE timestamp >= '2022-01-10 04:00:00'+ AND timestamp < '2022-01-10 06:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')+ GROUP BY team_id'''# ---# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.52]'''SELECT team_id,- COUNT() as count+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events_json- WHERE event = 'survey sent'- AND timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59'- AND uuid IN- (SELECT argMax(uuid, timestamp)- FROM events_json- WHERE timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59'- AND event = 'survey sent'- GROUP BY team_id,- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_id`), '\\/', '/'), toJSONString(properties.^`$survey_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_id`), '\\/', '/'), toJSONString(properties.^`$survey_id`)), if(ascii(toString(properties.`$survey_id`)) IN (91, 123)- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_id`), '\\/', '/'), toJSONString(properties.`$survey_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_id`), '\\/', '/'), toJSONString(properties.`$survey_id`)), '[]'), '{}'), toString(properties.`$survey_id`))), ''),- CASE- WHEN COALESCE(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)), if(ascii(toString(properties.`$survey_submission_id`)) IN (91, 123)- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`)), '[]'), '{}'), toString(properties.`$survey_submission_id`))), ''), '') = '' THEN toString(uuid)- ELSE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)), if(ascii(toString(properties.`$survey_submission_id`)) IN (91, 123)- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`)), '[]'), '{}'), toString(properties.`$survey_submission_id`))), '')- END)+ WHERE timestamp >= '2022-01-10 06:00:00'+ AND timestamp < '2022-01-10 08:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')GROUP BY team_id'''# ---@@ -1155,24 +1152,17 @@'''SELECT team_id,- COUNT() - uniqExactIf(request_id, verified- AND NOT relay- AND request_id != '') AS count,- max(relay) AS has_verified_relay- FROM- (SELECT team_id,- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_verified`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_verified`)), if(ascii(toString(properties.`$ai_gateway_verified`)) IN (91, 123)- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.`$ai_gateway_verified`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.`$ai_gateway_verified`)), '[]'), '{}'), toString(properties.`$ai_gateway_verified`))), '') IN ('true',- '1') AS verified,- if(verified, ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_request_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_request_id`)), if(ascii(toString(properties.`$ai_gateway_request_id`)) IN (91, 123)- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.`$ai_gateway_request_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.`$ai_gateway_request_id`)), '[]'), '{}'), toString(properties.`$ai_gateway_request_id`))), ''), '') AS request_id,- if(verified, ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_relay`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_relay`)), if(ascii(toString(properties.`$ai_gateway_relay`)) IN (91, 123)- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.`$ai_gateway_relay`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.`$ai_gateway_relay`)), '[]'), '{}'), toString(properties.`$ai_gateway_relay`))), ''), '') IN ('true',- '1') AS relay- FROM events_json- WHERE startsWith(event, '$ai_')- AND timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59')+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events_json+ WHERE timestamp >= '2022-01-10 08:00:00'+ AND timestamp < '2022-01-10 10:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')GROUP BY team_id'''# ---@@ -1180,16 +1170,107 @@'''SELECT team_id,- COUNT() - uniqExactIf(request_id, verified- AND request_id != '') as count- FROM- (SELECT team_id,- JSONExtractBool(toJSONString(properties), '$ai_gateway_verified') as verified,- if(verified, JSONExtractString(toJSONString(properties), '$ai_gateway_request_id'), '') as request_id- FROM events_json- WHERE event IN ['$ai_generation', '$ai_embedding', '$ai_span', '$ai_trace', '$ai_metric', '$ai_feedback', '$ai_evaluation', '$ai_tag', '$ai_trace_summary', '$ai_generation_summary', '$ai_trace_clusters', '$ai_generation_clusters']- AND timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59')+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events_json+ WHERE timestamp >= '2022-01-10 10:00:00'+ AND timestamp < '2022-01-10 12:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.55]+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events_json+ WHERE timestamp >= '2022-01-10 12:00:00'+ AND timestamp < '2022-01-10 14:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.56]+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events_json+ WHERE timestamp >= '2022-01-10 14:00:00'+ AND timestamp < '2022-01-10 16:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.57]+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events_json+ WHERE timestamp >= '2022-01-10 16:00:00'+ AND timestamp < '2022-01-10 18:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.58]+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events_json+ WHERE timestamp >= '2022-01-10 18:00:00'+ AND timestamp < '2022-01-10 20:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.59]+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events_json+ WHERE timestamp >= '2022-01-10 20:00:00'+ AND timestamp < '2022-01-10 22:00:00'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')GROUP BY team_id'''# ---@@ -1258,6 +1339,108 @@metric'''# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.60]+ '''++ SELECT team_id,+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count+ FROM events_json+ WHERE timestamp >= '2022-01-10 22:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND NOT startsWith(event, '$ai_')+ AND (properties.`$group_0` != ''+ OR properties.`$group_1` != ''+ OR properties.`$group_2` != ''+ OR properties.`$group_3` != ''+ OR properties.`$group_4` != '')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.61]+ '''++ SELECT distinct_id as team,+ sum(toInt64OrZero(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)), if(ascii(toString(properties.count)) IN (91, 123)+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count)), '[]'), '{}'), toString(properties.count))), ''))) as sum+ FROM events_json+ WHERE team_id = 99999+ AND event='decide usage'+ AND timestamp >= '2022-01-10 00:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ AND has(['correct'], ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)), if(ascii(toString(properties.token)) IN (91, 123)+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token)), '[]'), '{}'), toString(properties.token))), ''))+ GROUP BY team+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.62]+ '''++ SELECT distinct_id as team,+ sum(toInt64OrZero(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)), if(ascii(toString(properties.count)) IN (91, 123)+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count)), '[]'), '{}'), toString(properties.count))), ''))) as sum+ FROM events_json+ WHERE team_id = 99999+ AND event='local evaluation usage'+ AND timestamp >= '2022-01-10 00:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ AND has(['correct'], ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)), if(ascii(toString(properties.token)) IN (91, 123)+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token)), '[]'), '{}'), toString(properties.token))), ''))+ GROUP BY team+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.63]+ '''++ SELECT team_id,+ COUNT() as count+ FROM events_json+ WHERE event = 'survey sent'+ AND timestamp >= '2022-01-10 00:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ AND uuid IN+ (SELECT argMax(uuid, timestamp)+ FROM events_json+ WHERE timestamp >= '2022-01-10 00:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ AND event = 'survey sent'+ GROUP BY team_id,+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_id`), '\\/', '/'), toJSONString(properties.^`$survey_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_id`), '\\/', '/'), toJSONString(properties.^`$survey_id`)), if(ascii(toString(properties.`$survey_id`)) IN (91, 123)+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_id`), '\\/', '/'), toJSONString(properties.`$survey_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_id`), '\\/', '/'), toJSONString(properties.`$survey_id`)), '[]'), '{}'), toString(properties.`$survey_id`))), ''),+ CASE+ WHEN COALESCE(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)), if(ascii(toString(properties.`$survey_submission_id`)) IN (91, 123)+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`)), '[]'), '{}'), toString(properties.`$survey_submission_id`))), ''), '') = '' THEN toString(uuid)+ ELSE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)), if(ascii(toString(properties.`$survey_submission_id`)) IN (91, 123)+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`)), '[]'), '{}'), toString(properties.`$survey_submission_id`))), '')+ END)+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.64]+ '''++ SELECT team_id,+ COUNT() - uniqExactIf(request_id, verified+ AND NOT relay+ AND request_id != '') AS count,+ max(relay) AS has_verified_relay+ FROM+ (SELECT team_id,+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_verified`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_verified`)), if(ascii(toString(properties.`$ai_gateway_verified`)) IN (91, 123)+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.`$ai_gateway_verified`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.`$ai_gateway_verified`)), '[]'), '{}'), toString(properties.`$ai_gateway_verified`))), '') IN ('true',+ '1') AS verified,+ if(verified, ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_request_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_request_id`)), if(ascii(toString(properties.`$ai_gateway_request_id`)) IN (91, 123)+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.`$ai_gateway_request_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.`$ai_gateway_request_id`)), '[]'), '{}'), toString(properties.`$ai_gateway_request_id`))), ''), '') AS request_id,+ if(verified, ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_relay`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_relay`)), if(ascii(toString(properties.`$ai_gateway_relay`)) IN (91, 123)+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.`$ai_gateway_relay`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.`$ai_gateway_relay`)), '[]'), '{}'), toString(properties.`$ai_gateway_relay`))), ''), '') IN ('true',+ '1') AS relay+ FROM events_json+ WHERE startsWith(event, '$ai_')+ AND timestamp >= '2022-01-10 00:00:00'+ AND timestamp < '2022-01-10 23:59:59')+ GROUP BY team_id+ '''+# ---# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.6]'''diff --git a/posthog/tasks/test/test_usage_report.py b/posthog/tasks/test/test_usage_report.pyindex 6bbeaf08b2c9..6f6fa9c6a201 100644--- a/posthog/tasks/test/test_usage_report.py+++ b/posthog/tasks/test/test_usage_report.py@@ -70,6 +70,7 @@ from posthog.tasks.usage_report import (get_instance_metadata,get_teams_with_ai_credits_used_in_period,get_teams_with_billable_event_count_in_period,+ get_teams_with_event_count_with_groups_in_period,get_teams_with_posthog_code_credits_used_in_period,get_teams_with_query_metric,get_teams_with_sdk_logs_records_in_period,@@ -6112,6 +6113,37 @@ class TestQuerySplitting(ClickhouseDestroyTablesMixin, ClickhouseTestMixin, Testself.assertEqual(result[0][0], self.team.id)self.assertEqual(result[0][1], 5)+ def test_get_teams_with_event_count_with_groups_in_period_excludes_non_billable_events(self) -> None:+ # make sure we don't collapse duplicate rows+ sync_execute("SYSTEM STOP MERGES")+ self.addCleanup(sync_execute, "SYSTEM START MERGES")++ grouped_event_uuid = create_event(+ event_uuid=uuid4(),+ event="grouped_event",+ team=self.team,+ distinct_id="grouped_user",+ timestamp=self.begin + relativedelta(hours=1),+ properties={"$group_0": "org:1"},+ )+ for event in ["grouped_event", "$feature_flag_called", "$exception", "$ai_generation"]:+ _create_event(+ event_uuid=grouped_event_uuid if event == "grouped_event" else None,+ event=event,+ team=self.team,+ distinct_id="grouped_user",+ timestamp=self.begin + relativedelta(hours=1),+ properties={"$group_0": "org:1"},+ person_mode="full",+ )+ flush_persons_and_events()++ self.assertEqual(get_teams_with_event_count_with_groups_in_period(self.begin, self.end), [(self.team.id, 2)])+ self.assertEqual(+ get_teams_with_event_count_with_groups_in_period(self.begin, self.end, count_distinct=True),+ [(self.team.id, 1)],+ )+def test_get_all_event_metrics_counts_ai_sub_sdks(self) -> None:_create_event(event="$pageview",diff --git a/posthog/tasks/usage_report.py b/posthog/tasks/usage_report.pyindex 8438adc3bf02..92d15ecf9b9c 100644--- a/posthog/tasks/usage_report.py+++ b/posthog/tasks/usage_report.py@@ -792,23 +792,36 @@ def get_teams_with_billable_enhanced_persons_event_count_in_period(@timed_log()@retry(tries=QUERY_RETRIES, delay=QUERY_RETRY_DELAY, backoff=QUERY_RETRY_BACKOFF)-def get_teams_with_event_count_with_groups_in_period(begin: datetime, end: datetime) -> list[tuple[int, int]]:- with tags_context(product=Product.GROUP_ANALYTICS, feature=Feature.USAGE_REPORT):- use_new = use_new_events_schema(None)- group_columns = [f"properties.`$group_{i}`" if use_new else f"$group_{i}" for i in range(5)]- # nosemgrep: clickhouse-fstring-param-audit - events table comes from the internal schema gate- return sync_execute(- f"""- SELECT team_id, count(1) as count- FROM {events_read_table(use_new)}- WHERE timestamp >= %(begin)s AND timestamp < %(end)s+def get_teams_with_event_count_with_groups_in_period(+ begin: datetime, end: datetime, count_distinct: bool = False+) -> TeamUsageRows:+ # Uses the same exclusions and de-duplication as the billable enhanced persons count,+ # so that a group event count is never larger than the identified event count it is a subset of.+ if count_distinct:+ distinct_expression = "distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)"+ else:+ distinct_expression = "1"++ use_new = use_new_events_schema(None)+ group_columns = [f"properties.`$group_{i}`" if use_new else f"$group_{i}" for i in range(5)]+ # nosemgrep: clickhouse-fstring-param-audit - events table/count expression/group columns are internal fragments+ query_template = f"""+ SELECT team_id, count({distinct_expression}) as count+ FROM {events_read_table(use_new)}+ WHERE timestamp >= %(begin)s AND timestamp < %(end)s+ AND event NOT IN %(excluded_events)s+ AND NOT startsWith(event, %(ai_event_prefix)s)AND ({" OR ".join(f"{column} != ''" for column in group_columns)})- GROUP BY team_id- """,- {"begin": begin, "end": end},- workload=Workload.OFFLINE,- settings=CH_BILLING_SETTINGS,- ch_user=ClickHouseUser.BILLING,+ GROUP BY team_id+ """++ with tags_context(product=Product.GROUP_ANALYTICS, feature=Feature.USAGE_REPORT):+ return _execute_split_query(+ begin,+ end,+ query_template,+ {"excluded_events": BILLABLE_EVENT_EXCLUDED_EVENTS, "ai_event_prefix": AI_EVENT_NAME_PREFIX},+ num_splits=12,)@@ -2940,7 +2953,7 @@ def _get_all_usage_data(period_start: datetime, period_end: datetime) -> dict[stperiod_start, period_end, count_distinct=True),"teams_with_event_count_with_groups_in_period": get_teams_with_event_count_with_groups_in_period(- period_start, period_end+ period_start, period_end, count_distinct=True),"teams_with_event_count_from_helicone_in_period": all_metrics["helicone_events"],"teams_with_event_count_from_langfuse_in_period": all_metrics["langfuse_events"],diff --git a/posthog/temporal/usage_report/queries.py b/posthog/temporal/usage_report/queries.pyindex f10de06cb86c..d1b98ae226d6 100644--- a/posthog/temporal/usage_report/queries.py+++ b/posthog/temporal/usage_report/queries.py@@ -264,7 +264,8 @@ QUERIES: list[QuerySpec] = [),QuerySpec(name="teams_with_event_count_with_groups_in_period",- fn=get_teams_with_event_count_with_groups_in_period,+ fn=lambda b, e: get_teams_with_event_count_with_groups_in_period(b, e, count_distinct=True),+ timeout_minutes=30,),QuerySpec(name="all_event_metrics",