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(mysql): stop reporting best-effort row-size probe failures as noise (#68825)

Tom Owers7c5a1eb7e9af
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/mysql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/mysql.py
index 52a2d6afa71b..12c0e86342c1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/mysql.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/mysql.py
@@ -33,7 +33,10 @@ from pymysql.constants import FIELD_TYPE
from pymysql.cursors import Cursor, SSCursor
from structlog.types import FilteringBoundLogger
-from posthog.exceptions_capture import capture_exception
+# Module-level error-capture seam. This module's best-effort probes (get_rows_to_sync,
+# explain_query, fetch_average_row_size) deliberately do NOT report handled failures here;
+# their guard tests patch `mysql.capture_exception` to enforce that.
+from posthog.exceptions_capture import capture_exception # noqa: F401
from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import (
SourceInputs,
@@ -1086,8 +1089,14 @@ class MySQLImplementation(SQLSourceImplementation[MySQLSourceConfig, pymysql.Con
row_size_bytes = max(row[0] or 0, 1)
return int(row_size_bytes)
except Exception as e:
+ # Row-size sampling is a best-effort probe: on any failure the caller falls back to the
+ # default chunk size and the sync proceeds. A genuine problem (missing table, revoked
+ # permission) resurfaces in the real extraction query and is classified through the normal
+ # retryable/non-retryable path, while a transient connection drop here (e.g. pymysql's
+ # `InterfaceError(0, '')` when the socket was already closed) stays retryable there too.
+ # Capturing it would only flood error tracking with handled duplicates, so log at debug and
+ # fall back. Mirrors `get_partition_settings` and the Redshift source's `fetch_average_row_size`.
logger.debug(f"fetch_average_row_size: Error: {e}.", exc_info=e)
- capture_exception(e)
return None
def find_index_for_cursor(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py
index 583aa522249d..41ebe87828af 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py
@@ -533,6 +533,19 @@ class TestFetchAverageRowSize:
result = impl.fetch_average_row_size(cursor, "db", "t", "SELECT 1", {}, logger)
assert result is None
+ def test_does_not_capture_handled_probe_failures(self, impl, cursor, logger, mocker):
+ # Row-size sampling is best-effort: on failure the caller falls back to the default chunk
+ # size, so handled failures must not flood error tracking. pymysql raises InterfaceError(0, "")
+ # when the connection socket was already closed (a transient drop). Mirrors the get_rows_to_sync
+ # and explain_query probe guards.
+ cursor.execute.side_effect = pymysql.err.InterfaceError(0, "")
+ capture = mocker.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.mysql.mysql.capture_exception"
+ )
+
+ assert impl.fetch_average_row_size(cursor, "db", "t", "SELECT 1", {}, logger) is None
+ capture.assert_not_called()
+
def _show_index_rows(*triples: tuple[str, str, int]) -> list[tuple]:
"""Build fake SHOW INDEX rows from (key_name, column_name, seq_in_index) triples."""