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.

feat(propvals): support prefix entries in EXCLUDED_PROPERTY_KEYS (#124339)

Andy Zhaoa5f684d89d56
diff --git a/rust/property-vals-rs/src/config.rs b/rust/property-vals-rs/src/config.rs
index ad4b277f30fb..d92f492a5e01 100644
--- a/rust/property-vals-rs/src/config.rs
+++ b/rust/property-vals-rs/src/config.rs
@@ -121,11 +121,16 @@ impl FromStr for TeamList {
#[derive(Clone, Default)]
pub struct ExcludedPropertyKeys {
pub keys: Arc<HashSet<String>>,
+ pub prefixes: Arc<Vec<String>>,
}
impl ExcludedPropertyKeys {
pub fn contains(&self, key: &str) -> bool {
self.keys.contains(key)
+ || self
+ .prefixes
+ .iter()
+ .any(|prefix| key.starts_with(prefix.as_str()))
}
}
@@ -133,13 +138,19 @@ impl FromStr for ExcludedPropertyKeys {
type Err = Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
- let keys: HashSet<String> = s
- .split(',')
- .map(|k| k.trim().to_string())
- .filter(|k| !k.is_empty())
- .collect();
+ let mut keys = HashSet::new();
+ let mut prefixes = Vec::new();
+ for entry in s.split(',').map(str::trim).filter(|k| !k.is_empty()) {
+ match entry.strip_suffix('*') {
+ Some(prefix) => prefixes.push(prefix.to_string()),
+ None => {
+ keys.insert(entry.to_string());
+ }
+ }
+ }
Ok(ExcludedPropertyKeys {
keys: Arc::new(keys),
+ prefixes: Arc::new(prefixes),
})
}
}
diff --git a/rust/property-vals-rs/src/fan_out.rs b/rust/property-vals-rs/src/fan_out.rs
index ee3d4396fc4c..c5c519846071 100644
--- a/rust/property-vals-rs/src/fan_out.rs
+++ b/rust/property-vals-rs/src/fan_out.rs
@@ -405,13 +405,21 @@ mod tests {
#[test]
fn excluded_event_property_keys_are_skipped() {
- let blob =
- r#"{"$insert_id":"abc-123","$browser":"Chrome","distinct_id":"u1","$session_id":"s1"}"#;
- let exclusions = excluded(&["$insert_id", "distinct_id", "$session_id"]);
+ let blob = r#"{"$insert_id":"abc-123","$browser":"Chrome","distinct_id":"u1","$session_id":"s1","$time":"1","$timezone":"UTC","$feature/new-onboarding":true,"$feature_flag":"new-onboarding"}"#;
+ let exclusions = excluded(&[
+ "$insert_id",
+ "distinct_id",
+ "$session_id",
+ "$time",
+ "$feature/*",
+ ]);
let tuples = fan_out(&event(blob), &exclusions, TEST_CAPS);
- assert_eq!(tuples.len(), 1, "only $browser should survive exclusion");
- assert_eq!(tuples[0].0.property_key, "$browser");
- assert_eq!(tuples[0].0.property_value, "Chrome");
+ let mut keys: Vec<&str> = tuples
+ .iter()
+ .map(|(t, _)| t.property_key.as_str())
+ .collect();
+ keys.sort();
+ assert_eq!(keys, ["$browser", "$feature_flag", "$timezone"]);
}
#[test]