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(data-warehouse): stop billing-check network blips reporting noise (#78551)

Tom Owersc5b65954296c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py b/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py
index 0d8f7642f5e1..d55b04f6ef25 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py
@@ -8,6 +8,7 @@ from django.conf import settings
from django.db.models import F, Q, Sum
from django.db.utils import OperationalError
+import requests
from dateutil import parser
from redis import exceptions as redis_exceptions
from structlog.types import FilteringBoundLogger
@@ -247,6 +248,12 @@ async def will_hit_billing_limit(team_id: int, source: "ExternalDataSource", log
# data is a transient infra blip, and the check already fails open.
await logger.awarning(f"BillingLimits: Database error while checking billing limits, failing open: {e}")
+ return False
+ except requests.exceptions.RequestException as e:
+ # Same rationale as above: a network blip (e.g. a proxy timeout) reaching the
+ # billing service is a transient infra issue, and the check already fails open.
+ await logger.awarning(f"BillingLimits: Network error while checking billing limits, failing open: {e}")
+
return False
except Exception as e:
await logger.adebug(f"BillingLimits: Failed with exception {e}")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py
index 3c8277aa715a..e27d7179322e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py
@@ -12,6 +12,7 @@ from unittest import mock
from django.db.utils import OperationalError
from django.test import override_settings
+import requests
from asgiref.sync import sync_to_async
from redis import exceptions as redis_exceptions
from structlog.types import FilteringBoundLogger
@@ -241,3 +242,26 @@ class TestRowTracking(BaseTest):
assert await self._run(source, 10) is False
mock_capture_exception.assert_not_called()
+
+ @pytest.mark.asyncio
+ async def test_row_tracking_fails_open_on_request_error_without_capturing_exception(self):
+ # A network blip (e.g. a proxy timeout) reaching the billing service is a transient
+ # infra issue, not a bug, and must fail open like any other billing-check error
+ # without being reported to error tracking.
+ source = await self._create_source()
+
+ with (
+ mock.patch("ee.billing.billing_manager.BillingManager.get_billing") as mock_get_billing,
+ mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.row_tracking.capture_exception"
+ ) as mock_capture_exception,
+ ):
+ mock_get_billing.side_effect = requests.exceptions.ProxyError(
+ "HTTPSConnectionPool(host='billing.posthog.com', port=443): Max retries exceeded "
+ "with url: /api/billing (Caused by ProxyError('Cannot connect to proxy.', "
+ "OSError('Tunnel connection failed: 504 Gateway timeout')))"
+ )
+
+ assert await self._run(source, 10) is False
+
+ mock_capture_exception.assert_not_called()