: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(subscriptions): use standard SLO delivery events (#77556)
Matt Pua4cbd43dd44e0
diff --git a/terraform/us/project-2/team-analytics-platform/dashboard-key-metrics/insights.tf b/terraform/us/project-2/team-analytics-platform/dashboard-key-metrics/insights.tfindex 7bb86a7c8f75..de53c78aa455 100644--- a/terraform/us/project-2/team-analytics-platform/dashboard-key-metrics/insights.tf+++ b/terraform/us/project-2/team-analytics-platform/dashboard-key-metrics/insights.tf@@ -650,9 +650,15 @@ resource "posthog_insight" "subscription_delivery_success_rate" {{"kind": "EventsNode","math": "total",- "event": "subscription_delivery_started",+ "event": "slo_operation_started","custom_name": "Started","properties": [+ {+ "key": "operation",+ "type": "event",+ "value": ["subscription_delivery"],+ "operator": "exact"+ },{"key": "region","type": "event",@@ -664,9 +670,21 @@ resource "posthog_insight" "subscription_delivery_success_rate" {{"kind": "EventsNode","math": "total",- "event": "subscription_delivery_exhausted",- "custom_name": "Exhausted (failed)",+ "event": "slo_operation_completed",+ "custom_name": "Succeeded","properties": [+ {+ "key": "operation",+ "type": "event",+ "value": ["subscription_delivery"],+ "operator": "exact"+ },+ {+ "key": "outcome",+ "type": "event",+ "value": ["success"],+ "operator": "exact"+ },{"key": "region","type": "event",@@ -686,7 +704,7 @@ resource "posthog_insight" "subscription_delivery_success_rate" {"showLegend": true,"showValuesOnSeries": true,"formulaNodes": [- { "formula": "(A-B)/A", "custom_name": "Success rate" }+ { "formula": "B/A", "custom_name": "Success rate" }],"aggregationAxisFormat": "percentage_scaled"},@@ -704,7 +722,7 @@ resource "posthog_insight" "alert_failures_by_exception_type_aggregated" {"kind": "DataTableNode","source": {"kind": "HogQLQuery",- "query": "SELECT \n CASE \n WHEN properties.traceback LIKE '%RuntimeError: No results found for insight with alert id =%' \n THEN 'RuntimeError: No results found for insight'\n WHEN properties.traceback LIKE '%ValueError: Relative alerts not supported for non time series trends%' \n THEN 'ValueError: Relative alerts not supported for non time series trends'\n WHEN properties.traceback LIKE '%UnboundLocalError: cannot access local variable%config%' \n THEN 'UnboundLocalError: cannot access local variable config'\n WHEN properties.traceback LIKE '%pydantic_core._pydantic_core.ValidationError%AlertCondition%type%Field required%' \n THEN 'ValidationError: AlertCondition missing required field \"type\"'\n WHEN properties.traceback LIKE '%QueryTimeoutError%' OR properties.traceback LIKE '%timeout%'\n THEN 'Query timeout error'\n WHEN properties.traceback LIKE '%PermissionError%' OR properties.traceback LIKE '%permission%'\n THEN 'Permission error'\n WHEN properties.traceback LIKE '%KeyError%' \n THEN 'KeyError: Missing expected key'\n WHEN properties.traceback LIKE '%AttributeError%' \n THEN 'AttributeError: Missing attribute'\n WHEN properties.traceback LIKE '%IndexError%' \n THEN 'IndexError: List index out of range'\n WHEN properties.traceback LIKE '%TypeError%' \n THEN 'TypeError: Type mismatch'\n WHEN properties.traceback IS NULL OR properties.traceback = ''\n THEN 'Unknown (no traceback)'\n ELSE 'Other exception type'\n END AS exception_type,\n count() AS failure_count,\n count() * 100.0 / sum(count()) OVER () AS percentage_of_failures,\n uniq(properties.alert_id) AS unique_alerts_affected,\n uniq(properties.team_id) AS unique_teams_affected,\n min(timestamp) AS first_occurrence,\n max(timestamp) AS last_occurrence\nFROM events\nWHERE event = 'alert check failed'\n AND timestamp >= now() - INTERVAL 30 DAY\n AND timestamp < now()\nGROUP BY exception_type\nORDER BY failure_count DESC\nLIMIT 100"+ "query": "SELECT\n coalesce(\n properties.error_type,\n if(properties.alert_state = 'Errored', 'Alert configuration error', 'Unknown error')\n ) AS exception_type,\n count() AS failure_count,\n count() * 100.0 / sum(count()) OVER () AS percentage_of_failures,\n uniq(properties.resource_id) AS unique_alerts_affected,\n uniq(properties.team_id) AS unique_teams_affected,\n min(timestamp) AS first_occurrence,\n max(timestamp) AS last_occurrence\nFROM events\nWHERE event = 'slo_operation_completed'\n AND properties.operation = 'alert_check'\n AND (properties.outcome = 'failure' OR properties.alert_state = 'Errored')\n AND timestamp >= now() - INTERVAL 30 DAY\n AND timestamp < now()\nGROUP BY exception_type\nORDER BY failure_count DESC\nLIMIT 100"}})tags = ["managed-by:terraform"]diff --git a/terraform/us/project-2/team-analytics-platform/slo-monitoring/insights.tf b/terraform/us/project-2/team-analytics-platform/slo-monitoring/insights.tfindex 77f8c8431efc..bf094e9dbc29 100644--- a/terraform/us/project-2/team-analytics-platform/slo-monitoring/insights.tf+++ b/terraform/us/project-2/team-analytics-platform/slo-monitoring/insights.tf@@ -471,7 +471,7 @@ resource "posthog_insight" "slo_success_rate" {# ---------------------------------------------------------------------------resource "posthog_insight" "slo_volume" {name = "SLO: 28d Volume by Operation"- description = "* = all regions, but events are only emitted from the US project (ph_scoped_capture hardcodes the US client)"+ description = "* = all regions"query_json = jsonencode({kind = "DataVisualizationNode"source = {diff --git a/terraform/us/project-2/team-analytics-platform/slos/insights.tf b/terraform/us/project-2/team-analytics-platform/slos/insights.tfindex f3dacb1e9a4a..b26a682f795d 100644--- a/terraform/us/project-2/team-analytics-platform/slos/insights.tf+++ b/terraform/us/project-2/team-analytics-platform/slos/insights.tf@@ -109,7 +109,7 @@ locals {WHERE event = 'slo_operation_completed'AND properties.operation = 'alert_check'AND properties.alert_type = 'insight'- AND properties.region = '{{REGION}}'+ AND upper(properties.region) = upper('{{REGION}}')AND properties.skip_reason IS NULLAND timestamp >= now() - INTERVAL 30 DAYGROUP BY date@@ -141,7 +141,7 @@ locals {WHERE event = 'slo_operation_completed'AND properties.operation = 'alert_check'AND properties.alert_type = 'insight'- AND properties.region = '{{REGION}}'+ AND upper(properties.region) = upper('{{REGION}}')AND properties.skip_reason IS NULLAND properties.calculation_interval IN ('hourly', 'daily', 'weekly', 'monthly')AND timestamp >= now() - INTERVAL 45 DAY@@ -187,15 +187,37 @@ locals {error_budget = 0.01regions = ["us", "eu"]daily_sql = <<-SQL+ -- Attribute outcomes to the day the delivery started. A started workflow+ -- without a successful completion is a failed SLO operation, including a+ -- workflow that crashes before the interceptor can emit completion.+ WITH starts AS (+ SELECT+ toDate(min(timestamp)) AS date,+ properties.correlation_id AS correlation_id+ FROM events+ WHERE event = 'slo_operation_started'+ AND properties.operation = 'subscription_delivery'+ AND upper(properties.region) = upper('{{REGION}}')+ AND timestamp >= now() - INTERVAL 30 DAY+ GROUP BY correlation_id+ ), completed AS (+ SELECT+ properties.correlation_id AS correlation_id,+ max(properties.outcome = 'success') AS succeeded+ FROM events+ WHERE event = 'slo_operation_completed'+ AND properties.operation = 'subscription_delivery'+ AND upper(properties.region) = upper('{{REGION}}')+ AND timestamp >= now() - INTERVAL 30 DAY+ GROUP BY correlation_id+ )SELECT- toDate(timestamp) AS date,- countIf(event = 'subscription_delivery_started') AS total,- countIf(event = 'subscription_delivery_exhausted') AS failures- FROM events- WHERE event IN ('subscription_delivery_started', 'subscription_delivery_exhausted')- AND properties.region = '{{REGION}}'- AND timestamp >= now() - INTERVAL 30 DAY- GROUP BY date+ starts.date,+ count() AS total,+ countIf(coalesce(completed.succeeded, false) = false) AS failures+ FROM starts+ LEFT JOIN completed USING (correlation_id)+ GROUP BY starts.dateSQL}