: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(logs): bill retention as byte-days instead of fixed tiers (#93515)
Frank Hamandc1936a081fc2
diff --git a/ee/billing/billing_types.py b/ee/billing/billing_types.pyindex d93c5135e063..54567d65322d 100644--- a/ee/billing/billing_types.py+++ b/ee/billing/billing_types.py@@ -34,6 +34,7 @@ UsageType = Literal["workflow_billable_invocations_in_period","logs_mb_in_period","logs_retention_30d_mb_in_period",+ "logs_retention_mb_days_in_period","replay_vision_credits_used_in_period","data_pipelines","group_analytics",@@ -78,6 +79,7 @@ USAGE_TYPE_OPTIONS: tuple[UsageTypeOption, ...] = ({"label": "Workflow destinations", "value": "workflow_billable_invocations_in_period"},{"label": "Logs ingested (MB)", "value": "logs_mb_in_period"},{"label": "Logs 30-day retention (MB)", "value": "logs_retention_30d_mb_in_period"},+ {"label": "Logs retention (MB-days)", "value": "logs_retention_mb_days_in_period"},)USAGE_TYPE_VALUES: tuple[UsageType, ...] = cast(tuple[UsageType, ...], get_args(UsageType))diff --git a/frontend/src/scenes/billing/constants.ts b/frontend/src/scenes/billing/constants.tsindex 366300330da0..5add3ee42c82 100644--- a/frontend/src/scenes/billing/constants.ts+++ b/frontend/src/scenes/billing/constants.ts@@ -23,6 +23,7 @@ export const SPEND_TYPES = [{ label: 'Workflow destinations', value: 'workflow_billable_invocations_in_period' },{ label: 'Logs ingested (MB)', value: 'logs_mb_in_period' },{ label: 'Logs 30-day retention (MB)', value: 'logs_retention_30d_mb_in_period' },+ { label: 'Logs retention (MB-days)', value: 'logs_retention_mb_days_in_period' },] as constexport const USAGE_ONLY_TYPES = [diff --git a/nodejs/src/logs/logs-ingestion-consumer.test.ts b/nodejs/src/logs/logs-ingestion-consumer.test.tsindex 9abfbbf06f11..67fe70cb5193 100644--- a/nodejs/src/logs/logs-ingestion-consumer.test.ts+++ b/nodejs/src/logs/logs-ingestion-consumer.test.ts@@ -1446,7 +1446,8 @@ describe('LogsIngestionConsumer', () => {const messages = getProducedKafkaMessages().filter((m) => m.topic === KAFKA_APP_METRICS_2)- expect(messages).toHaveLength(8)+ // 7 base metrics + per-tier retention + retention_byte_days.+ expect(messages).toHaveLength(9)const metricNames = messages.map((m) => parseMetricValue(m.value)?.metric_name)expect(metricNames).toContain('bytes_received')@@ -1457,15 +1458,22 @@ describe('LogsIngestionConsumer', () => {expect(metricNames).toContain('bytes_dropped')expect(metricNames).toContain('records_dropped')expect(metricNames).toContain('bytes_ingested_retention_30d')+ expect(metricNames).toContain('retention_byte_days')++ const retentionByteDays = messages+ .map((m) => parseMetricValue(m.value))+ .find((m) => m?.metric_name === 'retention_byte_days')+ expect(retentionByteDays?.count).toBe(800 * 30)})it.each([- { retentionDays: 14, absent: ['bytes_ingested_retention_30d', 'bytes_ingested_retention_90d'] },- { retentionDays: 30, absent: ['bytes_ingested_retention_14d', 'bytes_ingested_retention_90d'] },- { retentionDays: 90, absent: ['bytes_ingested_retention_14d', 'bytes_ingested_retention_30d'] },+ { retentionDays: 14, tierMetric: 'bytes_ingested_retention_14d' },+ { retentionDays: 30, tierMetric: 'bytes_ingested_retention_30d' },+ { retentionDays: 90, tierMetric: 'bytes_ingested_retention_90d' },+ { retentionDays: 45, tierMetric: null },])(- 'should emit only bytes_ingested_retention_${retentionDays}d for the matching tier',- async ({ retentionDays, absent }) => {+ 'should emit retention_byte_days as bytes_ingested * $retentionDays alongside the per-tier metric',+ async ({ retentionDays, tierMetric }) => {const usageStats = new Map([[team.id,@@ -1486,14 +1494,17 @@ describe('LogsIngestionConsumer', () => {await consumer['emitUsageMetrics'](usageStats)const messages = getProducedKafkaMessages().filter((m) => m.topic === KAFKA_APP_METRICS_2)- const retentionMetric = messages- .map((m) => parseMetricValue(m.value))- .find((m) => m?.metric_name === `bytes_ingested_retention_${retentionDays}d`)-- expect(retentionMetric?.count).toBe(500)- const metricNames = messages.map((m) => parseMetricValue(m.value)?.metric_name)- for (const name of absent) {- expect(metricNames).not.toContain(name)+ const parsed = messages.map((m) => parseMetricValue(m.value))++ expect(parsed.find((m) => m?.metric_name === 'retention_byte_days')?.count).toBe(500 * retentionDays)++ const tierMetrics = parsed.filter((m) => m?.metric_name?.startsWith('bytes_ingested_retention_'))+ if (tierMetric) {+ expect(tierMetrics).toHaveLength(1)+ expect(tierMetrics[0]?.metric_name).toBe(tierMetric)+ expect(tierMetrics[0]?.count).toBe(500)+ } else {+ expect(tierMetrics).toHaveLength(0)}})@@ -1520,12 +1531,13 @@ describe('LogsIngestionConsumer', () => {const messages = getProducedKafkaMessages().filter((m) => m.topic === KAFKA_APP_METRICS_2)- // 4 non-zero base metrics (no dropped) + 1 retention tier row- expect(messages).toHaveLength(5)+ // 4 non-zero base metrics (no dropped) + per-tier retention + retention_byte_days.+ expect(messages).toHaveLength(6)const metricNames = messages.map((m) => parseMetricValue(m.value)?.metric_name)expect(metricNames).not.toContain('bytes_dropped')expect(metricNames).not.toContain('records_dropped')expect(metricNames).toContain('bytes_ingested_retention_14d')+ expect(metricNames).toContain('retention_byte_days')})it('should handle empty usageStats', async () => {@@ -1574,13 +1586,13 @@ describe('LogsIngestionConsumer', () => {const messages = getProducedKafkaMessages().filter((m) => m.topic === KAFKA_APP_METRICS_2)- // 4 base metrics + 1 retention tier per team (no dropped) = 10 total- expect(messages).toHaveLength(10)+ // 4 base metrics + per-tier retention + retention_byte_days per team (no dropped) = 12 total.+ expect(messages).toHaveLength(12)const team1Messages = messages.filter((m) => parseMetricValue(m.value)?.team_id === team.id)const team2Messages = messages.filter((m) => parseMetricValue(m.value)?.team_id === team2.id)- expect(team1Messages).toHaveLength(5)- expect(team2Messages).toHaveLength(5)+ expect(team1Messages).toHaveLength(6)+ expect(team2Messages).toHaveLength(6)})})diff --git a/nodejs/src/logs/logs-ingestion-consumer.ts b/nodejs/src/logs/logs-ingestion-consumer.tsindex 0038bf5d3b45..257701b1f1f8 100644--- a/nodejs/src/logs/logs-ingestion-consumer.ts+++ b/nodejs/src/logs/logs-ingestion-consumer.ts@@ -78,7 +78,7 @@ export interface LogsIngestionConsumerDeps {/** Ingestion default when `logs_settings.retention_days` is unset; must be in `TeamSerializer.VALID_RETENTION_DAYS`. */export const DEFAULT_LOGS_RETENTION_DAYS = 14-/** Retention tiers that get their own per-tier usage metric; total = sum across all tiers. */+/** Retention day counts that get their own per-tier usage metric. */const RETENTION_USAGE_TIERS = new Set([14, 30, 90])function retentionBytesMetricName(retentionDays: number): string | null {@@ -889,7 +889,7 @@ export class LogsIngestionConsumer {const jsonParse = logsSettings.json_parse_logs ?? falseconst retentionDays = logsSettings.retention_days ?? DEFAULT_LOGS_RETENTION_DAYS- // Retention is uniform per team; stash for retention-bucketed usage emit+ // Retention is uniform per team; stash it for the retention usage metrics.const teamStats = usageStats.get(message.teamId)if (teamStats) {teamStats.retentionDays = retentionDays@@ -1124,6 +1124,11 @@ export class LogsIngestionConsumer {if (retentionMetric) {this.queueUsageMetric(teamId, retentionMetric, stats.bytesAllowed)}+ // Byte-days: ingested bytes weighted by retention days. Summed over a period it is total+ // storage-duration and scales to any retention day count (average retention =+ // retention_byte_days / bytes_ingested). Uses credit-adjusted `bytesAllowed` to reconcile+ // with `bytes_ingested`. Runs beside the per-tier metric above until billing leaves fixed tiers.+ this.queueUsageMetric(teamId, 'retention_byte_days', stats.bytesAllowed * stats.retentionDays)const source = this.appSource === 'traces' ? 'apm_traces' : 'logs'// These records are per-flush aggregates, not one per billed thing, so there is no// stable identity to reproduce. A fresh ID per flush is what keeps two pods flushingdiff --git a/posthog/tasks/test/__snapshots__/test_usage_report.ambr b/posthog/tasks/test/__snapshots__/test_usage_report.ambrindex 236743d14c57..7d9d3614520e 100644--- a/posthog/tasks/test/__snapshots__/test_usage_report.ambr+++ b/posthog/tasks/test/__snapshots__/test_usage_report.ambr@@ -458,16 +458,13 @@'''SELECT team_id,- metric_name,SUM(count) as countFROM app_metrics2- WHERE app_source='traces'- AND metric_name IN ('bytes_ingested',- 'records_ingested')+ WHERE app_source='logs'+ AND metric_name='retention_byte_days'AND timestamp >= '2022-01-10 00:00:00'AND timestamp < '2022-01-10 23:59:59'- GROUP BY team_id,- metric_name+ GROUP BY team_id'''# ---# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.3@@ -508,6 +505,22 @@# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.30'''+ SELECT team_id,+ metric_name,+ SUM(count) as count+ FROM app_metrics2+ WHERE app_source='traces'+ AND metric_name IN ('bytes_ingested',+ 'records_ingested')+ AND timestamp >= '2022-01-10 00:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ GROUP BY team_id,+ metric_name+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.31+ '''+SELECT team_id,multiIf(replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'node', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python', 'unknown') AS library,count(1) as total@@ -519,7 +532,7 @@library'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.31+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.32'''SELECT team_id,@@ -531,7 +544,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.32+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.33'''SELECT team_id,@@ -543,7 +556,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.33+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.34'''SELECT team_id,@@ -555,7 +568,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.34+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.35'''SELECT team_id,@@ -567,7 +580,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.35+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.36'''SELECT team_id,@@ -579,7 +592,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.36+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.37'''SELECT team_id,@@ -591,7 +604,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.37+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.38'''SELECT team_id,@@ -603,7 +616,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.38+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.39'''SELECT team_id,@@ -615,18 +628,6 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.39- '''-- 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']- GROUP BY team_id- '''-# ---# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.4'''@@ -668,8 +669,8 @@SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events- WHERE timestamp >= '2022-01-10 18:00:00'- AND timestamp < '2022-01-10 20:00:00'+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']GROUP BY team_id'''@@ -680,8 +681,8 @@SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events- WHERE timestamp >= '2022-01-10 20:00:00'- AND timestamp < '2022-01-10 22:00:00'+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']GROUP BY team_id'''@@ -692,8 +693,8 @@SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events- WHERE timestamp >= '2022-01-10 22:00:00'- AND timestamp < '2022-01-10 23:59:59'+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']GROUP BY team_id'''@@ -704,11 +705,9 @@SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events- WHERE timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 02:00:00'+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']- AND person_mode IN ('full',- 'force_upgrade')GROUP BY team_id'''# ---@@ -718,8 +717,8 @@SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events- WHERE timestamp >= '2022-01-10 02:00:00'- AND timestamp < '2022-01-10 04:00:00'+ WHERE timestamp >= '2022-01-10 00:00:00'+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']AND person_mode IN ('full','force_upgrade')@@ -732,8 +731,8 @@SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events- WHERE timestamp >= '2022-01-10 04:00:00'- AND timestamp < '2022-01-10 06:00:00'+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']AND person_mode IN ('full','force_upgrade')@@ -746,8 +745,8 @@SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events- WHERE timestamp >= '2022-01-10 06:00:00'- AND timestamp < '2022-01-10 08:00:00'+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']AND person_mode IN ('full','force_upgrade')@@ -760,8 +759,8 @@SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events- WHERE timestamp >= '2022-01-10 08:00:00'- AND timestamp < '2022-01-10 10:00:00'+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']AND person_mode IN ('full','force_upgrade')@@ -774,8 +773,8 @@SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events- WHERE timestamp >= '2022-01-10 10:00:00'- AND timestamp < '2022-01-10 12:00:00'+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']AND person_mode IN ('full','force_upgrade')@@ -788,8 +787,8 @@SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events- WHERE timestamp >= '2022-01-10 12:00:00'- AND timestamp < '2022-01-10 14:00:00'+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']AND person_mode IN ('full','force_upgrade')@@ -834,6 +833,20 @@# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.50'''+ 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', '$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', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']+ AND person_mode IN ('full',+ 'force_upgrade')+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.51+ '''+SELECT team_id,count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as countFROM events@@ -845,7 +858,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.51+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.52'''SELECT team_id,@@ -859,7 +872,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.52+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.53'''SELECT team_id,@@ -873,7 +886,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.53+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.54'''SELECT team_id,@@ -887,7 +900,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.54+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.55'''SELECT team_id,@@ -901,7 +914,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.55+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.56'''SELECT team_id,@@ -917,7 +930,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.56+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.57'''SELECT team_id,@@ -928,7 +941,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.57+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.58'''SELECT team_id,@@ -951,7 +964,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.58+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.59'''SELECT team_id,@@ -974,30 +987,6 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.59- '''-- SELECT team_id,- sum(total_size) as bytes- FROM- (SELECT any(team_id) as team_id,- session_id,- sum(size) as total_size- 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.6'''@@ -1036,6 +1025,30 @@# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.60'''+ SELECT team_id,+ sum(total_size) as bytes+ FROM+ (SELECT any(team_id) as team_id,+ session_id,+ sum(size) as total_size+ 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.61+ '''+SELECT team_id,count(distinct session_id) as countFROM@@ -1056,7 +1069,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.61+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.62'''SELECT team_id,@@ -1080,7 +1093,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.62+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.63'''SELECT team_id,@@ -1103,7 +1116,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.63+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.64'''SELECT distinct_id as team,@@ -1117,7 +1130,7 @@GROUP BY team'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.64+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.65'''SELECT distinct_id as team,@@ -1131,7 +1144,7 @@GROUP BY team'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.65+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.66'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1150,7 +1163,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.66+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.67'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1169,7 +1182,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.67+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.68'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1188,32 +1201,13 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.68- '''- 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(read_bytes) 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 = 'personal_api_key'- 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_methodSELECT team_id,- sum(read_rows) as count+ sum(read_bytes) as countFROM clusterAllReplicas(posthog, system.query_log)WHERE (type = 'QueryFinish'OR type = 'ExceptionWhileProcessing')@@ -1267,7 +1261,7 @@JSONExtractString(log_comment, 'query_type') as query_type,JSONExtractString(log_comment, 'access_method') as access_methodSELECT team_id,- sum(query_duration_ms) as count+ sum(read_rows) as countFROM clusterAllReplicas(posthog, system.query_log)WHERE (type = 'QueryFinish'OR type = 'ExceptionWhileProcessing')@@ -1281,6 +1275,25 @@'''# ---# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.71+ '''+ 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 = 'personal_api_key'+ GROUP BY team_id+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.72'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1300,7 +1313,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.72+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.73'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1320,7 +1333,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.73+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.74'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1340,7 +1353,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.74+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.75'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1360,7 +1373,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.75+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.76'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1380,7 +1393,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.76+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.77'''WITH JSONExtractInt(log_comment, 'team_id') as team_id,JSONExtractString(log_comment, 'query_type') as query_type,@@ -1400,7 +1413,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.77+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.78'''SELECT team_id,@@ -1424,7 +1437,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.78+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.79'''SELECT team_id,@@ -1439,20 +1452,6 @@metric_name'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.79- '''-- SELECT team_id,- SUM(count) as count- FROM app_metrics2- WHERE app_source='hog_function'- AND metric_name IN ('fetch')- AND timestamp >= '2022-01-10 00:00:00'- AND timestamp < '2022-01-10 23:59:59'- GROUP BY team_id,- metric_name- '''-# ---# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.8'''@@ -1491,6 +1490,20 @@# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.80'''+ SELECT team_id,+ SUM(count) as count+ FROM app_metrics2+ WHERE app_source='hog_function'+ AND metric_name IN ('fetch')+ AND timestamp >= '2022-01-10 00:00:00'+ AND timestamp < '2022-01-10 23:59:59'+ GROUP BY team_id,+ metric_name+ '''+# ---+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.81+ '''+SELECT team_id,SUM(count) as countFROM app_metrics2@@ -1501,7 +1514,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.81+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.82'''SELECT team_id,@@ -1523,7 +1536,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.82+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.83'''SELECT team_id,@@ -1537,7 +1550,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.83+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.84'''SELECT team_id,@@ -1551,7 +1564,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.84+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.85'''SELECT team_id,@@ -1565,7 +1578,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.85+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.86'''SELECT team_id,@@ -1579,7 +1592,7 @@GROUP BY team_id'''# ----# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.86+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.87'''SELECT team_id,diff --git a/posthog/tasks/test/test_usage_report.py b/posthog/tasks/test/test_usage_report.pyindex 7a0d29c1cc33..8d8163d971c0 100644--- a/posthog/tasks/test/test_usage_report.py+++ b/posthog/tasks/test/test_usage_report.py@@ -3295,14 +3295,13 @@ class TestHogFunctionUsageReports(ClickhouseDestroyTablesMixin, TestCase, Clickh@parameterized.expand([- # A team that changed retention 14d -> 30d mid-period: 1.5 GB total split across both tiers- # (0.5 GB at 14d, 1.0 GB at 30d).+ # 1.5 GB at a non-tier 45 days = 67.5 GB-days, so logs_retention_mb_days_in_period = 67_500+ # (67_500_000_000 byte-days // 1_000_000).(- "split_retention_14d_to_30d",+ "arbitrary_retention_days",{"bytes_ingested": 1_500_000_000,- "bytes_ingested_retention_14d": 500_000_000,- "bytes_ingested_retention_30d": 1_000_000_000,+ "retention_byte_days": 67_500_000_000,"records_ingested": 1000,},{@@ -3310,48 +3309,45 @@ class TestHogFunctionUsageReports(ClickhouseDestroyTablesMixin, TestCase, Clickh"logs_records_in_period": 1000,"logs_mb_in_period": 1500,"logs_and_traces_mb_in_period": 1500,- "logs_retention_14d_mb_in_period": 500,- "logs_retention_30d_mb_in_period": 1000,- "logs_retention_90d_mb_in_period": 0,+ "logs_retention_mb_days_in_period": 67_500,},),- # A team on a single tier the whole period: 2.5 GB, all under 90d retention.+ # Sub-MB-day total floors to 0: 500 KB retained 1 day is 500_000 byte-days, under 1 MB-day.(- "single_tier_90d",+ "sub_mb_day_floors_to_zero",{- "bytes_ingested": 2_500_000_000,- "bytes_ingested_retention_90d": 2_500_000_000,- "records_ingested": 2000,+ "bytes_ingested": 500_000,+ "retention_byte_days": 500_000,+ "records_ingested": 5,},{- "logs_bytes_in_period": 2_500_000_000,- "logs_records_in_period": 2000,- "logs_mb_in_period": 2500,- "logs_and_traces_mb_in_period": 2500,- "logs_retention_14d_mb_in_period": 0,- "logs_retention_30d_mb_in_period": 0,- "logs_retention_90d_mb_in_period": 2500,+ "logs_bytes_in_period": 500_000,+ "logs_records_in_period": 5,+ "logs_mb_in_period": 0,+ "logs_and_traces_mb_in_period": 0,+ "logs_retention_mb_days_in_period": 0,},),- # Sub-MB bytes split across tiers: each tier is floored to whole MB independently, so both- # tier counters drop to 0 even though the total (1.2 MB) rounds down to 1 MB. The tiers can- # sum to less than logs_mb_in_period.+ # Per-tier and byte-days in parallel: 2 GB at 30 days + 1 GB at 14 days. Each tier reports+ # its own MB; byte-days = 2_000*30 + 1_000*14 = 74_000 MB-days.(- "sub_mb_split_floors_to_zero",+ "per_tier_and_byte_days_in_parallel",{- "bytes_ingested": 1_200_000,- "bytes_ingested_retention_14d": 600_000,- "bytes_ingested_retention_30d": 600_000,- "records_ingested": 5,+ "bytes_ingested": 3_000_000_000,+ "bytes_ingested_retention_30d": 2_000_000_000,+ "bytes_ingested_retention_14d": 1_000_000_000,+ "retention_byte_days": 74_000_000_000,+ "records_ingested": 1500,},{- "logs_bytes_in_period": 1_200_000,- "logs_records_in_period": 5,- "logs_mb_in_period": 1,- "logs_and_traces_mb_in_period": 1,- "logs_retention_14d_mb_in_period": 0,- "logs_retention_30d_mb_in_period": 0,+ "logs_bytes_in_period": 3_000_000_000,+ "logs_records_in_period": 1500,+ "logs_mb_in_period": 3000,+ "logs_and_traces_mb_in_period": 3000,+ "logs_retention_14d_mb_in_period": 1000,+ "logs_retention_30d_mb_in_period": 2000,"logs_retention_90d_mb_in_period": 0,+ "logs_retention_mb_days_in_period": 74_000,},),]diff --git a/posthog/tasks/usage_report.py b/posthog/tasks/usage_report.pyindex b17b426cbf18..9a1f4243293b 100644--- a/posthog/tasks/usage_report.py+++ b/posthog/tasks/usage_report.py@@ -142,6 +142,9 @@ QUERY_RETRIES = 3QUERY_RETRY_DELAY = 1QUERY_RETRY_BACKOFF = 2+# `(team_id, count)` rows, the shape `convert_team_usage_rows_to_dict` reads.+TeamUsageRows = list[tuple[int, int]]+# Kafka's default `message.max.bytes` is ~1 MiB. For orgs with several hundred# teams the per-team breakdown under `teams` makes the report payload exceed# that limit, and the event is dropped at the broker — silently.@@ -352,13 +355,16 @@ class UsageReportCounters:logs_bytes_in_period: intlogs_records_in_period: intlogs_mb_in_period: int- # MB ingested while each retention tier was active. A team that changes retention mid-period has- # bytes under more than one tier. Each tier is floored to whole MB independently (bytes // 1_000_000),- # so the tiers sum to at most logs_mb_in_period and usually slightly less — every tier drops its own- # sub-MB remainder, so the totals only line up when each tier happens to be an exact MB multiple.+ # MB ingested under each retention tier. A team that changes retention mid-period splits across+ # tiers. Each tier floors to whole MB independently (bytes // 1_000_000), so the tiers sum to at+ # most logs_mb_in_period. Runs beside logs_retention_mb_days_in_period until billing leaves fixed tiers.logs_retention_14d_mb_in_period: intlogs_retention_30d_mb_in_period: intlogs_retention_90d_mb_in_period: int+ # Byte-days of retention floored to whole MB-days (retention_byte_days // 1_000_000): ingested bytes+ # weighted by retention days, so it scales to any retention day count. Report-only, like+ # logs_mb_in_period. Average retention days = logs_retention_mb_days_in_period / logs_mb_in_period.+ logs_retention_mb_days_in_period: int# Per-SDK split of logs_records_in_period, which on its own has no SDK dimension. Keyed off the# telemetry.sdk.name resource attribute each SDK sets on every record. See SDK_TELEMETRY_NAMES.web_logs_records_in_period: int@@ -2514,14 +2520,12 @@ def get_teams_with_logs_retention_bytes_in_period(end: datetime,) -> dict[str, list[tuple[int, int]]]:"""- Returns log bytes ingested while each retention tier (14d/30d/90d) was active, grouped by team.-- The logs-ingestion consumer emits a per-tier `bytes_ingested_retention_{14,30,90}d` metric into- `app_metrics2` alongside the total `bytes_ingested`. Result is keyed by the short tier suffix- used on `UsageReportCounters` (`14d`, `30d`, `90d`); each value is a list of `(team_id, count)`- tuples ready for `convert_team_usage_rows_to_dict`. All tier bytes also flow into the total- `logs_mb_in_period`, but each tier is floored to whole MB independently, so the tiers sum to at- most `logs_mb_in_period` (and usually a little less, as each tier drops its own sub-MB remainder).+ Returns log bytes ingested under each retention tier (14d/30d/90d), grouped by team.++ The consumer emits a per-tier `bytes_ingested_retention_{14,30,90}d` metric into `app_metrics2`.+ Keyed by the tier suffix on `UsageReportCounters` (`14d`, `30d`, `90d`); each value is a list of+ `(team_id, count)` tuples for `convert_team_usage_rows_to_dict`. Runs beside `retention_byte_days`+ (`get_teams_with_logs_retention_byte_days_in_period`) until billing leaves fixed tiers."""with tags_context(product=Product.LOGS, feature=Feature.USAGE_REPORT):rows = sync_execute(@@ -2549,6 +2553,36 @@ def get_teams_with_logs_retention_bytes_in_period(return by_tier+@timed_log()+@retry(tries=QUERY_RETRIES, delay=QUERY_RETRY_DELAY, backoff=QUERY_RETRY_BACKOFF)+def get_teams_with_logs_retention_byte_days_in_period(+ begin: datetime,+ end: datetime,+) -> TeamUsageRows:+ """+ Returns byte-days of log retention grouped by team: ingested bytes weighted by retention days.++ The consumer emits one `retention_byte_days` metric into `app_metrics2`+ (`retention_byte_days = bytes_ingested * retention_days`, summed per flush). Summed over the period+ it is total storage-duration and scales to any retention day count. Average retention days =+ `retention_byte_days` / `bytes_ingested`. Each `(team_id, count)` tuple is ready for+ `convert_team_usage_rows_to_dict`.+ """+ with tags_context(product=Product.LOGS, feature=Feature.USAGE_REPORT):+ return sync_execute(+ """+ SELECT team_id, SUM(count) as count+ FROM app_metrics2+ WHERE app_source='logs' AND metric_name='retention_byte_days' AND timestamp >= %(begin)s AND timestamp < %(end)s+ GROUP BY team_id+ """,+ {"begin": begin, "end": end},+ workload=Workload.OFFLINE,+ settings=CH_BILLING_SETTINGS,+ ch_user=ClickHouseUser.BILLING,+ )++@timed_log()@retry(tries=QUERY_RETRIES, delay=QUERY_RETRY_DELAY, backoff=QUERY_RETRY_BACKOFF)def get_teams_with_logs_records_in_period(@@ -2835,6 +2869,7 @@ def _get_all_usage_data(period_start: datetime, period_end: datetime) -> dict[stperiod_start, period_end, team_ids_with_logs=team_ids_with_logs)logs_retention_by_tier = get_teams_with_logs_retention_bytes_in_period(period_start, period_end)+ logs_retention_byte_days_rows = get_teams_with_logs_retention_byte_days_in_period(period_start, period_end)apm_tracing_usage = get_teams_with_apm_tracing_usage_in_period(period_start, period_end)exception_metrics_by_library, exception_metrics = get_teams_with_exceptions_captured_in_period(period_start, period_end@@ -3108,6 +3143,7 @@ def _get_all_usage_data(period_start: datetime, period_end: datetime) -> dict[st"teams_with_logs_retention_14d_bytes_in_period": logs_retention_by_tier["14d"],"teams_with_logs_retention_30d_bytes_in_period": logs_retention_by_tier["30d"],"teams_with_logs_retention_90d_bytes_in_period": logs_retention_by_tier["90d"],+ "teams_with_logs_retention_byte_days_in_period": logs_retention_byte_days_rows,"teams_with_logs_records_in_period": logs_records_rows,"teams_with_web_logs_records_in_period": sdk_logs_by_suffix["web"],"teams_with_ios_logs_records_in_period": sdk_logs_by_suffix["ios"],@@ -3350,6 +3386,9 @@ def _get_team_report(all_data: dict[str, Any], team: Team) -> UsageReportCounterlogs_retention_90d_mb_in_period=int(all_data["teams_with_logs_retention_90d_bytes_in_period"].get(team.id, 0) // 1_000_000),+ logs_retention_mb_days_in_period=int(+ all_data["teams_with_logs_retention_byte_days_in_period"].get(team.id, 0) // 1_000_000+ ),web_logs_records_in_period=all_data["teams_with_web_logs_records_in_period"].get(team.id, 0),ios_logs_records_in_period=all_data["teams_with_ios_logs_records_in_period"].get(team.id, 0),react_native_logs_records_in_period=all_data["teams_with_react_native_logs_records_in_period"].get(team.id, 0),diff --git a/posthog/temporal/tests/usage_report/test_aggregate_activity.py b/posthog/temporal/tests/usage_report/test_aggregate_activity.pyindex 5075b6d5e6f3..ee782ddd8cd4 100644--- a/posthog/temporal/tests/usage_report/test_aggregate_activity.py+++ b/posthog/temporal/tests/usage_report/test_aggregate_activity.py@@ -122,6 +122,10 @@ def _canned_query_payload(query_name: str, team_a_id: int, team_b_id: int, *extrif query_name == "teams_with_event_count_in_period":return [(team_a_id, 100), (team_b_id, 50), *extra_total_rows]+ if query_name == "teams_with_logs_retention_byte_days_in_period":+ # 2_500_000 byte-days floors to 2 MB-days, so a dropped floor or raw-bytes passthrough+ # fails the assertion instead of matching by accident.+ return [(team_a_id, 2_500_000)]if query_name == "teams_with_recording_count_in_period":return [(team_a_id, 8)]@@ -266,6 +270,10 @@ async def test_aggregate_writes_chunks_and_manifest(minio_workflow_ctx: Workflowassert by_org[str(org_b.id)]["apm_tracing_bytes_in_period"] == 0assert by_org[str(org_b.id)]["apm_tracing_spans_in_period"] == 0+ # Log retention byte-days reach the counter floored to whole MB-days.+ assert by_org[str(org_a.id)]["logs_retention_mb_days_in_period"] == 2+ assert by_org[str(org_b.id)]["logs_retention_mb_days_in_period"] == 0+# has_non_zero_usage is computed and present on every line.assert by_org[str(org_a.id)]["has_non_zero_usage"] is Trueassert by_org[str(org_b.id)]["has_non_zero_usage"] is Truediff --git a/posthog/temporal/usage_report/queries.py b/posthog/temporal/usage_report/queries.pyindex bcc1efa5bbb2..b7bada2e7447 100644--- a/posthog/temporal/usage_report/queries.py+++ b/posthog/temporal/usage_report/queries.py@@ -73,6 +73,7 @@ from posthog.tasks.usage_report import (get_teams_with_hog_function_fetch_calls_in_period,get_teams_with_logs_bytes_in_period,get_teams_with_logs_records_in_period,+ get_teams_with_logs_retention_byte_days_in_period,get_teams_with_logs_retention_bytes_in_period,get_teams_with_mobile_billable_recording_count_in_period,get_teams_with_posthog_code_credits_used_in_period,@@ -564,6 +565,10 @@ QUERIES: list[QuerySpec] = ["90d": "teams_with_logs_retention_90d_bytes_in_period",},),+ QuerySpec(+ name="teams_with_logs_retention_byte_days_in_period",+ fn=get_teams_with_logs_retention_byte_days_in_period,+ ),# ---- ClickHouse: APM tracing ---------------------------------------------QuerySpec(name="apm_tracing_usage",diff --git a/products/billing/frontend/generated/api.schemas.ts b/products/billing/frontend/generated/api.schemas.tsindex 12e1d553e534..815eb34c71b9 100644--- a/products/billing/frontend/generated/api.schemas.ts+++ b/products/billing/frontend/generated/api.schemas.ts@@ -672,7 +672,7 @@ export type BillingSpendRetrieveParams = {*/team_ids?: string | null/**- * JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. ["event_count_in_period","recording_count_in_period"]. Omit for all types.+ * JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, logs_retention_mb_days_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. ["event_count_in_period","recording_count_in_period"]. Omit for all types.* @nullable*/usage_types?: string | null@@ -702,7 +702,7 @@ export type BillingUsageRetrieveParams = {*/team_ids?: string | null/**- * JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. ["event_count_in_period","recording_count_in_period"]. Omit for all types.+ * JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, logs_retention_mb_days_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. ["event_count_in_period","recording_count_in_period"]. Omit for all types.* @nullable*/usage_types?: string | nulldiff --git a/products/billing/skills/understanding-billing-usage/references/usage-type-routing.md b/products/billing/skills/understanding-billing-usage/references/usage-type-routing.mdindex 2399cf69ca1f..c30b0d3f4101 100644--- a/products/billing/skills/understanding-billing-usage/references/usage-type-routing.md+++ b/products/billing/skills/understanding-billing-usage/references/usage-type-routing.md@@ -28,31 +28,32 @@ Useful downstream skills for usage investigations include:- `posthog:exploring-replay-vision-observations` when Replay Vision credits point to scannerobservations.-| Usage type | What Billing can show | Customer-visible follow-up |-| ------------------------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| `event_count_in_period` | Events by day/project | Use `posthog:investigate-metric` or Product Analytics SQL/insight tools on the affected project. Break down by event name and compare the alert/high-usage day to baseline days. If `$autocapture` dominates, continue with `posthog:exploring-autocapture-events`. |-| `enhanced_persons_event_count_in_period` | Identified events by day/project | Start like Events, using `posthog:investigate-metric` when available, but avoid claiming the raw event-name breakdown exactly explains the identified/anonymous split unless that dimension is visible. |-| `group_analytics` | Group Analytics spend/usage attribution using identified-event usage | Treat as an alias-style product view. Use identified-event/Product Analytics drilldown, usually via `posthog:investigate-metric`, and explain that the Billing view is product-specific attribution, not a separate raw event stream. |-| `recording_count_in_period` | Session recordings by day/project | Use Session Replay tools or the Replay UI for recording volume, SDK/platform filters, and representative sessions. Use `posthog:investigating-replay` only after you have representative recording/session IDs. |-| `mobile_recording_count_in_period` | Mobile recordings by day/project | Use Session Replay/mobile replay surfaces. Look for mobile SDK/platform mix before suggesting product changes. Use `posthog:investigating-replay` only after you have representative mobile recording/session IDs. |-| `billable_feature_flag_requests_count_in_period` | Feature flag requests by day/project | Use feature flag tools, flag configuration, and activity history. The billable unit is flag evaluation/API request volume, not `$feature_flag_called` events. Do not use stale-flag cleanup workflows unless the user asks how to remove unused flags. |-| `exceptions_captured_in_period` | Exceptions by day/project | Use Error Tracking issue tools and `$exception` aggregates in the affected project. If one issue dominates the movement, use `posthog:investigating-error-issue`. UI issue counts are grouped context, while Billing usage is captured exception volume. |-| `survey_responses_count_in_period` | Survey responses by day/project | Use survey tools and survey events such as `survey shown` and `survey sent` to distinguish reach from response-rate changes. Use `posthog:debugging-surveys` when the investigation turns into "why is this survey showing, not showing, or getting fewer/more responses than expected?" |-| `ai_event_count_in_period` | AI Observability events by day/project | Use AI Observability tools or SQL over `$ai_*` events in the affected project. Break down by provider/model/trace/user only when those properties are available. Use `posthog:exploring-llm-costs` for cost-shaped questions and `posthog:analyzing-expensive-users` for user-level drivers. |-| `ai_credits_used_in_period` | PostHog AI credits by day/project | Use PostHog AI or AI Observability surfaces exposed to the user. Prefer `posthog:exploring-llm-costs` for credit/spend movement and `posthog:analyzing-expensive-users` for concentrated user drivers. Do not inspect internal PostHog-owned AI telemetry in a customer-facing investigation. |-| `signals_credits_used_in_period` | Inbox credits by day/project | Use Signals/Inbox product tools when available. Start with `posthog:inbox-exploration` for report-level context; use `posthog:signals` only when raw signal search is needed. Billing shows chargeable credit movement; product tools should explain reports/PRs/refunds. |-| `posthog_code_credits_used_in_period` | PostHog Desktop credits by day/project | Use PostHog Desktop usage surfaces when available. Treat token credits and sandbox compute as possible sub-drivers if exposed. |-| `posthog_code_token_credits_used_in_period` | PostHog Desktop token credits by day/project | Use PostHog Desktop/AI usage surfaces when available. |-| `sandbox_compute_credits_used_in_period` | Sandbox compute credits by day/project | Use task/sandbox/PostHog Desktop surfaces when available. |-| `sandbox_compute_cpu_millicore_seconds_in_period` | Sandbox CPU usage by day/project | Use task/sandbox surfaces when available. This is a raw usage diagnostic, not usually the headline spend type. |-| `sandbox_compute_memory_mib_seconds_in_period` | Sandbox memory usage by day/project | Use task/sandbox surfaces when available. This is a raw usage diagnostic, not usually the headline spend type. |-| `rows_synced_in_period` | Data Warehouse synced rows by day/project | Use Data Warehouse source/schema health and sync tools. Look for new sources, enabled schemas, failed/stale syncs, or expected backfills. Use `posthog:auditing-warehouse-source-health` for a project-wide scan and `posthog:diagnosing-failed-warehouse-syncs` for a specific source/schema. |-| `free_historical_rows_synced_in_period` | Historical synced rows by day/project | Use Data Warehouse source/schema tools. Explain it as historical sync activity, not ongoing incremental volume. Use `posthog:auditing-warehouse-source-health` or `posthog:diagnosing-failed-warehouse-syncs` if a source or schema needs investigation. |-| `rows_exported_in_period` | Batch export rows by day/project | Use batch export/CDP export tools and export configuration. Check newly enabled exports or changed destinations. |-| `data_pipelines` | Legacy Data Pipelines product attribution | Treat as a legacy/synthetic product view. Use the Product Analytics or CDP surface that actually produced the usage, depending on the user's context. |-| `cdp_billable_invocations_in_period` | Realtime destination trigger events by day/project | Use CDP function tools: list functions, inspect enabled destinations, metrics, and logs for the affected window. |-| `workflow_emails_sent_in_period` | Workflow emails by day/project | Use Workflows tools: workflow stats, invocation logs, enabled workflows, and recent changes. |-| `workflow_billable_invocations_in_period` | Workflow destination dispatches by day/project | Use Workflows tools and destination/invocation logs. Keep it separate from email volume. |-| `logs_mb_in_period` | Logs ingested in MB by day/project | Use `posthog:investigating-logs` with Logs tools: service overview, count ranges, facets, and pattern diffs. Prefer log-specific tools over raw SQL. |-| `logs_retention_30d_mb_in_period` | Logs ingested under 30-day retention by day/project | Use `posthog:investigating-logs` with Logs tools and retention/settings surfaces. Explain that this is retention-tier usage, not separate log content. |-| `replay_vision_credits_used_in_period` | Replay Vision credits by day/project | Use Replay Vision scanner/observation tools. Credits come from scanner observations, so inspect scanners and observation status/results. Use `posthog:exploring-replay-vision-observations` when scanner observations are the natural drilldown. |+| Usage type | What Billing can show | Customer-visible follow-up |+| ------------------------------------------------- | ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| `event_count_in_period` | Events by day/project | Use `posthog:investigate-metric` or Product Analytics SQL/insight tools on the affected project. Break down by event name and compare the alert/high-usage day to baseline days. If `$autocapture` dominates, continue with `posthog:exploring-autocapture-events`. |+| `enhanced_persons_event_count_in_period` | Identified events by day/project | Start like Events, using `posthog:investigate-metric` when available, but avoid claiming the raw event-name breakdown exactly explains the identified/anonymous split unless that dimension is visible. |+| `group_analytics` | Group Analytics spend/usage attribution using identified-event usage | Treat as an alias-style product view. Use identified-event/Product Analytics drilldown, usually via `posthog:investigate-metric`, and explain that the Billing view is product-specific attribution, not a separate raw event stream. |+| `recording_count_in_period` | Session recordings by day/project | Use Session Replay tools or the Replay UI for recording volume, SDK/platform filters, and representative sessions. Use `posthog:investigating-replay` only after you have representative recording/session IDs. |+| `mobile_recording_count_in_period` | Mobile recordings by day/project | Use Session Replay/mobile replay surfaces. Look for mobile SDK/platform mix before suggesting product changes. Use `posthog:investigating-replay` only after you have representative mobile recording/session IDs. |+| `billable_feature_flag_requests_count_in_period` | Feature flag requests by day/project | Use feature flag tools, flag configuration, and activity history. The billable unit is flag evaluation/API request volume, not `$feature_flag_called` events. Do not use stale-flag cleanup workflows unless the user asks how to remove unused flags. |+| `exceptions_captured_in_period` | Exceptions by day/project | Use Error Tracking issue tools and `$exception` aggregates in the affected project. If one issue dominates the movement, use `posthog:investigating-error-issue`. UI issue counts are grouped context, while Billing usage is captured exception volume. |+| `survey_responses_count_in_period` | Survey responses by day/project | Use survey tools and survey events such as `survey shown` and `survey sent` to distinguish reach from response-rate changes. Use `posthog:debugging-surveys` when the investigation turns into "why is this survey showing, not showing, or getting fewer/more responses than expected?" |+| `ai_event_count_in_period` | AI Observability events by day/project | Use AI Observability tools or SQL over `$ai_*` events in the affected project. Break down by provider/model/trace/user only when those properties are available. Use `posthog:exploring-llm-costs` for cost-shaped questions and `posthog:analyzing-expensive-users` for user-level drivers. |+| `ai_credits_used_in_period` | PostHog AI credits by day/project | Use PostHog AI or AI Observability surfaces exposed to the user. Prefer `posthog:exploring-llm-costs` for credit/spend movement and `posthog:analyzing-expensive-users` for concentrated user drivers. Do not inspect internal PostHog-owned AI telemetry in a customer-facing investigation. |+| `signals_credits_used_in_period` | Inbox credits by day/project | Use Signals/Inbox product tools when available. Start with `posthog:inbox-exploration` for report-level context; use `posthog:signals` only when raw signal search is needed. Billing shows chargeable credit movement; product tools should explain reports/PRs/refunds. |+| `posthog_code_credits_used_in_period` | PostHog Desktop credits by day/project | Use PostHog Desktop usage surfaces when available. Treat token credits and sandbox compute as possible sub-drivers if exposed. |+| `posthog_code_token_credits_used_in_period` | PostHog Desktop token credits by day/project | Use PostHog Desktop/AI usage surfaces when available. |+| `sandbox_compute_credits_used_in_period` | Sandbox compute credits by day/project | Use task/sandbox/PostHog Desktop surfaces when available. |+| `sandbox_compute_cpu_millicore_seconds_in_period` | Sandbox CPU usage by day/project | Use task/sandbox surfaces when available. This is a raw usage diagnostic, not usually the headline spend type. |+| `sandbox_compute_memory_mib_seconds_in_period` | Sandbox memory usage by day/project | Use task/sandbox surfaces when available. This is a raw usage diagnostic, not usually the headline spend type. |+| `rows_synced_in_period` | Data Warehouse synced rows by day/project | Use Data Warehouse source/schema health and sync tools. Look for new sources, enabled schemas, failed/stale syncs, or expected backfills. Use `posthog:auditing-warehouse-source-health` for a project-wide scan and `posthog:diagnosing-failed-warehouse-syncs` for a specific source/schema. |+| `free_historical_rows_synced_in_period` | Historical synced rows by day/project | Use Data Warehouse source/schema tools. Explain it as historical sync activity, not ongoing incremental volume. Use `posthog:auditing-warehouse-source-health` or `posthog:diagnosing-failed-warehouse-syncs` if a source or schema needs investigation. |+| `rows_exported_in_period` | Batch export rows by day/project | Use batch export/CDP export tools and export configuration. Check newly enabled exports or changed destinations. |+| `data_pipelines` | Legacy Data Pipelines product attribution | Treat as a legacy/synthetic product view. Use the Product Analytics or CDP surface that actually produced the usage, depending on the user's context. |+| `cdp_billable_invocations_in_period` | Realtime destination trigger events by day/project | Use CDP function tools: list functions, inspect enabled destinations, metrics, and logs for the affected window. |+| `workflow_emails_sent_in_period` | Workflow emails by day/project | Use Workflows tools: workflow stats, invocation logs, enabled workflows, and recent changes. |+| `workflow_billable_invocations_in_period` | Workflow destination dispatches by day/project | Use Workflows tools and destination/invocation logs. Keep it separate from email volume. |+| `logs_mb_in_period` | Logs ingested in MB by day/project | Use `posthog:investigating-logs` with Logs tools: service overview, count ranges, facets, and pattern diffs. Prefer log-specific tools over raw SQL. |+| `logs_retention_30d_mb_in_period` | Logs ingested under 30-day retention by day/project | Use `posthog:investigating-logs` with Logs tools and retention/settings surfaces. Explain that this is retention-tier usage, not separate log content. |+| `logs_retention_mb_days_in_period` | Logs retention in MB-days (bytes ingested weighted by retention days) by day/project | Use `posthog:investigating-logs` with Logs tools and retention/settings surfaces. Explain that this is storage-duration usage (MB times days retained), not separate log content. Average retention days = this / `logs_mb_in_period`. |+| `replay_vision_credits_used_in_period` | Replay Vision credits by day/project | Use Replay Vision scanner/observation tools. Credits come from scanner observations, so inspect scanners and observation status/results. Use `posthog:exploring-replay-vision-observations` when scanner observations are the natural drilldown. |diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 7e0ba56c9b14..b99ac78127df 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -90326,7 +90326,7 @@ export namespace Schemas {*/team_ids?: string | null;/**- * JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. ["event_count_in_period","recording_count_in_period"]. Omit for all types.+ * JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, logs_retention_mb_days_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. ["event_count_in_period","recording_count_in_period"]. Omit for all types.* @nullable*/usage_types?: string | null;@@ -90356,7 +90356,7 @@ export namespace Schemas {*/team_ids?: string | null;/**- * JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. ["event_count_in_period","recording_count_in_period"]. Omit for all types.+ * JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, logs_retention_mb_days_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. ["event_count_in_period","recording_count_in_period"]. Omit for all types.* @nullable*/usage_types?: string | null;diff --git a/services/mcp/src/generated/billing/api.ts b/services/mcp/src/generated/billing/api.tsindex a20de1575e91..3579a80f473a 100644--- a/services/mcp/src/generated/billing/api.ts+++ b/services/mcp/src/generated/billing/api.ts@@ -31,7 +31,7 @@ export const BillingSpendRetrieveQueryParams = () => zod.object({.string().nullish().describe(- 'JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. [\"event_count_in_period\",\"recording_count_in_period\"]. Omit for all types.'+ 'JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, logs_retention_mb_days_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. [\"event_count_in_period\",\"recording_count_in_period\"]. Omit for all types.'),})@@ -55,6 +55,6 @@ export const BillingUsageRetrieveQueryParams = () => zod.object({.string().nullish().describe(- 'JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. [\"event_count_in_period\",\"recording_count_in_period\"]. Omit for all types.'+ 'JSON-encoded array of usage type identifiers to filter on. Valid values: event_count_in_period, exceptions_captured_in_period, recording_count_in_period, rows_synced_in_period, free_historical_rows_synced_in_period, survey_responses_count_in_period, mobile_recording_count_in_period, billable_feature_flag_requests_count_in_period, enhanced_persons_event_count_in_period, ai_event_count_in_period, cdp_billable_invocations_in_period, rows_exported_in_period, ai_credits_used_in_period, signals_credits_used_in_period, posthog_code_credits_used_in_period, posthog_code_token_credits_used_in_period, sandbox_compute_credits_used_in_period, sandbox_compute_cpu_millicore_seconds_in_period, sandbox_compute_memory_mib_seconds_in_period, workflow_emails_sent_in_period, workflow_billable_invocations_in_period, logs_mb_in_period, logs_retention_30d_mb_in_period, logs_retention_mb_days_in_period, replay_vision_credits_used_in_period, data_pipelines, group_analytics. E.g. [\"event_count_in_period\",\"recording_count_in_period\"]. Omit for all types.'),})