: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(error-tracking): drop stale spike notifications (#68137)
Hugues Pouillot5ff87e4b7523
diff --git a/rust/cymbal/src/modes/notifications/issue_handler.rs b/rust/cymbal/src/modes/notifications/issue_handler.rsindex f53b1419a174..268081575d8a 100644--- a/rust/cymbal/src/modes/notifications/issue_handler.rs+++ b/rust/cymbal/src/modes/notifications/issue_handler.rs@@ -1,5 +1,5 @@use chrono::{DateTime, Utc};-use tracing::warn;+use tracing::{debug, warn};use uuid::Uuid;use crate::core::{@@ -115,9 +115,8 @@ pub async fn handle_issue_spiking(issue: issue_snapshot,event_properties,} = issue;- let issue = issue_from_notification(meta.team_id, issue_id, issue_snapshot);- persist_spike_event(+ match persist_spike_event(context,meta.notification_id,meta.team_id,@@ -125,7 +124,31 @@ pub async fn handle_issue_spiking(computed_baseline,current_bucket_value,)- .await?;+ .await?+ {+ PersistSpikeEventResult::Inserted => {}+ PersistSpikeEventResult::AlreadyPersisted => {+ debug!(+ notification_id = %meta.notification_id,+ team_id = meta.team_id,+ issue_id = %issue_id,+ "dropping duplicate spike notification"+ );+ return Ok(());+ }+ PersistSpikeEventResult::MissingIssue => {+ warn!(+ notification_id = %meta.notification_id,+ team_id = meta.team_id,+ issue_id = %issue_id,+ "dropping spike notification for missing issue"+ );+ return Ok(());+ }+ }++ let issue = issue_from_notification(meta.team_id, issue_id, issue_snapshot);+send_issue_spiking_internal_event(&context.cyclotron_producer,&context.internal_events_topic,@@ -146,6 +169,12 @@ pub async fn handle_issue_spiking(Ok(())}+enum PersistSpikeEventResult {+ Inserted,+ AlreadyPersisted,+ MissingIssue,+}+fn issue_from_notification(team_id: i32,issue_id: Uuid,@@ -168,12 +197,17 @@ async fn persist_spike_event(issue_id: Uuid,computed_baseline: f64,current_bucket_value: f64,-) -> Result<(), UnhandledError> {+) -> Result<PersistSpikeEventResult, UnhandledError> {let now = Utc::now();- sqlx::query(- r#"INSERT INTO posthog_errortrackingspikeevent+ let result = sqlx::query(+ r#"WITH existing_issue AS (+ SELECT 1 FROM posthog_errortrackingissue+ WHERE team_id = $2 AND id = $3+ FOR KEY SHARE+ )+ INSERT INTO posthog_errortrackingspikeevent(id, team_id, issue_id, detected_at, computed_baseline, current_bucket_value)- VALUES ($1, $2, $3, $4, $5, $6)+ SELECT $1, $2, $3, $4, $5, $6 FROM existing_issueON CONFLICT (id) DO NOTHING"#,).bind(notification_id)@@ -185,7 +219,25 @@ async fn persist_spike_event(.execute(&context.posthog_pool).await?;- Ok(())+ if result.rows_affected() > 0 {+ return Ok(PersistSpikeEventResult::Inserted);+ }++ let issue_exists: bool = sqlx::query_scalar(+ r#"SELECT EXISTS(+ SELECT 1 FROM posthog_errortrackingissue WHERE team_id = $1 AND id = $2+ )"#,+ )+ .bind(team_id)+ .bind(issue_id)+ .fetch_one(&context.posthog_pool)+ .await?;++ if issue_exists {+ return Ok(PersistSpikeEventResult::AlreadyPersisted);+ }++ Ok(PersistSpikeEventResult::MissingIssue)}fn parse_notification_timestamp(event_timestamp: &str, event_uuid: Uuid) -> DateTime<Utc> {