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-imports): stop reporting transient app-db blips from table-statistics activity (#83887)

Tom Owers66e5cda001bf
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py
index ad0d5f98c0f2..4424638db9c1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py
@@ -30,6 +30,7 @@ from posthog.exceptions_capture import capture_exception
from posthog.models import Team
from posthog.sync import database_sync_to_async
from posthog.temporal.common.base import PostHogWorkflow
+from posthog.temporal.common.db_errors import is_transient_db_error
from posthog.temporal.common.errors import NonReportableError
from posthog.temporal.common.heartbeat import LivenessHeartbeater as Heartbeater
@@ -285,7 +286,14 @@ async def compute_table_statistics_activity(inputs: ComputeTableStatisticsInputs
# get_delta_table already re-raises known-transient object-store blips as
# NonReportableError (see DeltaTableRef._capture_unless_transient) and intentionally
# skips reporting them itself — don't undo that here.
- if not isinstance(e, NonReportableError):
+ #
+ # The activity interceptor (posthog/temporal/common/posthog_client.py) already skips
+ # reporting a transient app-DB blip (e.g. a PgBouncer query_wait_timeout hit while
+ # resolving the Team/ExternalDataSchema/ExternalDataJob rows above) via
+ # is_transient_db_error — but only for exceptions that reach it unreported. The
+ # unconditional capture_exception call below would report it first, so apply the same
+ # classifier here to avoid double-reporting a condition nobody can act on.
+ if not isinstance(e, NonReportableError) and not is_transient_db_error(e):
capture_exception(e)
try:
posthoganalytics.capture(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py
index f860b5277db2..e3f879ae0b67 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py
@@ -6,7 +6,7 @@ from decimal import Decimal
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
-from django.db import connection
+from django.db import InterfaceError, OperationalError, connection
from django.test.utils import CaptureQueriesContext
from django.utils import timezone
@@ -335,6 +335,25 @@ class TestComputeTableStatisticsActivity:
await ActivityEnvironment().run(compute_table_statistics_activity, inputs)
mock_capture.assert_not_called()
+ @pytest.mark.parametrize("error_cls", [OperationalError, InterfaceError])
+ async def test_activity_does_not_report_transient_app_db_error(self, error_cls: type[Exception]) -> None:
+ # compute_table_statistics_sync's Team/ExternalDataSchema/ExternalDataJob lookups run against
+ # PostHog's own app DB through a connection pooler. A pooler blip under load (e.g. PgBouncer's
+ # query_wait_timeout) surfaces as a Django OperationalError/InterfaceError that the activity
+ # interceptor (posthog_client.py) already knows to keep out of error tracking via
+ # is_transient_db_error — but only if nothing reports it first. This activity's own except
+ # block must defer to that same classifier instead of unconditionally calling
+ # capture_exception, or it reports the blip before the interceptor ever gets a say. It must
+ # still fail the activity so Temporal retries it.
+ with (
+ patch.object(comp, "compute_table_statistics_sync", side_effect=error_cls("query_wait_timeout")),
+ patch.object(comp, "capture_exception") as mock_capture,
+ ):
+ inputs = ComputeTableStatisticsInputs(team_id=1, schema_id=uuid.uuid4())
+ with pytest.raises(error_cls, match="query_wait_timeout"):
+ await ActivityEnvironment().run(compute_table_statistics_activity, inputs)
+ mock_capture.assert_not_called()
+
class TestComputeTableStatisticsWorkflow:
def test_parse_inputs_round_trips_json(self) -> None: