Skip to content

: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.

fix(logs): remove highly compressable/static fields from log row bytes (#63562)

Frank Hamand71c1db2d873f
diff --git a/rust/capture-logs/src/log_record.rs b/rust/capture-logs/src/log_record.rs
index 8dfed3639952..d9dcc65b3f04 100644
--- a/rust/capture-logs/src/log_record.rs
+++ b/rust/capture-logs/src/log_record.rs
@@ -47,14 +47,18 @@ pub struct KafkaLogRow {
/// is the raw HTTP body size for the whole batch.
pub fn compute_kafka_log_row_bytes(row: &KafkaLogRow) -> i64 {
let mut total: usize = 0;
- total = total.saturating_add(row.uuid.len());
- total = total.saturating_add(row.trace_id.len());
- total = total.saturating_add(row.span_id.len());
total = total.saturating_add(row.body.len());
- total = total.saturating_add(row.severity_text.len());
- total = total.saturating_add(row.service_name.len());
- total = total.saturating_add(row.instrumentation_scope.len());
- total = total.saturating_add(row.event_name.len());
+
+ // by default exclude instrumentation_scope and event_name as they are
+ // low cardinality and highly compressible, but add them if they are large
+ // to prevent abuse
+ if row.instrumentation_scope.len() > 50 {
+ total = total.saturating_add(row.instrumentation_scope.len());
+ }
+ if row.event_name.len() > 50 {
+ total = total.saturating_add(row.event_name.len());
+ }
+
for (k, v) in &row.resource_attributes {
total = total.saturating_add(k.len()).saturating_add(v.len());
}
@@ -392,11 +396,10 @@ mod tests {
#[test]
fn test_compute_kafka_log_row_bytes_sums_string_and_map_lengths() {
let row = sample_row();
- // string fields: uuid(9) + trace_id(3) + span_id(3) + body(5) + severity_text(4)
- // + service_name(3) + instrumentation_scope(7) + event_name(3) = 37
+ // string fields: body(5)
// maps: resource_attributes "host.name"(9)+"localhost"(9)=18; attributes "k"(1)+"v"(1)=2
- // total = 37 + 18 + 2 = 57
- assert_eq!(compute_kafka_log_row_bytes(&row), 57);
+ // total = 5 + 18 + 2 = 25
+ assert_eq!(compute_kafka_log_row_bytes(&row), 25);
}
fn sample_row_bytes() -> u64 {