: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
chore(feature-flags): reduce hot-path log noise, keep metrics coverage (#74226)
Ben Whiteef0a368ec78d
diff --git a/rust/feature-flags/src/flags/flag_matching.rs b/rust/feature-flags/src/flags/flag_matching.rsindex 553ab2c669ed..529e1c626bc9 100644--- a/rust/feature-flags/src/flags/flag_matching.rs+++ b/rust/feature-flags/src/flags/flag_matching.rs@@ -25,10 +25,11 @@ use crate::handler::with_canonical_log;use crate::metrics::consts::{DB_PERSON_AND_GROUP_PROPERTIES_READS_COUNTER, FLAG_BATCH_EVALUATION_COUNTER,FLAG_BATCH_EVALUATION_TIME, FLAG_BATCH_SIZE, FLAG_COHORT_SOURCE_COUNTER,- FLAG_DB_PROPERTIES_FETCH_TIME, FLAG_EVALUATE_ALL_CONDITIONS_TIME,- FLAG_EVALUATION_ERROR_COUNTER, FLAG_EVALUATION_TIME, FLAG_EXPERIENCE_CONTINUITY_OPTIMIZED,- FLAG_EXPERIENCE_CONTINUITY_REQUESTS_COUNTER, FLAG_GET_MATCH_TIME, FLAG_GROUP_CACHE_FETCH_TIME,- FLAG_GROUP_DB_FETCH_TIME, FLAG_HASH_KEY_PROCESSING_TIME, FLAG_HASH_KEY_WRITES_COUNTER,+ FLAG_CONDITION_SKIPPED_COUNTER, FLAG_DB_PROPERTIES_FETCH_TIME,+ FLAG_EVALUATE_ALL_CONDITIONS_TIME, FLAG_EVALUATION_ERROR_COUNTER, FLAG_EVALUATION_TIME,+ FLAG_EXPERIENCE_CONTINUITY_OPTIMIZED, FLAG_EXPERIENCE_CONTINUITY_REQUESTS_COUNTER,+ FLAG_GET_MATCH_TIME, FLAG_GROUP_CACHE_FETCH_TIME, FLAG_GROUP_DB_FETCH_TIME,+ FLAG_HASH_KEY_PROCESSING_TIME, FLAG_HASH_KEY_WRITES_COUNTER,FLAG_REALTIME_COHORT_QUERY_ERROR_COUNTER, FLAG_REALTIME_COHORT_QUERY_TIME,PROPERTY_CACHE_HITS_COUNTER, PROPERTY_CACHE_MISSES_COUNTER,};@@ -45,7 +46,7 @@ use rayon::prelude::*;use serde_json::Value;use std::collections::{HashMap, HashSet};use std::sync::Arc;-use tracing::{error, instrument, warn};+use tracing::{debug, error, instrument, warn};use uuid::Uuid;const DEFAULT_PARALLEL_EVAL_THRESHOLD: usize = 100;@@ -1383,8 +1384,13 @@ impl FeatureFlagMatcher {.as_ref().is_none_or(|device_id| device_id.is_empty()){+ inc(+ FLAG_CONDITION_SKIPPED_COUNTER,+ &[("reason".to_string(), "missing_device_id".to_string())],+ 1,+ );with_canonical_log(|log| {- tracing::warn!(+ tracing::debug!(flag_key = %flag.key,team_id = %flag.team_id,condition_index = %index,@@ -1425,7 +1431,12 @@ impl FeatureFlagMatcher {_ => false,});if !has_group_key {- warn!(+ inc(+ FLAG_CONDITION_SKIPPED_COUNTER,+ &[("reason".to_string(), "missing_group_type".to_string())],+ 1,+ );+ debug!(flag_key = %flag.key,team_id = %flag.team_id,condition_index = %index,diff --git a/rust/feature-flags/src/flags/flag_matching_utils.rs b/rust/feature-flags/src/flags/flag_matching_utils.rsindex a2240b42af56..fb05e6e06cb8 100644--- a/rust/feature-flags/src/flags/flag_matching_utils.rs+++ b/rust/feature-flags/src/flags/flag_matching_utils.rs@@ -16,7 +16,7 @@ use once_cell::sync::Lazy;use serde_json::Value;use sha1::{Digest, Sha1};use sqlx::{Acquire, Row};-use tracing::{info, instrument, warn};+use tracing::{debug, instrument, warn};// Add thread-local imports for test-specific counter#[cfg(test)]@@ -206,7 +206,7 @@ async fn fetch_person_and_cohorts(let mut conn = match conn_result {Ok(conn) => {- info!(+ debug!(conn_acquisition_ms = conn_acquisition_duration.as_millis(),"persons_reader connection acquired for person+cohort query");@@ -270,7 +270,7 @@ async fn fetch_person_and_cohorts("Slow person query detected");} else {- info!(+ debug!(duration_ms = person_query_duration.as_millis(),distinct_id = distinct_id,team_id = team_id,@@ -317,7 +317,7 @@ async fn fetch_person_and_cohorts("Slow cohort query detected");} else {- info!(+ debug!(duration_ms = cohort_query_duration.as_millis(),person_id = person.id,cohort_count = static_cohort_ids.len(),@@ -377,7 +377,7 @@ async fn fetch_group_properties(let mut conn = match conn_result {Ok(conn) => {- info!(+ debug!(conn_acquisition_ms = conn_acquisition_duration.as_millis(),"persons_reader connection acquired for group query");@@ -454,7 +454,7 @@ async fn fetch_group_properties("Slow group query detected");} else {- info!(+ debug!(duration_ms = group_query_duration.as_millis(),team_id = team_id,group_pair_count = group_type_to_key.len(),@@ -562,7 +562,7 @@ pub async fn fetch_and_locally_cache_all_relevant_properties(// Log pool stats before attempting connectionsif let Some(stats) = reader.as_ref().get_pool_stats() {- info!(+ debug!(pool_size = stats.size,pool_idle = stats.num_idle,pool_in_use = stats.size.saturating_sub(stats.num_idle as u32),@@ -844,7 +844,7 @@ async fn try_get_feature_flag_hash_key_overrides("Slow hash override lookup query detected");} else {- info!(+ debug!(duration_ms = query_duration.as_millis(),team_id = team_id,distinct_id_count = distinct_id_and_hash_key_override.len(),@@ -1059,7 +1059,7 @@ async fn try_set_feature_flag_hash_key_overrides("Slow person data query detected in set_hash_key_overrides");} else {- info!(+ debug!(duration_ms = person_query_duration.as_millis(),team_id = team_id,distinct_id_count = distinct_ids.len(),@@ -1133,7 +1133,7 @@ async fn try_set_feature_flag_hash_key_overrides("Slow active flags query detected in set_hash_key_overrides");} else {- info!(+ debug!(duration_ms = flags_query_duration.as_millis(),team_id = team_id,"Active flags query completed in set_hash_key_overrides"@@ -1200,7 +1200,7 @@ async fn try_set_feature_flag_hash_key_overrides("Slow bulk insert query detected in set_hash_key_overrides");} else {- info!(+ debug!(duration_ms = insert_duration.as_millis(),team_id = team_id,row_count = person_ids_to_insert.len(),diff --git a/rust/feature-flags/src/handler/billing.rs b/rust/feature-flags/src/handler/billing.rsindex 874e5af08456..34f5d0edb2c3 100644--- a/rust/feature-flags/src/handler/billing.rs+++ b/rust/feature-flags/src/handler/billing.rs@@ -4,7 +4,9 @@ use crate::{flag_analytics::is_billable_flag_key, flag_models::FeatureFlagList,flag_request::FlagRequestType,},+ metrics::consts::FLAG_QUOTA_LIMITED_COUNTER,};+use common_metrics::inc;use limiters::redis::ServiceName;use std::collections::HashMap;@@ -21,6 +23,7 @@ pub async fn check_limits(.await;if billing_limited {+ inc(FLAG_QUOTA_LIMITED_COUNTER, &[], 1);return Ok(Some(FlagsResponse::new(false,HashMap::new(),diff --git a/rust/feature-flags/src/handler/mod.rs b/rust/feature-flags/src/handler/mod.rsindex 4f833550d551..eb4d2471e8d8 100644--- a/rust/feature-flags/src/handler/mod.rs+++ b/rust/feature-flags/src/handler/mod.rs@@ -26,7 +26,7 @@ use crate::{team::team_models::Team,};use std::collections::HashMap;-use tracing::{instrument, warn};+use tracing::{debug, instrument};#[cfg(test)]use crate::handler::test_metrics::{histogram, inc};@@ -218,7 +218,7 @@ async fn process_request_inner(};if let Some(quota_limited_response) = billing_limited {- warn!("Request quota limited");+ debug!("Request quota limited");with_canonical_log(|log| log.quota_limited = true);quota_limited_response} else {diff --git a/rust/feature-flags/src/metrics/consts.rs b/rust/feature-flags/src/metrics/consts.rsindex ca97099537a0..0e6ce4c3f1a2 100644--- a/rust/feature-flags/src/metrics/consts.rs+++ b/rust/feature-flags/src/metrics/consts.rs@@ -390,6 +390,13 @@ pub const FLAG_DEPENDENCY_GRAPH_BUILD_COUNTER: &str = "flags_dependency_graph_bupub const FLAG_DEPENDENCY_GRAPH_BUILD_TIME: &str = "flags_dependency_graph_build_ms";pub const FLAG_MISSING_REQUESTED_FLAG_KEY: &str = "missing_requested_flag_key";+// Requests short-circuited because the team is over its billing quota.+pub const FLAG_QUOTA_LIMITED_COUNTER: &str = "flags_quota_limited_total";++// Conditions skipped during evaluation because required context was absent.+// Labels: reason (missing_device_id, missing_group_type)+pub const FLAG_CONDITION_SKIPPED_COUNTER: &str = "flags_condition_skipped_total";+// Tombstone metric for tracking "impossible" failures that should never happen in production// Different failure types are tracked via the "failure_type" labelpub const TOMBSTONE_COUNTER: &str = "posthog_tombstone_total";diff --git a/rust/feature-flags/src/utils/graph_utils.rs b/rust/feature-flags/src/utils/graph_utils.rsindex a0853dfca5d9..1b9ecd7e6a5f 100644--- a/rust/feature-flags/src/utils/graph_utils.rs+++ b/rust/feature-flags/src/utils/graph_utils.rs@@ -12,11 +12,11 @@ use crate::metrics::consts::{FLAG_EVALUATION_ERROR_COUNTER, FLAG_MISSING_REQUESTED_FLAG_KEY,};use common_metrics::{inc, timing_guard};-use tracing::warn;+use tracing::debug;-/// Logs a warning and increments the error counter when a requested flag key is not found.+/// Increments the error counter (and logs at debug) when a requested flag key is not found.fn warn_missing_flag_key(key: &str) {- warn!("Requested flag key not found: {}", key);+ debug!("Requested flag key not found: {}", key);inc(FLAG_EVALUATION_ERROR_COUNTER,&[(