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(warehouse-sources): stop the SQL row-count probe flooding error tracking (#105584)

Tom Owers032f6506ca31
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/implementation.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/implementation.py
index d32b41f6e78b..e86f919d41f6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/implementation.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/implementation.py
@@ -32,8 +32,6 @@ from typing import Any, Generic, Protocol, TypeVar
from structlog.types import FilteringBoundLogger
-from posthog.exceptions_capture import capture_exception
-
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.consts import (
DEFAULT_CHUNK_SIZE,
DEFAULT_TABLE_SIZE_BYTES,
@@ -269,8 +267,12 @@ class SQLSourceImplementation(Generic[ConfigT, ConnT, CursorT], ABC):
logger.debug(f"get_rows_to_sync: rows_to_sync_int={rows_to_sync_int}")
return rows_to_sync_int
except Exception as e:
+ # This COUNT(*) is a best-effort estimate for progress reporting and partition sizing.
+ # It shares its FROM/WHERE with the real streaming query, so any genuine problem
+ # (missing table, permissions, a dropped connection) resurfaces there and is classified
+ # through the normal retryable/non-retryable path. Capturing it here too would only
+ # flood error tracking with handled duplicates, so log at debug and fall back to 0.
logger.debug(f"get_rows_to_sync: Error: {e}. Using 0 as rows to sync", exc_info=e)
- capture_exception(e)
return 0
def fetch_average_row_size(
@@ -361,11 +363,13 @@ class SQLSourceImplementation(Generic[ConfigT, ConnT, CursorT], ABC):
cursor, schema, table_name, inner_query, inner_query_args, logger
)
except Exception as e:
+ # Row-size sampling is a best-effort optimization, same as `get_rows_to_sync` above:
+ # a genuine problem resurfaces in the real streaming query and is classified there, so
+ # capturing it here too would only flood error tracking with handled duplicates.
logger.debug(
f"get_chunk_size: Error: {e}. Using default_chunk_size={default_chunk_size}",
exc_info=e,
)
- capture_exception(e)
return default_chunk_size
if row_size_bytes is None or row_size_bytes <= 0:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_implementation.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_implementation.py
index f03801f128af..a9b075cb05ab 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_implementation.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/sql/tests/test_implementation.py
@@ -26,6 +26,14 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.sql
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceInputs, SourceResponse
+# `capture_exception` isn't imported in `implementation` anymore — patched here (not at
+# `posthog.exceptions_capture.capture_exception`) so the mock still catches a call if that
+# import, and a call site, are ever reintroduced. A `from X import Y` binding is a separate
+# reference from the source; patching the source wouldn't intercept it.
+_CAPTURE_EXCEPTION_TARGET = (
+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.sql.implementation.capture_exception"
+)
+
@dataclasses.dataclass
class _FakeConfig(Config):
@@ -94,8 +102,7 @@ class TestGetPartitionSettings:
def test_returns_none_when_fetch_raises(self, logger):
impl = _FakeImplementation(raises_on_stats=True)
- module = "products.warehouse_sources.backend.temporal.data_imports.sources.common.sql.implementation"
- with patch(f"{module}.capture_exception") as mock_capture:
+ with patch(_CAPTURE_EXCEPTION_TARGET, create=True) as mock_capture:
assert impl.get_partition_settings(MagicMock(), "db", "t", logger) is None
# We still called through to the driver hook.
assert len(impl.fetch_table_stats_calls) == 1
@@ -173,6 +180,15 @@ class TestGetChunkSize:
impl = _FakeImplementation(raises_on_row_size=True)
assert impl.get_chunk_size(MagicMock(), "db", "t", "SELECT 1", {}, logger, default_chunk_size=99) == 99
+ def test_does_not_report_error_to_tracking_on_exception(self, logger):
+ impl = _FakeImplementation(raises_on_row_size=True)
+ with patch(_CAPTURE_EXCEPTION_TARGET, create=True) as mock_capture:
+ impl.get_chunk_size(MagicMock(), "db", "t", "SELECT 1", {}, logger, default_chunk_size=99)
+ # Best-effort probe: a raised row-size query must not flood error tracking — it degrades
+ # to the default chunk size here and resurfaces in the real streaming query if it's a
+ # genuine problem.
+ mock_capture.assert_not_called()
+
def test_passes_inner_query_through(self, logger):
impl = _FakeImplementation(row_size=500)
cursor = MagicMock()
@@ -221,3 +237,13 @@ class TestGetRowsToSync:
cursor = MagicMock()
cursor.fetchone.return_value = ("123",)
assert impl.get_rows_to_sync(cursor, "SELECT 1", None, logger) == 123
+
+ def test_does_not_report_error_to_tracking_on_exception(self, logger):
+ impl = _FakeImplementation()
+ cursor = MagicMock()
+ cursor.execute = MagicMock(side_effect=RuntimeError("connection lost"))
+ with patch(_CAPTURE_EXCEPTION_TARGET, create=True) as mock_capture:
+ assert impl.get_rows_to_sync(cursor, "SELECT 1", None, logger) == 0
+ # Best-effort probe: a raised count query must not flood error tracking — it degrades to
+ # 0 here and resurfaces in the real streaming query if it's a genuine problem.
+ mock_capture.assert_not_called()