: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): add per-row retention_days field to capture-logs Avro schema (#73825)
Frank Hamanda66fdac17902
diff --git a/rust/capture-logs/src/avro_schema.rs b/rust/capture-logs/src/avro_schema.rsindex ce404391532f..cdd94d1dc5e3 100644--- a/rust/capture-logs/src/avro_schema.rs+++ b/rust/capture-logs/src/avro_schema.rs@@ -90,6 +90,12 @@ pub const AVRO_SCHEMA: &str = r#""name": "bytes_uncompressed","type": ["null", "long"],"doc": "Logical content size of the row (sum of byte lengths of string/map fields). Used by drop-rule accounting; does not include fixed-width numeric or timestamp fields."+ },+ {+ "name": "retention_days",+ "type": ["null", "int"],+ "default": null,+ "doc": "Per-row retention in days, stamped by the Node consumer from team retention rules. Null when unset — ClickHouse then falls back to the batch `retention-days` header. capture-logs always writes null; it does not evaluate team rules."}]}"#;diff --git a/rust/capture-logs/src/endpoints/datadog.rs b/rust/capture-logs/src/endpoints/datadog.rsindex 9d445c919647..c52074221d87 100644--- a/rust/capture-logs/src/endpoints/datadog.rs+++ b/rust/capture-logs/src/endpoints/datadog.rs@@ -256,6 +256,7 @@ pub fn datadog_log_to_kafka_row(event_name,attributes,bytes_uncompressed: None,+ retention_days: None,}.with_computed_bytes();(row, was_overridden)diff --git a/rust/capture-logs/src/log_record.rs b/rust/capture-logs/src/log_record.rsindex d9dcc65b3f04..baf95f7224db 100644--- a/rust/capture-logs/src/log_record.rs+++ b/rust/capture-logs/src/log_record.rs@@ -39,6 +39,9 @@ pub struct KafkaLogRow {pub event_name: String,pub attributes: HashMap<String, String>,pub bytes_uncompressed: Option<i64>,+ // Per-row retention in days. capture-logs always writes None — the Node consumer stamps+ // this from team retention rules. Null lets ClickHouse fall back to the batch header.+ pub retention_days: Option<i32>,}/// Sum byte lengths of the row's string and map content. Fixed-width fields@@ -175,6 +178,7 @@ impl KafkaLogRow {service_name,attributes,bytes_uncompressed: None,+ retention_days: None,}.with_computed_bytes();debug!("log: {:?}", log_row);@@ -390,6 +394,7 @@ mod tests {event_name: "evt".to_string(),attributes,bytes_uncompressed: None,+ retention_days: None,}}@@ -486,6 +491,37 @@ mod tests {assert_eq!(found_long, Some(expected));}+ #[test]+ fn test_retention_days_serialises_into_avro_payload() {+ use apache_avro::types::Value;++ let mut row = sample_row();+ row.retention_days = Some(30);++ let schema = Schema::parse_str(AVRO_SCHEMA).expect("schema parses");+ let mut writer = Writer::with_codec(&schema, Vec::new(), Codec::Null);+ writer.append_ser(&row).expect("append_ser ok");+ let payload = writer.into_inner().expect("flush ok");++ let reader = Reader::new(payload.as_slice()).expect("reader ok");+ let mut found_int: Option<i32> = None;+ for value in reader {+ let value = value.expect("decode ok");+ if let Value::Record(fields) = value {+ for (name, field_value) in fields {+ if name == "retention_days" {+ if let Value::Union(_, inner) = field_value {+ if let Value::Int(v) = *inner {+ found_int = Some(v);+ }+ }+ }+ }+ }+ }+ assert_eq!(found_int, Some(30));+ }+#[test]fn test_new_populates_bytes_uncompressed() {let log_record = LogRecord::default();