: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-imports): keep transient S3 credential blips out of error tracking (#74388)
Tom Owerse39473971bf0
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta_table_helper.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta_table_helper.pyindex 5be95cf41c43..5054c0910b45 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta_table_helper.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/delta_table_helper.py@@ -11,6 +11,7 @@ import pyarrow as paimport deltalake as deltalakeimport pyarrow.compute as pcimport posthoganalytics+import botocore.exceptionsimport deltalake.exceptionsfrom dlt.common.libs.deltalake import ensure_delta_compatible_arrow_schemafrom structlog.types import FilteringBoundLogger@@ -69,13 +70,20 @@ TRANSIENT_OBJECT_STORE_ERRORS = (def is_transient_object_store_error(error: BaseException) -> bool:- """True for a transient object-store error, however delta-rs happened to surface it.+ """True for a transient object-store error, however it happened to surface.`DeltaTable.is_deltatable()` raises these as a plain `OSError`, but table-level operations(e.g. `vacuum()`, `optimize.compact()`) wrap the identical underlying object-store error text in`deltalake.exceptions.DeltaError` instead — same blip, different exception type depending on- which delta-rs entry point hit it.+ which delta-rs entry point hit it. `_purge_s3_prefix`'s s3fs/aiobotocore calls can also raise a+ bare `botocore.exceptions.NoCredentialsError` unwrapped — the same IMDS/STS credential-provider+ blip, just surfaced by aiobotocore's own credential resolution instead of delta-rs's Rust+ `object_store` crate. `NoCredentialsError`'s message is a fixed, generic string (no needle to+ match), but hitting our own instance-role-authenticated bucket always means the same transient+ resolution hiccup, so it's recognized by type rather than by message."""+ if isinstance(error, botocore.exceptions.NoCredentialsError):+ return Truereturn isinstance(error, OSError | deltalake.exceptions.DeltaError) and any(needle in str(error) for needle in TRANSIENT_OBJECT_STORE_ERRORS)diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_delta_table_helper.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_delta_table_helper.pyindex a1f58e4af4bd..1104500088a4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_delta_table_helper.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_delta_table_helper.py@@ -12,6 +12,7 @@ from django.test import override_settingsimport pyarrow as paimport deltalakeimport pyarrow.compute as pc+import botocore.exceptionsfrom parameterized import parameterizedfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.core.arrow_utils import (@@ -26,6 +27,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.del_first_per_pk_table,_realign_decimal_buffers,is_transient_delta_maintenance_error,+ is_transient_object_store_error,)@@ -1267,3 +1269,30 @@ class TestIsTransientDeltaMaintenanceError:)def test_matches_only_the_racy_optimize_scan_signature(self, _name: str, error: Exception, expected: bool):assert is_transient_delta_maintenance_error(error) is expected+++class TestIsTransientObjectStoreError:+ @parameterized.expand(+ [+ (+ "credential_provider_not_enabled_os_error",+ OSError(+ "Operation not supported: the credential provider was not enabled: "+ "no providers in chain provided credentials"+ ),+ True,+ ),+ ("unrelated_os_error", OSError("Permission denied: bucket policy forbids this operation"), False),+ (+ # s3fs/aiobotocore's own credential resolution (distinct from delta-rs's Rust+ # object_store crate) can raise this bare, unwrapped — same IMDS/STS blip+ # hitting our own instance-role-authenticated bucket, different client library.+ "bare_no_credentials_error",+ botocore.exceptions.NoCredentialsError(),+ True,+ ),+ ("unrelated_exception_type", ValueError("some other unrelated failure"), False),+ ]+ )+ def test_classifies_transient_errors(self, _name: str, error: Exception, expected: bool):+ assert is_transient_object_store_error(error) is expecteddiff --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.pyindex ba2c29905923..7867d8bcd7ac 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@@ -36,6 +36,9 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.common.efrom products.warehouse_sources.backend.temporal.data_imports.pipelines.core.arrow_utils import (SchemaColumnTypeChangedException,)+from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta_table_helper import (+ is_transient_object_store_error,+)from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.typings import PipelineResultfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_sync import PipelineInputsfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v2.pipeline import PipelineNonDLT@@ -332,7 +335,8 @@ async def _handle_import_error((``posthog/temporal/common/posthog_client.py``) from reporting whatever exception type escapesthe activity; only that marker type does. ``RESTClientRetryableError`` gets the same treatmentby type, since it's already a ``NonReportableError`` subclass and every REST-based source hits- that condition already.+ that condition already. A transient object-store hiccup talking to our own data-warehouse+ bucket is re-raised as ``NonReportableError`` the same way.Everything else is logged as an exception and re-raised so Temporal retries it as usual."""@@ -378,6 +382,15 @@ async def _handle_import_error(await logger.adebug("REST client exhausted its retries - re-raising for Temporal retry")raise error+ # A transient S3/object-store hiccup talking to our own data-warehouse bucket (IMDS/STS+ # blip, SlowDown throttling) that surfaced during this run — e.g. resetting or opening the+ # Delta table. Not a PostHog defect and not a customer credential problem (see+ # TRANSIENT_OBJECT_STORE_ERRORS), and retrying resolves it, so it shouldn't page anyone.+ if is_transient_object_store_error(error):+ await logger.awarning(error_msg)+ await logger.adebug("Transient object-store error - re-raising for Temporal retry")+ raise NonReportableError(error_msg) from error+# Cross-source non-retryable errors (missing primary key on an incremental table, bad SSH tunnel# auth, a widened column type) are raised from shared pipeline code, not any one source. The# finalization activity already consults this shared dict; this in-activity handler decides whetherdiff --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.pyindex a04c2a182f4e..0da8c1ecfbd3 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@@ -222,6 +222,33 @@ async def test_rest_client_retryable_error_logged_as_warning_without_source_opt_logger.aexception.assert_not_awaited()+async def test_transient_object_store_error_reraised_as_non_reportable():+ # A transient S3 credential-provider blip (IMDS/STS) talking to our own data-warehouse bucket,+ # e.g. while resetting the Delta table. It's retryable (Temporal retries the activity as usual),+ # but re-raising the bare OSError would still be captured by the activity interceptor, which+ # only skips reporting for NonReportableError — so it must be wrapped, not just logged at warning.+ error = OSError(+ "Operation not supported: the credential provider was not enabled: no providers in chain provided credentials"+ )+ source = mock.MagicMock(spec=SimpleSource)+ source.get_non_retryable_errors.return_value = {}+ source.get_retryable_errors.return_value = set()++ logger = mock.MagicMock()+ logger.awarning = mock.AsyncMock()+ logger.aexception = mock.AsyncMock()+ logger.adebug = mock.AsyncMock()++ with mock.patch.object(module.SourceRegistry, "get_source", return_value=source):+ with pytest.raises(NonReportableError) as exc_info:+ await module._handle_import_error(mock.MagicMock(), logger, error)++ assert exc_info.value.__cause__ is error+ logger.awarning.assert_awaited_once()+ logger.aexception.assert_not_awaited()++@pytest.mark.asyncioasync def test_schema_column_type_changed_routes_through_handler_without_source_opt_in():# SchemaColumnTypeChangedException is raised in shared pipeline code when incoming data can't be