: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
feat(ws): improve warehouse-sources-load observability (#60231)
estefania3406cb0b42c0
diff --git a/posthog/temporal/data_imports/pipelines/pipeline_v3/load/idempotency.py b/posthog/temporal/data_imports/pipelines/pipeline_v3/load/idempotency.pyindex 8a42c622fc1a..78957c5b6f06 100644--- a/posthog/temporal/data_imports/pipelines/pipeline_v3/load/idempotency.py+++ b/posthog/temporal/data_imports/pipelines/pipeline_v3/load/idempotency.py@@ -28,7 +28,12 @@ def get_redis_client():redis_client = get_client(f"redis://{settings.DATA_WAREHOUSE_REDIS_HOST}:{settings.DATA_WAREHOUSE_REDIS_PORT}/")redis_client.ping()except Exception as e:+ logger.warning(+ "Redis unavailable for idempotency check — falling back to delta history scan",+ error=str(e),+ )capture_exception(e)+ redis_client = Nonetry:yield redis_clientdiff --git a/posthog/temporal/data_imports/pipelines/pipeline_v3/load/processor.py b/posthog/temporal/data_imports/pipelines/pipeline_v3/load/processor.pyindex 9b76bc60d9a1..309b92567449 100644--- a/posthog/temporal/data_imports/pipelines/pipeline_v3/load/processor.py+++ b/posthog/temporal/data_imports/pipelines/pipeline_v3/load/processor.py@@ -9,6 +9,7 @@ import pyarrow.compute as pcimport posthoganalyticsfrom asgiref.sync import async_to_sync+from posthog.exceptions_capture import capture_exceptionfrom posthog.temporal.data_imports.pipelines.common.load import run_post_load_operations, supports_partial_data_loadingfrom posthog.temporal.data_imports.pipelines.pipeline.consts import PARTITION_KEYfrom posthog.temporal.data_imports.pipelines.pipeline.delta_table_helper import DeltaTableHelper@@ -134,12 +135,14 @@ async def _handle_partial_data_loading(if modified_files:logger.warning("Found modified files during first sync, skipping partial data loading",+ batch_index=export_signal.batch_index,modified_count=len(modified_files),)+ capture_exception(Exception(f"Found {len(modified_files)} modified delta files during first sync"))returnif not new_file_uris:- logger.debug("No new files to make queryable")+ logger.debug("No new files to make queryable", batch_index=export_signal.batch_index)returnlogger.debug(@@ -169,7 +172,11 @@ async def _handle_partial_data_loading(primary_keys=export_signal.primary_keys,)- logger.debug("partial_data_loading_complete", queryable_folder=queryable_folder)+ logger.debug(+ "partial_data_loading_complete",+ batch_index=export_signal.batch_index,+ queryable_folder=queryable_folder,+ )def _run_post_load_for_already_processed_batch(export_signal: ExportSignalMessage) -> None:@@ -202,7 +209,11 @@ def _run_post_load_for_already_processed_batch(export_signal: ExportSignalMessagdelta_table = await delta_table_helper.get_delta_table()if delta_table is None:- logger.warning("no_delta_table_for_post_load", job_id=export_signal.job_id)+ logger.error(+ "no_delta_table_for_post_load",+ job_id=export_signal.job_id,+ batch_index=export_signal.batch_index,+ )returnpa_table = read_parquet(export_signal.s3_path)@@ -357,6 +368,7 @@ def process_message(message: Any, progress_callback: Callable[[], None] | None =logger.debug("parquet_file_read",+ batch_index=export_signal.batch_index,s3_path=export_signal.s3_path,num_rows=pa_table.num_rows,num_columns=pa_table.num_columns,@@ -403,6 +415,13 @@ def process_message(message: Any, progress_callback: Callable[[], None] | None =delete_key_set.add(tuple(arr[i] for arr in pk_arrays))if delete_key_set:+ logger.debug(+ "cdc_delete_enrichment",+ delete_row_count=len(delete_key_set),+ primary_key_count=len(present_pks),+ cdc_write_mode=cdc_write_mode,+ batch_index=export_signal.batch_index,+ )# Delta-rs: single-column IN avoids tuple filters (weak NULL semantics).# For composite PKs that IN is a superset — narrow in PyArrow below.first_pk = present_pks[0]@@ -503,6 +522,7 @@ def process_message(message: Any, progress_callback: Callable[[], None] | None =if export_signal.is_final_batch:logger.info("final_batch_received",+ batch_index=export_signal.batch_index,total_batches=export_signal.total_batches,total_rows=export_signal.total_rows,cdc_write_mode=export_signal.cdc_write_mode,diff --git a/posthog/temporal/data_imports/pipelines/pipeline_v3/pipeline.py b/posthog/temporal/data_imports/pipelines/pipeline_v3/pipeline.pyindex 2fa097be280c..ee3675cdebb0 100644--- a/posthog/temporal/data_imports/pipelines/pipeline_v3/pipeline.py+++ b/posthog/temporal/data_imports/pipelines/pipeline_v3/pipeline.py@@ -185,6 +185,16 @@ class PipelineV3(Generic[ResumableData]):start_time = time.perf_counter()status = "success"+ await self._logger.ainfo(+ "V3 Pipeline: Extraction starting",+ run_uuid=self._s3_batch_writer.get_run_uuid(),+ sync_type=sync_type,+ is_incremental=self._is_incremental,+ is_resume=should_resume,+ is_first_ever_sync=self._delta_table_helper.is_first_sync,+ reset_pipeline=self._reset_pipeline,+ )+try:await cdp_producer_clear_chunks(self._cdp_producer)@@ -262,6 +272,7 @@ class PipelineV3(Generic[ResumableData]):}except Exception:status = "error"+ self._logger.exception("V3 Pipeline: Extraction failed")try:self._s3_batch_writer.cleanup()except Exception:diff --git a/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py b/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.pyindex 8cc2114da52c..1c06f2d8ac3f 100644--- a/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py+++ b/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/consumer.py@@ -162,6 +162,8 @@ class BatchConsumer:"shutdown_mid_group",team_id=team_id,schema_id=schema_id,+ batch_id=batch.id,+ batch_index=batch.batch_index,remaining=len(batches) - batches.index(batch),)break@@ -236,6 +238,7 @@ class BatchConsumer:"batch_max_retries_exceeded",batch_id=batch.id,run_uuid=batch.run_uuid,+ batch_index=batch.batch_index,attempt=attempt,)await self._fail_run(batch, reason=f"max retries exceeded (attempt {attempt})")@@ -290,6 +293,7 @@ class BatchConsumer:"batch_failed_no_retries_left",batch_id=batch.id,run_uuid=batch.run_uuid,+ batch_index=batch.batch_index,attempt=attempt,)await self._fail_run(batch, reason=f"max retries exceeded: {e}")@@ -297,6 +301,7 @@ class BatchConsumer:logger.warning("batch_failed_will_retry",batch_id=batch.id,+ batch_index=batch.batch_index,attempt=attempt,error=str(e),)@@ -359,18 +364,54 @@ class BatchConsumer:RECOVERY_SWEEPS_TOTAL.labels(outcome="orphans_found").inc()logger.info("recovery_sweep_found_stale_batches", count=len(stale))+ recovery_bound_keys = (+ "team_id",+ "schema_id",+ "source_id",+ "job_id",+ "run_uuid",+ "batch_id",+ "resource_name",+ "log_source_id",+ "attempt",+ )for batch in stale:# latest_attempt was already incremented before the crash# (pre-increment in _process_single), so no +1 needed here.- if batch.latest_attempt >= self._config.max_attempts:- await self._fail_run(batch, reason="max retries exceeded (likely OOM)", conn=conn)- else:- await BatchQueue.update_status(- conn,- batch_id=batch.id,- job_state=SourceBatchStatus.State.WAITING_RETRY,- attempt=batch.latest_attempt,- )+ structlog.contextvars.bind_contextvars(+ team_id=batch.team_id,+ schema_id=batch.schema_id,+ source_id=batch.source_id,+ job_id=batch.job_id,+ run_uuid=batch.run_uuid,+ batch_id=batch.id,+ resource_name=batch.resource_name,+ log_source_id=batch.schema_id,+ attempt=batch.latest_attempt,+ )+ try:+ if batch.latest_attempt >= self._config.max_attempts:+ logger.warning(+ "batch_recovered_max_retries_exceeded",+ batch_index=batch.batch_index,+ attempt=batch.latest_attempt,+ )+ await self._fail_run(batch, reason="max retries exceeded (likely OOM)", conn=conn)+ else:+ logger.warning(+ "batch_recovered_for_retry",+ batch_index=batch.batch_index,+ attempt=batch.latest_attempt,+ )+ await BatchQueue.update_status(+ conn,+ batch_id=batch.id,+ job_state=SourceBatchStatus.State.WAITING_RETRY,+ attempt=batch.latest_attempt,+ error_response={"error": "executing timed out — pod restart or OOM"},+ )+ finally:+ structlog.contextvars.unbind_contextvars(*recovery_bound_keys)def _install_signal_handlers(self) -> None:"""Wire SIGTERM/SIGINT to trigger graceful shutdown."""diff --git a/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/producer.py b/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/producer.pyindex 6e59a33b160b..015bba36abb3 100644--- a/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/producer.py+++ b/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/producer.py@@ -163,11 +163,20 @@ class PostgresProducer:)self._batches_sent += 1- self._logger.debug(- "batch_inserted_to_postgres_queue",- batch_index=batch_result.batch_index,- is_final_batch=is_final_batch,- )+ if is_final_batch:+ self._logger.info(+ "batch_inserted_to_postgres_queue",+ batch_index=batch_result.batch_index,+ is_final_batch=True,+ total_batches=total_batches,+ total_rows=total_rows,+ )+ else:+ self._logger.debug(+ "batch_inserted_to_postgres_queue",+ batch_index=batch_result.batch_index,+ is_final_batch=False,+ )def flush(self, timeout: Optional[float] = None) -> int:"""No-op — inserts are durable on commit. Returns count of batches sent since last flush."""diff --git a/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py b/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.pyindex 47a61819b38d..d8159a801aac 100644--- a/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py+++ b/posthog/temporal/data_imports/pipelines/pipeline_v3/postgres_queue/test_consumer.py@@ -224,6 +224,7 @@ class TestRecoverySweep:batch_id=stale_batch.id,job_state=SourceBatchStatus.State.WAITING_RETRY,attempt=1,+ error_response={"error": "executing timed out — pod restart or OOM"},)@pytest.mark.asyncio