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 posthog-db blips as error noise (#79868)

Tom Owers3ae62e0055f9
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py
index 97836c876142..cec86b9927a8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/cdp_producer.py
@@ -144,12 +144,17 @@ class CDPProducer:
trigger__type="data-warehouse-table",
trigger__table_name=dot_notated_table_name,
).exists()
- except DjangoOperationalError as e:
+ except (DjangoOperationalError, OSError) as e:
# This queries PostHog's own database, not the source being synced. A transient
# failure reaching it (e.g. a DNS blip resolving our host) stringifies with the
# same wording a customer's misconfigured source host would, which the source's
# `get_non_retryable_errors` would misclassify as non-retryable and permanently
# stop a healthy sync. Re-raise clear of those substrings so it stays retryable.
+ # A bare OSError (e.g. "Too many open files") reaches here unwrapped rather than as
+ # a DjangoOperationalError when the worker runs out of file descriptors while
+ # opening the connection's selector, before libpq has anything to report — same
+ # transient condition, different exception type depending on which connect step it
+ # hits, so both need the same reclassification.
raise PostHogInternalDatabaseError(
"Failed to check hog function/workflow triggers in PostHog's database"
) from e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py
index 250277fc388f..3e0cd7a614d7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_cdp_producer.py
@@ -292,7 +292,19 @@ async def test_should_run_with_both_hog_function_and_flow(team):
@pytest.mark.django_db(transaction=True)
@pytest.mark.asyncio
-async def test_should_run_posthog_database_connection_failure_stays_retryable(team):
+ "error_cls,message",
+ [
+ (DjangoOperationalError, "[Errno -2] Name or service not known"),
+ # Fd exhaustion opening the connection's selector surfaces as a bare OSError, unwrapped by
+ # Django, rather than a DjangoOperationalError — same transient condition, different
+ # exception type depending on which connect step runs out of file descriptors first.
+ (OSError, "[Errno 24] Too many open files"),
+ ],
+)
+async def test_should_run_posthog_database_connection_failure_stays_retryable(
+ error_cls: type[Exception], message: str, team
+):
# `should_run` queries PostHog's own database (HogFunction/HogFlow), not the
# source being synced. A transient connection failure there (e.g. a DNS blip resolving our
# host) surfaces the same "Name or service not known" wording a customer's misconfigured
@@ -313,7 +325,7 @@ async def test_should_run_posthog_database_connection_failure_stays_retryable(te
with patch(
"products.warehouse_sources.backend.temporal.data_imports.pipelines.core.cdp_producer.HogFunction.objects"
) as mock_hog_function_objects:
- mock_hog_function_objects.filter.side_effect = DjangoOperationalError("[Errno -2] Name or service not known")
+ mock_hog_function_objects.filter.side_effect = error_cls(message)
with pytest.raises(PostHogInternalDatabaseError) as exc_info:
await producer.should_run()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py
index 4d24edc4d765..d9c56ecbe10f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py
@@ -65,6 +65,7 @@ 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
from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.exceptions import CDCHandledExternally
+from products.warehouse_sources.backend.temporal.data_imports.util import PostHogInternalDatabaseError
from products.warehouse_sources.backend.temporal.data_imports.workload_report import aworkload_reporting
from products.warehouse_sources.backend.types import ExternalDataSourceType
@@ -470,8 +471,10 @@ async def _handle_import_error(
# a raw driver connection, never Django's ORM, so this exception type can only mean a transient
# connection-pool blip on our side (e.g. a PgBouncer query_wait_timeout under load), not a
# customer data or config problem. Same classification already used for app-DB blips in
- # delta_table_ref.is_transient_maintenance_error.
- if isinstance(error, OperationalError | InterfaceError):
+ # delta_table_ref.is_transient_maintenance_error. PostHogInternalDatabaseError is the same
+ # condition already reclassified by shared pipeline code (e.g. cdp_producer's should_run check)
+ # specifically so it wouldn't be mistaken for a customer-side failure here — honor that by type.
+ if isinstance(error, OperationalError | InterfaceError | PostHogInternalDatabaseError):
await logger.awarning(error_msg)
await logger.adebug("Transient app-DB error - re-raising for Temporal retry")
raise NonReportableError(error_msg) from error
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py
index 31504375c963..146a95c4243d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py
@@ -26,7 +26,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
RESTClientNonRetryableError,
RESTClientRetryableError,
)
-from products.warehouse_sources.backend.temporal.data_imports.util import NonRetryableException
+from products.warehouse_sources.backend.temporal.data_imports.util import (
+ NonRetryableException,
+ PostHogInternalDatabaseError,
+)
from products.warehouse_sources.backend.temporal.data_imports.workflow_activities import import_data_sync as module
from products.warehouse_sources.backend.temporal.data_imports.workflow_activities.import_data_sync import (
ImportDataActivityInputs,
@@ -345,6 +348,11 @@ async def test_rest_client_retryable_error_logged_as_warning_without_source_opt_
[
("operational_error", OperationalError, "query_wait_timeout"),
("interface_error", InterfaceError, "connection already closed"),
+ # Raised by shared pipeline code (e.g. cdp_producer's should_run check) when a lookup
+ # against PostHog's own app DB fails — already reclassified clear of wording a customer's
+ # misconfigured source host would produce, so it must get the same NonReportableError
+ # treatment as the Django exception types above, not fall through to the default branch.
+ ("posthog_internal_database_error", PostHogInternalDatabaseError, "Failed to check hog function triggers"),
]
)
@pytest.mark.asyncio