: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(flags): don't report transient cross-region sync blips to error tracking (#71793)
posthog[bot]1ede72ecc71d
diff --git a/products/feature_flags/backend/cross_region_flag_sync.py b/products/feature_flags/backend/cross_region_flag_sync.pyindex d4c3089535f2..7586f2bed8d0 100644--- a/products/feature_flags/backend/cross_region_flag_sync.py+++ b/products/feature_flags/backend/cross_region_flag_sync.py@@ -35,9 +35,10 @@ DOGFOOD_SELF_TEAM_ID = 2_FLAGS_DEFINITIONS_PATH = "/flags/definitions"_REQUEST_TIMEOUT_SECONDS = (3, 10) # (connect, read)-# Throttle window for capturing an unexpected failure (network error, bad JSON) to-# PostHog error tracking, shared across the 30s schedule so a sustained outage-# reports once per window instead of once per tick.+# Throttle window for capturing a genuinely unexpected failure (bad JSON, an+# unexpected request error) to PostHog error tracking, shared across the 30s schedule+# so a sustained outage reports once per window instead of once per tick. Expected+# transient network blips (connection/timeout/proxy errors) are logged, not captured._SYNC_FAILURE_CAPTURE_THROTTLE_KEY = "cross_region_dogfood_flags_sync_capture_throttle"_SYNC_FAILURE_CAPTURE_THROTTLE_TTL = 300 # seconds@@ -70,6 +71,12 @@ def sync_cross_region_dogfood_flags() -> None:headers=headers,timeout=_REQUEST_TIMEOUT_SECONDS,)+ except (requests.ConnectionError, requests.Timeout) as e:+ # Expected transient cross-region blips (proxy timeouts, connection resets).+ # ProxyError subclasses ConnectionError, so it's covered here. The best-effort+ # poll self-heals on the next 30s tick, so log without reporting to error tracking.+ logger.warning("cross_region_dogfood_flags_sync_request_failed", error=str(e))+ returnexcept requests.RequestException as e:capture_exception_throttled(_SYNC_FAILURE_CAPTURE_THROTTLE_KEY, e, _SYNC_FAILURE_CAPTURE_THROTTLE_TTL)logger.warning("cross_region_dogfood_flags_sync_request_failed", error=str(e))diff --git a/products/feature_flags/backend/test/test_cross_region_flag_sync.py b/products/feature_flags/backend/test/test_cross_region_flag_sync.pyindex ac01d61c4dc1..f48de482e0e7 100644--- a/products/feature_flags/backend/test/test_cross_region_flag_sync.py+++ b/products/feature_flags/backend/test/test_cross_region_flag_sync.py@@ -76,16 +76,39 @@ class TestSyncCrossRegionDogfoodFlags(BaseTest):# conditional GET, silently degrading to a full transfer on every poll.assert flag_definitions_hypercache.get_etag(DOGFOOD_SELF_TEAM_ID)- def test_fails_safe_on_request_exception(self):- # A crash here would take down the Celery task every 30s; the existing- # cache entry must survive an upstream hiccup instead.+ @parameterized.expand(+ [+ ("connection_error", requests.ConnectionError("boom")),+ ("timeout", requests.Timeout("slow")),+ ("proxy_error", requests.exceptions.ProxyError("proxy down")),+ ]+ )+ def test_transient_network_error_is_not_captured(self, _name, exc):+ # These self-heal on the next 30s tick, so they must fail safe (keep the+ # cached entry) without reporting to error tracking -- otherwise every blip+ # spawns a "new issue".+ with (+ patch(f"{_MODULE}.requests.get", side_effect=exc),+ patch.object(flag_definitions_hypercache, "set_cache_value") as mock_set,+ patch(f"{_MODULE}.capture_exception_throttled") as mock_capture,+ ):+ sync_cross_region_dogfood_flags()++ mock_set.assert_not_called()+ mock_capture.assert_not_called()++ def test_unexpected_request_error_is_captured(self):+ # A non-network RequestException (e.g. a malformed URL) is genuinely+ # unexpected, so it should still surface in error tracking.with (- patch(f"{_MODULE}.requests.get", side_effect=requests.ConnectionError("boom")),+ patch(f"{_MODULE}.requests.get", side_effect=requests.RequestException("unexpected")),patch.object(flag_definitions_hypercache, "set_cache_value") as mock_set,+ patch(f"{_MODULE}.capture_exception_throttled") as mock_capture,):sync_cross_region_dogfood_flags()mock_set.assert_not_called()+ mock_capture.assert_called_once()@parameterized.expand([