: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(error-tracking): stop capturing handled embedding outages as issues (#73455)
posthog[bot]863253805eef
diff --git a/products/error_tracking/backend/temporal/lifecycle/issue_created/activities.py b/products/error_tracking/backend/temporal/lifecycle/issue_created/activities.pyindex e9a85a23b4dd..74d140c8b6e9 100644--- a/products/error_tracking/backend/temporal/lifecycle/issue_created/activities.py+++ b/products/error_tracking/backend/temporal/lifecycle/issue_created/activities.py@@ -8,6 +8,7 @@ from django.utils.dateparse import parse_datetimeimport httpximport requestsimport tiktoken+import structlogimport posthoganalyticsfrom asgiref.sync import sync_to_asyncfrom confluent_kafka import KafkaError, KafkaException@@ -48,6 +49,8 @@ from products.error_tracking.backend.temporal.lifecycle.issue_created.types impo)from products.signals.backend.facade.api import emit_signal+logger = structlog.get_logger(__name__)+EMBEDDING_MODEL = "text-embedding-3-large-3072"EMBEDDING_RENDERING = "type_message_and_stack"EMBEDDING_MAX_TOKENS = 7000@@ -66,6 +69,11 @@ ERROR_TRACKING_EVENT_PROPERTIES_READ_DURATION = Histogram("Duration of Error Tracking event property reads by storage source",labelnames=("source",),)+ERROR_TRACKING_EMBEDDING_UNAVAILABLE = Counter(+ "error_tracking_issue_created_embedding_unavailable_total",+ "Issue-created embedding attempts that failed because the embedding service was unavailable",+ labelnames=("reason",),+)class IssueCreatedEventNotFoundError(RuntimeError):@@ -251,12 +259,21 @@ def _fetch_event_properties(team: Team, inputs: IssueCreatedWorkflowInputs) -> dreturn _fetch_event_properties_from_clickhouse(team, inputs)-@close_db_connections-def generate_issue_created_embedding_activity(- inputs: IssueCreatedWorkflowInputs,-) -> IssueEmbeddingPreparationResult:+def _embedding_unavailable_error(inputs: IssueCreatedWorkflowInputs, reason: str, message: str) -> ApplicationError:+ # A short embedding-service outage is expected and already tolerated — the workflow retries then+ # fails open. Log and count it here so the outage is still observable, but leave capture to the+ # caller, which does not surface this as an error-tracking issue.+ ERROR_TRACKING_EMBEDDING_UNAVAILABLE.labels(reason=reason).inc()+ logger.warning(+ "error_tracking_issue_created_embedding_unavailable",+ team_id=inputs.team_id,+ issue_id=inputs.issue_id,+ reason=reason,+ )+ return ApplicationError(message, type=EMBEDDING_SERVICE_UNAVAILABLE_ERROR_TYPE)+++def _prepare_issue_created_embedding(inputs: IssueCreatedWorkflowInputs) -> IssueEmbeddingPreparationResult:try:team = Team.objects.get(id=inputs.team_id)except Team.DoesNotExist:@@ -284,14 +301,10 @@ def generate_issue_created_embedding_activity(type="EmbeddingRequestRejected",non_retryable=True,) from error- raise ApplicationError(- "Embedding service is unavailable",- type=EMBEDDING_SERVICE_UNAVAILABLE_ERROR_TYPE,- ) from error+ raise _embedding_unavailable_error(inputs, "transport", "Embedding service is unavailable") from errorexcept (KeyError, TypeError) as error:- raise ApplicationError(- "Embedding service returned an invalid response",- type=EMBEDDING_SERVICE_UNAVAILABLE_ERROR_TYPE,+ raise _embedding_unavailable_error(+ inputs, "invalid_response", "Embedding service returned an invalid response") from errorreturn IssueEmbeddingPreparationResult(team_exists=True,@@ -310,6 +323,27 @@ def generate_issue_created_embedding_activity()[email protected](capture_exceptions=False)+@close_db_connections+def generate_issue_created_embedding_activity(+ inputs: IssueCreatedWorkflowInputs,+) -> IssueEmbeddingPreparationResult:+ # capture_exceptions=False, then capture genuine failures explicitly below: a brief embedding-service+ # outage is expected and already tolerated (the workflow retries then fails open, tracked by the+ # error_tracking_issue_created_embedding_fail_open metric), so auto-capturing every retry turned a+ # short blip into a burst of noisy error-tracking issues. Real bugs are still surfaced.+ try:+ return _prepare_issue_created_embedding(inputs)+ except ApplicationError as error:+ if error.type != EMBEDDING_SERVICE_UNAVAILABLE_ERROR_TYPE:+ posthoganalytics.capture_exception(error)+ raise+ except Exception as error:+ posthoganalytics.capture_exception(error)+ raise++@activity.defn@posthoganalytics.scoped()@close_db_connectionsdiff --git a/products/error_tracking/backend/temporal/lifecycle/issue_created/test/test_workflow.py b/products/error_tracking/backend/temporal/lifecycle/issue_created/test/test_workflow.pyindex 54ab7b3f7222..16e666da3952 100644--- a/products/error_tracking/backend/temporal/lifecycle/issue_created/test/test_workflow.py+++ b/products/error_tracking/backend/temporal/lifecycle/issue_created/test/test_workflow.py@@ -111,48 +111,51 @@ def test_stacktrace_rendering_matches_cymbal_embedding_content() -> None:)+ "side_effect,expected_type,expected_non_retryable,expect_captured",+ [+ # Transient outages (DNS/connection/timeout/5xx and malformed responses) are expected and+ # handled by the workflow's fail-open path, so they must not be captured to error tracking.+ (requests.Timeout("embedding timeout"), EMBEDDING_SERVICE_UNAVAILABLE_ERROR_TYPE, False, False),+ (requests.ConnectionError("Name or service not known"), EMBEDDING_SERVICE_UNAVAILABLE_ERROR_TYPE, False, False),+ (+ requests.HTTPError(response=MagicMock(status_code=500)),+ EMBEDDING_SERVICE_UNAVAILABLE_ERROR_TYPE,+ False,+ False,+ ),+ (KeyError("embedding"), EMBEDDING_SERVICE_UNAVAILABLE_ERROR_TYPE, False, False),+ # A genuine 4xx rejection is a real bug and stays captured.+ (requests.HTTPError(response=MagicMock(status_code=400)), "EmbeddingRequestRejected", True, True),+ ],+)+@patch("products.error_tracking.backend.temporal.lifecycle.issue_created.activities.posthoganalytics.capture_exception")@patch("products.error_tracking.backend.temporal.lifecycle.issue_created.activities.render_stacktrace")@patch("products.error_tracking.backend.temporal.lifecycle.issue_created.activities._fetch_event_properties")@patch("products.error_tracking.backend.temporal.lifecycle.issue_created.activities.Team.objects.get")@patch("products.error_tracking.backend.temporal.lifecycle.issue_created.activities.generate_embedding")-def test_embedding_service_timeout_is_classified_as_retryable(- generate_embedding: MagicMock,- get_team: MagicMock,- fetch_event_properties: MagicMock,- render_stacktrace: MagicMock,-) -> None:- get_team.return_value.organization.is_ai_data_processing_approved = True- fetch_event_properties.return_value = {"$exception_list": [{"type": "TypeError", "value": "boom"}]}- render_stacktrace.return_value = "TypeError: boom"- generate_embedding.side_effect = requests.Timeout("embedding timeout")-- with pytest.raises(ApplicationError) as error:- generate_issue_created_embedding_activity(_inputs("fingerprint"))-- assert error.value.type == EMBEDDING_SERVICE_UNAVAILABLE_ERROR_TYPE- assert error.value.non_retryable is False---@patch("products.error_tracking.backend.temporal.lifecycle.issue_created.activities.render_stacktrace")-@patch("products.error_tracking.backend.temporal.lifecycle.issue_created.activities._fetch_event_properties")-@patch("products.error_tracking.backend.temporal.lifecycle.issue_created.activities.Team.objects.get")-@patch("products.error_tracking.backend.temporal.lifecycle.issue_created.activities.generate_embedding")-def test_embedding_service_rejected_request_is_non_retryable(+def test_embedding_failure_classification_and_capture(generate_embedding: MagicMock,get_team: MagicMock,fetch_event_properties: MagicMock,render_stacktrace: MagicMock,+ capture_exception: MagicMock,+ side_effect: Exception,+ expected_type: str,+ expected_non_retryable: bool,+ expect_captured: bool,) -> None:get_team.return_value.organization.is_ai_data_processing_approved = Truefetch_event_properties.return_value = {"$exception_list": [{"type": "TypeError", "value": "boom"}]}render_stacktrace.return_value = "TypeError: boom"- generate_embedding.side_effect = requests.HTTPError(response=MagicMock(status_code=400))+ generate_embedding.side_effect = side_effectwith pytest.raises(ApplicationError) as error:generate_issue_created_embedding_activity(_inputs("fingerprint"))- assert error.value.type == "EmbeddingRequestRejected"- assert error.value.non_retryable is True+ assert error.value.type == expected_type+ assert error.value.non_retryable is expected_non_retryable+ assert capture_exception.called is expect_captured@override_settings(ERROR_TRACKING_EVENT_PROPERTIES_REDIS_URL="redis://event-properties")