: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(signals): exclude expected spend retries from error tracking (#131045)
Oliver Browne169c9b9b6841
diff --git a/posthog/temporal/common/posthog_client.py b/posthog/temporal/common/posthog_client.pyindex 1c323117bb41..fcb20c63074e 100644--- a/posthog/temporal/common/posthog_client.py+++ b/posthog/temporal/common/posthog_client.py@@ -42,6 +42,7 @@ EXPECTED_CONTROL_FLOW_ERROR_TYPES = frozenset({"trace_not_settled","session_not_settled",+ "TaskSpendPending","TransientRepartitionError","EmbeddingServiceUnavailable","AIFeaturesCloudOnly",diff --git a/posthog/temporal/tests/common/test_error_tracking.py b/posthog/temporal/tests/common/test_error_tracking.pyindex d254e15e4bf6..6996c3d328a5 100644--- a/posthog/temporal/tests/common/test_error_tracking.py+++ b/posthog/temporal/tests/common/test_error_tracking.py@@ -6,13 +6,13 @@ from dataclasses import dataclassfrom typing import Anyimport pytest-from unittest.mock import patch+from unittest.mock import AsyncMock, MagicMock, patchfrom temporalio import activity, workflowfrom temporalio.client import Client, WorkflowFailureErrorfrom temporalio.common import RetryPolicyfrom temporalio.exceptions import ApplicationError, CancelledError-from temporalio.worker import UnsandboxedWorkflowRunner, Worker+from temporalio.worker import ExecuteActivityInput, UnsandboxedWorkflowRunner, Workerfrom posthog.egress.github.transport import GitHubEgressBudgetExhaustedfrom posthog.exceptions_capture import bind_exception_context@@ -494,3 +494,35 @@ async def test_workflow_only_error_is_captured(temporal_client: Client):assert isinstance(workflow_call[0][0], ApplicationError)assert workflow_call[1]["properties"]["temporal.execution_type"] == "workflow"assert workflow_call[1]["properties"]["temporal.workflow.id"] == workflow_id+++ "error,expected_captures",+ [+ (ApplicationError("Task spend is still settling", type="TaskSpendPending"), 0),+ (ApplicationError("Spend task run no longer exists", non_retryable=True), 1),+ (ApplicationError("Task workflow did not complete settlement", non_retryable=True), 1),+ ],+ ids=["pending", "missing_run", "failed_settlement"],+)+async def test_task_spend_failure_reporting(error: ApplicationError, expected_captures: int) -> None:+ next_interceptor = AsyncMock()+ next_interceptor.execute_activity.side_effect = error+ interceptor = PostHogClientInterceptor().intercept_activity(next_interceptor)+ activity_input = MagicMock(spec=ExecuteActivityInput)+ activity_input.args = []+ activity_input.fn = failing_activity++ with (+ patch("posthog.temporal.common.posthog_client.api_key", "phc_test"),+ patch("posthog.temporal.common.posthog_client.activity.info", return_value=MagicMock()),+ patch("posthog.temporal.common.posthog_client.capture_exception") as capture,+ ):+ with pytest.raises(ApplicationError) as raised:+ await interceptor.execute_activity(activity_input)++ assert raised.value is error+ assert capture.call_count == expected_captures+ if expected_captures:+ assert capture.call_args.args[0] is error