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(temporal): keep egress-budget backpressure out of error tracking (#68856)

Tom Owers370fdbe40ced
diff --git a/posthog/temporal/common/posthog_client.py b/posthog/temporal/common/posthog_client.py
index 8603a2f97937..f94ae1458905 100644
--- a/posthog/temporal/common/posthog_client.py
+++ b/posthog/temporal/common/posthog_client.py
@@ -14,6 +14,7 @@ from temporalio.worker import (
WorkflowInterceptorClassInput,
)
+from posthog.egress.transport.transport import EgressBudgetExhausted
from posthog.temporal.common.interceptor import ALL_TASK_QUEUES
from posthog.temporal.common.logger import get_write_only_logger
@@ -65,9 +66,11 @@ class _PostHogClientActivityInboundInterceptor(ActivityInboundInterceptor):
try:
return await super().execute_activity(input)
except Exception as e:
- # Cancellations (worker drain, activity timeout, workflow cancellation) are expected
- # control flow, not defects — re-raise without reporting them to error tracking.
- if temporalio.exceptions.is_cancelled_exception(e):
+ # Cancellations (worker drain, activity timeout, workflow cancellation) and our own
+ # egress-budget backpressure (a deliberate "defer and retry later" signal that our
+ # rate limiter already records via record_outbound_decision) are expected control flow,
+ # not defects — re-raise without reporting them to error tracking.
+ if temporalio.exceptions.is_cancelled_exception(e) or isinstance(e, EgressBudgetExhausted):
raise
activity_info = activity.info()
capture_kwargs = {
diff --git a/posthog/temporal/tests/common/test_error_tracking.py b/posthog/temporal/tests/common/test_error_tracking.py
index fe444bb3495b..83a7dda2512e 100644
--- a/posthog/temporal/tests/common/test_error_tracking.py
+++ b/posthog/temporal/tests/common/test_error_tracking.py
@@ -14,6 +14,7 @@ from temporalio.common import RetryPolicy
from temporalio.exceptions import ApplicationError, CancelledError
from temporalio.worker import UnsandboxedWorkflowRunner, Worker
+from posthog.egress.github.transport import GitHubEgressBudgetExhausted
from posthog.temporal.common.posthog_client import PostHogClientInterceptor
@@ -97,6 +98,24 @@ class CancelledActivityWorkflow:
)
+async def egress_backpressure_activity(inputs: OptionallyFailingInputs) -> None:
+ raise GitHubEgressBudgetExhausted("GitHub egress budget exhausted for installation 123; deferring")
+
+
+class EgressBackpressureActivityWorkflow:
+ @workflow.run
+ async def run(self, inputs: OptionallyFailingInputs) -> None:
+ await workflow.execute_activity(
+ egress_backpressure_activity,
+ inputs,
+ start_to_close_timeout=dt.timedelta(minutes=1),
+ heartbeat_timeout=dt.timedelta(seconds=5),
+ retry_policy=RetryPolicy(maximum_attempts=1),
+ )
+
+
@workflow.defn
class DirectlyFailingWorkflow:
@workflow.run
@@ -206,6 +225,35 @@ async def test_cancellation_is_not_captured(temporal_client: Client):
mock_ph_capture.assert_not_called()
+async def test_egress_backpressure_is_not_captured(temporal_client: Client):
+ """An egress-budget backpressure error (our own limiter shedding a deferrable call so Temporal
+ retries later) is expected control flow, not a defect, so the interceptor must re-raise it
+ without reporting it to error tracking."""
+ task_queue = "TEST-TASK-QUEUE"
+ workflow_id = str(uuid.uuid4())
+
+ with patch("posthog.temporal.common.posthog_client.capture_exception") as mock_ph_capture:
+ async with Worker(
+ temporal_client,
+ task_queue=task_queue,
+ workflows=[EgressBackpressureActivityWorkflow],
+ activities=[egress_backpressure_activity],
+ interceptors=[PostHogClientInterceptor()],
+ workflow_runner=UnsandboxedWorkflowRunner(),
+ ):
+ with pytest.raises(WorkflowFailureError):
+ await temporal_client.execute_workflow(
+ "EgressBackpressureActivityWorkflow",
+ OptionallyFailingInputs(fail=True),
+ id=workflow_id,
+ task_queue=task_queue,
+ retry_policy=RetryPolicy(maximum_attempts=1),
+ )
+
+ mock_ph_capture.assert_not_called()
+
+
@pytest.mark.asyncio
async def test_workflow_only_error_is_captured(temporal_client: Client):
task_queue = "TEST-TASK-QUEUE"