: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): truncate cymbal issue name to bound kafka message size (#73218)
Catalin00d8caed3d99
diff --git a/rust/cymbal/src/modes/processing/issue_resolution.rs b/rust/cymbal/src/modes/processing/issue_resolution.rsindex d99c440bde80..47d80b0a7936 100644--- a/rust/cymbal/src/modes/processing/issue_resolution.rs+++ b/rust/cymbal/src/modes/processing/issue_resolution.rs@@ -26,6 +26,12 @@ use crate::{const ERROR_TRACKING_EVENT_PROPERTIES_KEY_PREFIX: &str = "error_tracking:event_properties:v1";+// Upper bounds on the issue name and description we persist. Exception types and values are+// attacker-controlled and occasionally enormous (crash reporters embedding base64 minidumps,+// serialized blobs, etc.), so we cap both before writing to Postgres and Kafka.+const MAX_ISSUE_NAME_CHARS: usize = 255;+const MAX_ISSUE_DESCRIPTION_CHARS: usize = 255;+#[derive(Debug, Clone)]pub struct IssueFingerprintOverride {pub id: Uuid,@@ -139,8 +145,15 @@ impl Issue {whereE: sqlx::Executor<'c, Database = sqlx::Postgres>,{- // Truncate the description to 255 characters, we've seen very large exception values- let description = description.chars().take(255).collect();+ // Truncate name and description, we've seen very large exception values (e.g. crash+ // reporters that stuff an entire base64-encoded minidump into the exception type).+ // An unbounded name also produces oversized fingerprint-issue-state Kafka messages,+ // which fail the produce with MessageSizeTooLarge.+ let name = name.chars().take(MAX_ISSUE_NAME_CHARS).collect();+ let description = description+ .chars()+ .take(MAX_ISSUE_DESCRIPTION_CHARS)+ .collect();let issue = Self {id: Uuid::now_v7(),team_id,diff --git a/rust/cymbal/src/modes/processing/types/event.rs b/rust/cymbal/src/modes/processing/types/event.rsindex 84c51830378f..2102b988118c 100644--- a/rust/cymbal/src/modes/processing/types/event.rs+++ b/rust/cymbal/src/modes/processing/types/event.rs@@ -70,15 +70,25 @@ impl TryFrom<ClickHouseEvent> for AnyEvent {#[cfg(test)]mod test {- use crate::types::exception_event::{ExceptionEvent, Parsed, MAX_EXCEPTION_VALUE_LENGTH};+ use crate::types::exception_event::{+ ExceptionEvent, Parsed, MAX_EXCEPTION_TYPE_LENGTH, MAX_EXCEPTION_VALUE_LENGTH,+ MAX_ISSUE_NAME_LENGTH,+ };use super::*;use uuid::Uuid;fn make_exception_event(exception_value: &str) -> ClickHouseEvent {+ make_exception_event_with_type("Error", exception_value)+ }++ fn make_exception_event_with_type(+ exception_type: &str,+ exception_value: &str,+ ) -> ClickHouseEvent {let props = serde_json::json!({"$exception_list": [{- "type": "Error",+ "type": exception_type,"value": exception_value}]});@@ -118,7 +128,60 @@ mod test {let any_event = AnyEvent::try_from(event).unwrap();let exc_props = ExceptionEvent::<Parsed>::try_from(any_event).unwrap();- let expected = format!("{}...", "x".repeat(MAX_EXCEPTION_VALUE_LENGTH));- assert_eq!(exc_props.exception_list()[0].exception_message, expected);+ let value = &exc_props.exception_list()[0].exception_message;+ let expected = format!("{}...", "x".repeat(MAX_EXCEPTION_VALUE_LENGTH - 3));+ assert_eq!(*value, expected);+ // The ellipsis must not push the result past the cap.+ assert!(value.len() <= MAX_EXCEPTION_VALUE_LENGTH);+ }++ #[test]+ fn test_exception_type_truncation() {+ // Crash reporters that stuff a base64 minidump into the type field would otherwise+ // produce a multi-hundred-KB type, bloating downstream Kafka payloads.+ let long_type = "T".repeat(MAX_EXCEPTION_TYPE_LENGTH + 100);+ let event = make_exception_event_with_type(&long_type, "boom");+ let any_event = AnyEvent::try_from(event).unwrap();+ let exc_props = ExceptionEvent::<Parsed>::try_from(any_event).unwrap();++ let ty = &exc_props.exception_list()[0].exception_type;+ let expected = format!("{}...", "T".repeat(MAX_EXCEPTION_TYPE_LENGTH - 3));+ assert_eq!(*ty, expected);+ assert!(ty.len() <= MAX_EXCEPTION_TYPE_LENGTH);+ }++ #[test]+ fn test_exception_type_truncation_respects_utf8_byte_limit() {+ let long_type = "🦔".repeat(MAX_EXCEPTION_TYPE_LENGTH);+ let event = make_exception_event_with_type(&long_type, "boom");+ let any_event = AnyEvent::try_from(event).unwrap();+ let exc_props = ExceptionEvent::<Parsed>::try_from(any_event).unwrap();++ let ty = &exc_props.exception_list()[0].exception_type;+ assert!(ty.ends_with("..."));+ assert!(ty.len() <= MAX_EXCEPTION_TYPE_LENGTH);+ assert!(ty.is_char_boundary(ty.len()));+ }++ #[test]+ fn test_proposed_issue_name_truncation() {+ // $issue_name is sender-controlled and reaches the notification Kafka payload untruncated,+ // so an oversized name must be bounded at parse time.+ let long_name = "N".repeat(MAX_ISSUE_NAME_LENGTH + 100);+ let props = serde_json::json!({+ "$issue_name": long_name,+ "$exception_list": [{ "type": "Error", "value": "boom" }],+ });+ let mut event = make_exception_event("boom");+ event.properties = Some(props.to_string());+ let any_event = AnyEvent::try_from(event).unwrap();+ let exc_props = ExceptionEvent::<Parsed>::try_from(any_event).unwrap();++ let name = exc_props.proposed_issue_name().unwrap();+ assert_eq!(+ name,+ format!("{}...", "N".repeat(MAX_ISSUE_NAME_LENGTH - 3))+ );+ assert!(name.len() <= MAX_ISSUE_NAME_LENGTH);}}diff --git a/rust/cymbal/src/modes/processing/types/exception_event.rs b/rust/cymbal/src/modes/processing/types/exception_event.rsindex f1d494bf7fcf..0b212f34b901 100644--- a/rust/cymbal/src/modes/processing/types/exception_event.rs+++ b/rust/cymbal/src/modes/processing/types/exception_event.rs@@ -18,6 +18,32 @@ use crate::{use super::ProcessedExceptionPropertiesWire;pub const MAX_EXCEPTION_VALUE_LENGTH: usize = 10_000;+// Exception types are attacker-controlled and occasionally enormous (e.g. crash reporters that+// embed a base64-encoded minidump as the exception type). A real type is a short class name, so+// bound it tightly: an unbounded type bloats $exception_list / $exception_types and every+// downstream Kafka payload past message.max.bytes.+pub const MAX_EXCEPTION_TYPE_LENGTH: usize = 255;+// $issue_name / $issue_description are sender-controlled and flow untruncated into both the+// ClickHouse properties and the error-tracking notification Kafka payload, so bound them the+// same way the persisted issue is bounded.+pub const MAX_ISSUE_NAME_LENGTH: usize = 255;+pub const MAX_ISSUE_DESCRIPTION_LENGTH: usize = 255;++/// Truncate `value` in place to at most `max_bytes` (including the ellipsis), on a UTF-8 char+/// boundary, appending an ellipsis when anything was dropped.+fn truncate_with_ellipsis(value: &mut String, max_bytes: usize) {+ if value.len() <= max_bytes {+ return;+ }+ // Reserve room for the ellipsis suffix so the result never exceeds max_bytes.+ let ellipsis = &"..."[..max_bytes.min(3)];+ let mut truncate_at = max_bytes - ellipsis.len();+ while !value.is_char_boundary(truncate_at) {+ truncate_at -= 1;+ }+ value.truncate(truncate_at);+ value.push_str(ellipsis);+}pub type PipelineItem<S> = Result<ExceptionEvent<S>, EventError>;@@ -536,20 +562,18 @@ impl TryFrom<AnyEvent> for ExceptionEvent<Parsed> {}for exception in raw.exception_list.iter_mut() {- if exception.exception_message.len() > MAX_EXCEPTION_VALUE_LENGTH {- let truncate_at = exception- .exception_message- .char_indices()- .take_while(|(index, _)| *index < MAX_EXCEPTION_VALUE_LENGTH)- .last()- .map(|(index, character)| index + character.len_utf8())- .unwrap_or(0);- exception.exception_message.truncate(truncate_at);- exception.exception_message.push_str("...");- }+ truncate_with_ellipsis(&mut exception.exception_message, MAX_EXCEPTION_VALUE_LENGTH);+ truncate_with_ellipsis(&mut exception.exception_type, MAX_EXCEPTION_TYPE_LENGTH);exception.exception_id = Some(Uuid::now_v7().to_string());}+ if let Some(name) = raw.issue_name.as_mut() {+ truncate_with_ellipsis(name, MAX_ISSUE_NAME_LENGTH);+ }+ if let Some(description) = raw.issue_description.as_mut() {+ truncate_with_ellipsis(description, MAX_ISSUE_DESCRIPTION_LENGTH);+ }+for key in ["$exception_sources","$exception_types",