: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(usage-ingestion): delimit usage counter scopes (#96006)
Ben White51d1cf9bf1db
diff --git a/rust/usage-ingestion/src/counters.rs b/rust/usage-ingestion/src/counters.rsindex 767f22ca4dfc..dbd08621beae 100644--- a/rust/usage-ingestion/src/counters.rs+++ b/rust/usage-ingestion/src/counters.rs@@ -241,8 +241,8 @@ impl CounterStore for RedisCounterStore {pub fn counter_key(scope: &CounterScope, bucket: Bucket) -> String {let scope = match scope {- CounterScope::Team(team_id) => format!("team:{team_id}"),- CounterScope::Organization(organization_id) => format!("org:{organization_id}"),+ CounterScope::Team(team_id) => format!("team={team_id}"),+ CounterScope::Organization(organization_id) => format!("org={organization_id}"),};format!("usage:v1:{{{scope}}}:{}:{}",@@ -420,10 +420,17 @@ mod tests {assert!(team.entries.values().all(|quantity| *quantity == 5));assert_eq!(counter_key(&CounterScope::Team(42), Bucket::Hour(477_336)),- "usage:v1:{team:42}:h:477336"+ "usage:v1:{team=42}:h:477336"+ );+ assert!(counter_key(&CounterScope::Team(42), Bucket::Hour(477_336)).contains("{team=42}"));+ assert!(counter_key(&CounterScope::Team(42), Bucket::Day(19_889)).contains("{team=42}"));+ assert_eq!(+ counter_key(+ &CounterScope::Organization(organization_id),+ Bucket::Day(19_889)+ ),+ "usage:v1:{org=00000000-0000-0000-0000-000000000000}:d:19889");- assert!(counter_key(&CounterScope::Team(42), Bucket::Hour(477_336)).contains("{team:42}"));- assert!(counter_key(&CounterScope::Team(42), Bucket::Day(19_889)).contains("{team:42}"));}#[test]