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(experiments): Keep metric validation errors out of error tracking (#108404)

Juraj Majerik782605e10b4f
diff --git a/posthog/temporal/common/errors.py b/posthog/temporal/common/errors.py
index 901ba133f70b..16f0f3f6c76a 100644
--- a/posthog/temporal/common/errors.py
+++ b/posthog/temporal/common/errors.py
@@ -15,6 +15,12 @@ class NonReportableError(Exception):
retrying can't resolve, so a tracked exception would only be noise."""
+class NonReportableApplicationError(ApplicationError, NonReportableError):
+ """NonReportableError for an activity that must fail with a typed Temporal ApplicationError
+ (so the workflow can read `type` and `non_retryable`) while the failure stays out of error
+ tracking."""
+
+
# Bound error strings so a multi-MB str(e) (ClickHouse 5xx body, Playwright HTML dump)
# can't blow out Temporal's 2 MiB payload limit.
MAX_ERROR_MESSAGE_CHARS = 8_000
diff --git a/products/experiments/backend/temporal/recalculation_logic.py b/products/experiments/backend/temporal/recalculation_logic.py
index 110ba0f6de54..4c9bd92223d5 100644
--- a/products/experiments/backend/temporal/recalculation_logic.py
+++ b/products/experiments/backend/temporal/recalculation_logic.py
@@ -29,6 +29,7 @@ from posthog.exceptions_capture import capture_exception
from posthog.hogql_queries.query_runner import ExecutionMode
from posthog.models.scoping import team_scope
from posthog.sync import database_sync_to_async_pool
+from posthog.temporal.common.errors import NonReportableApplicationError
from products.experiments.backend.hogql_queries.base_query_utils import experiment_window_end
from products.experiments.backend.hogql_queries.error_handling import (
@@ -962,5 +963,10 @@ def _calculate_experiment_metric_for_recalculation_sync(
trigger=state.trigger,
)
if is_permanent:
+ if error_type == "validation_error":
+ # The activity interceptor captures any ApplicationError that escapes, which
+ # would undo the capture skip above. The non-reportable variant keeps the
+ # stored failure out of error tracking.
+ raise NonReportableApplicationError(message, type=error_type, non_retryable=True) from e
raise ApplicationError(message, type=error_type, non_retryable=True) from e
raise
diff --git a/products/experiments/backend/temporal/test_recalculation_activities.py b/products/experiments/backend/temporal/test_recalculation_activities.py
index 28091931dc5c..0642db09c0ce 100644
--- a/products/experiments/backend/temporal/test_recalculation_activities.py
+++ b/products/experiments/backend/temporal/test_recalculation_activities.py
@@ -18,6 +18,7 @@ from temporalio.exceptions import ApplicationError
from posthog.clickhouse.client.limit import ConcurrencyLimitExceeded
from posthog.clickhouse.query_tagging import Feature, Product, get_query_tags
from posthog.exceptions import ClickHouseAtCapacity, ClickHouseQueryMemoryLimitExceeded, ClickHouseQueryTimeOut
+from posthog.temporal.common.errors import NonReportableError
from products.experiments.backend.hogql_queries.experiment_metric_fingerprint import compute_metric_fingerprint
from products.experiments.backend.hogql_queries.utils import get_experiment_stats_method
@@ -877,6 +878,9 @@ class TestCalculateActivity(BaseTest):
assert exc_info.value.non_retryable is True
assert exc_info.value.type == expected_type
+ # Validation errors are user config, not defects: the raised error must carry the
+ # non-reportable marker so the activity interceptor doesn't send it to error tracking.
+ assert isinstance(exc_info.value, NonReportableError) == (expected_type == "validation_error")
recalc.refresh_from_db()
assert "m1" in recalc.metric_errors
row = ExperimentMetricResult.objects.get(experiment=exp, metric_uuid="m1")