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.

refactor(error-tracking): isolate behind facade, contracts and presentation (#64233)

Hugues Pouillot78b60bd2a104
diff --git a/ee/hogai/context/error_tracking/context.py b/ee/hogai/context/error_tracking/context.py
index 0e4e3e8740a7..d791a0a558a4 100644
--- a/ee/hogai/context/error_tracking/context.py
+++ b/ee/hogai/context/error_tracking/context.py
@@ -9,7 +9,7 @@ from posthog.sync import database_sync_to_async
from products.error_tracking.backend.facade import (
api as error_tracking_api,
- types as error_tracking_types,
+ contracts as error_tracking_contracts,
)
from .prompts import ERROR_TRACKING_ISSUE_CONTEXT_TEMPLATE
@@ -34,7 +34,7 @@ class ErrorTrackingIssueContext:
self._issue_id = issue_id
self._issue_name = issue_name
- def _get_issue_sync(self) -> error_tracking_types.ErrorTrackingIssue | None:
+ def _get_issue_sync(self) -> error_tracking_contracts.ErrorTrackingIssue | None:
try:
issue_id = UUID(self._issue_id)
except ValueError:
@@ -45,7 +45,7 @@ class ErrorTrackingIssueContext:
except error_tracking_api.IssueNotFoundError:
return None
- async def aget_issue(self) -> error_tracking_types.ErrorTrackingIssue | None:
+ async def aget_issue(self) -> error_tracking_contracts.ErrorTrackingIssue | None:
"""Fetch the issue from the error tracking facade using async."""
return await database_sync_to_async(self._get_issue_sync)()
diff --git a/ee/hogai/core/agent_modes/presets/error_tracking.py b/ee/hogai/core/agent_modes/presets/error_tracking.py
index 61920e627824..6d9fd1f39c82 100644
--- a/ee/hogai/core/agent_modes/presets/error_tracking.py
+++ b/ee/hogai/core/agent_modes/presets/error_tracking.py
@@ -87,7 +87,7 @@ class ErrorTrackingAgentToolkit(AgentToolkit):
@property
def tools(self) -> list[type["MaxTool"]]:
- from products.error_tracking.backend.tools.search_issues import SearchErrorTrackingIssuesTool
+ from products.error_tracking.backend.facade.tools import SearchErrorTrackingIssuesTool
tools: list[type[MaxTool]] = [SearchErrorTrackingIssuesTool]
return tools
diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.py
index 0a27db0815b8..3b1e5099e66a 100644
--- a/posthog/hogql_queries/query_runner.py
+++ b/posthog/hogql_queries/query_runner.py
@@ -769,7 +769,7 @@ def get_query_runner(
)
if kind == "ErrorTrackingQuery":
- from products.error_tracking.backend.hogql_queries.error_tracking_query_runner import ErrorTrackingQueryRunner
+ from products.error_tracking.backend.facade.queries import ErrorTrackingQueryRunner
return ErrorTrackingQueryRunner(
query=query,
@@ -793,9 +793,7 @@ def get_query_runner(
)
if kind == "ErrorTrackingIssueCorrelationQuery":
- from products.error_tracking.backend.hogql_queries.error_tracking_issue_correlation_query_runner import (
- ErrorTrackingIssueCorrelationQueryRunner,
- )
+ from products.error_tracking.backend.facade.queries import ErrorTrackingIssueCorrelationQueryRunner
return ErrorTrackingIssueCorrelationQueryRunner(
query=query,
@@ -807,9 +805,7 @@ def get_query_runner(
)
if kind == "ErrorTrackingSimilarIssuesQuery":
- from products.error_tracking.backend.hogql_queries.error_tracking_similar_issues_query_runner import (
- ErrorTrackingSimilarIssuesQueryRunner,
- )
+ from products.error_tracking.backend.facade.queries import ErrorTrackingSimilarIssuesQueryRunner
return ErrorTrackingSimilarIssuesQueryRunner(
query=query,
@@ -821,9 +817,7 @@ def get_query_runner(
)
if kind == "ErrorTrackingBreakdownsQuery":
- from products.error_tracking.backend.hogql_queries.error_tracking_breakdowns_query_runner import (
- ErrorTrackingBreakdownsQueryRunner,
- )
+ from products.error_tracking.backend.facade.queries import ErrorTrackingBreakdownsQueryRunner
return ErrorTrackingBreakdownsQueryRunner(
query=query,
diff --git a/posthog/management/commands/start_temporal_worker.py b/posthog/management/commands/start_temporal_worker.py
index d44afdfd4dbc..9677064b8d6f 100644
--- a/posthog/management/commands/start_temporal_worker.py
+++ b/posthog/management/commands/start_temporal_worker.py
@@ -179,7 +179,7 @@ from products.business_knowledge.backend.temporal import (
ACTIVITIES as BUSINESS_KNOWLEDGE_ACTIVITIES,
WORKFLOWS as BUSINESS_KNOWLEDGE_WORKFLOWS,
)
-from products.error_tracking.backend.temporal import (
+from products.error_tracking.backend.facade.temporal import (
ACTIVITIES as ERROR_TRACKING_ACTIVITIES,
WORKFLOWS as ERROR_TRACKING_WORKFLOWS,
)
diff --git a/posthog/temporal/schedule.py b/posthog/temporal/schedule.py
index 8a1af78cb8b0..6fc3d28d252e 100644
--- a/posthog/temporal/schedule.py
+++ b/posthog/temporal/schedule.py
@@ -79,11 +79,9 @@ from posthog.temporal.warehouse_sources_queue_partition_management.schedule impo
from posthog.temporal.weekly_digest.types import WeeklyDigestInput
from products.business_knowledge.backend.temporal.schedule import create_business_knowledge_refresh_coordinator_schedule
-from products.error_tracking.backend.temporal.recommendations_refresh.types import RecommendationsRefreshInputs
-from products.error_tracking.backend.temporal.spike_event_cleanup.schedule import (
+from products.error_tracking.backend.facade.temporal import (
+ RecommendationsRefreshInputs,
create_error_tracking_spike_event_cleanup_schedule,
-)
-from products.error_tracking.backend.temporal.symbol_set_cleanup.schedule import (
create_error_tracking_symbol_set_cleanup_schedule,
)
from products.experiments.backend.temporal.schedule import create_experiment_precompute_canary_schedule
diff --git a/products/dashboards/backend/api/test/test_run_widgets.py b/products/dashboards/backend/api/test/test_run_widgets.py
index 26b1b3d61e1d..9d7d0444dbff 100644
--- a/products/dashboards/backend/api/test/test_run_widgets.py
+++ b/products/dashboards/backend/api/test/test_run_widgets.py
@@ -47,7 +47,7 @@ from products.dashboards.backend.widgets.activity_events_list import (
)
from products.dashboards.backend.widgets.error_tracking_list import run_error_tracking_list_widget
from products.dashboards.backend.widgets.session_replay_list import run_session_replay_list_widget
-from products.error_tracking.backend.api.query_utils import ERROR_TRACKING_LISTING_VOLUME_RESOLUTION
+from products.error_tracking.backend.facade.query_utils import ERROR_TRACKING_LISTING_VOLUME_RESOLUTION
class TestWidgetRegistry(APIBaseTest):
@@ -259,9 +259,7 @@ class TestDashboardRunWidgets(APIBaseTest):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn(expected_detail, response.json()["detail"])
- @patch(
- "products.error_tracking.backend.hogql_queries.error_tracking_query_runner.ErrorTrackingQueryRunner.calculate"
- )
+ @patch("products.error_tracking.backend.facade.queries.ErrorTrackingQueryRunner.calculate")
def test_runs_widget_for_requested_tile(self, mock_calculate: MagicMock) -> None:
mock_calculate.return_value = MagicMock(
model_dump=lambda mode="json": {"results": [], "hasMore": False, "limit": 10, "offset": 0}
@@ -896,9 +894,7 @@ class TestDashboardRunWidgets(APIBaseTest):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn(str(MAX_WIDGETS_BATCH_SIZE), response.json()["detail"])
- @patch(
- "products.error_tracking.backend.hogql_queries.error_tracking_query_runner.ErrorTrackingQueryRunner.calculate"
- )
+ @patch("products.error_tracking.backend.facade.queries.ErrorTrackingQueryRunner.calculate")
def test_run_widgets_deduplicates_tile_ids(self, mock_calculate: MagicMock) -> None:
mock_calculate.return_value = MagicMock(
model_dump=lambda mode="json": {"results": [], "hasMore": False, "limit": 10, "offset": 0}
@@ -952,9 +948,7 @@ class TestDashboardRunWidgets(APIBaseTest):
body = response.json()
self.assertEqual(body["results"][0]["error"], "API key missing required scope 'error_tracking:read'")
- @patch(
- "products.error_tracking.backend.hogql_queries.error_tracking_query_runner.ErrorTrackingQueryRunner.calculate"
- )
+ @patch("products.error_tracking.backend.facade.queries.ErrorTrackingQueryRunner.calculate")
@patch("posthog.slo.events.posthoganalytics.capture")
def test_run_widgets_emits_slo_on_successful_widget_delivery(
self, mock_capture: MagicMock, mock_calculate: MagicMock
diff --git a/products/dashboards/backend/widgets/error_tracking_list.py b/products/dashboards/backend/widgets/error_tracking_list.py
index f63c2b18a301..5421f34ff381 100644
--- a/products/dashboards/backend/widgets/error_tracking_list.py
+++ b/products/dashboards/backend/widgets/error_tracking_list.py
@@ -14,15 +14,15 @@ from products.dashboards.backend.widget_specs.registry import validate_widget_co
from products.dashboards.backend.widgets.config import resolve_filter_test_accounts
from products.dashboards.backend.widgets.list_widget import ListWidgetPage, run_list_widget
from products.dashboards.backend.widgets.widget_filters import build_property_group_filter_from_widget_filters
-from products.error_tracking.backend.api.query import normalize_volume_resolution
-from products.error_tracking.backend.api.query_utils import (
+from products.error_tracking.backend.facade.queries import ErrorTrackingQueryRunner
+from products.error_tracking.backend.facade.query_utils import (
ERROR_TRACKING_LISTING_VOLUME_RESOLUTION,
LIST_ISSUE_FIELDS,
build_date_range,
get_page_info,
+ normalize_volume_resolution,
pick_fields,
)
-from products.error_tracking.backend.hogql_queries.error_tracking_query_runner import ErrorTrackingQueryRunner
ValidatedErrorTrackingListWidgetConfig = dict[str, Any]
diff --git a/products/error_tracking/backend/api/__init__.py b/products/error_tracking/backend/api/__init__.py
deleted file mode 100644
index ab4c58e0f8f9..000000000000
--- a/products/error_tracking/backend/api/__init__.py
+++ /dev/null
@@ -1,33 +0,0 @@
-from .assignment_rules import ErrorTrackingAssignmentRuleViewSet
-from .external_references import ErrorTrackingExternalReferenceViewSet
-from .fingerprints import ErrorTrackingFingerprintViewSet
-from .git_provider_file_link_resolver import GitProviderFileLinksViewSet
-from .grouping_rules import ErrorTrackingGroupingRuleViewSet
-from .issues import ErrorTrackingIssueViewSet
-from .query import ErrorTrackingQueryViewSet
-from .recommendations import ErrorTrackingRecommendationViewSet
-from .releases import ErrorTrackingReleaseViewSet
-from .settings import ErrorTrackingSettingsViewSet
-from .spike_detection_config import ErrorTrackingSpikeDetectionConfigViewSet
-from .spike_events import ErrorTrackingSpikeEventViewSet
-from .stack_frames import ErrorTrackingStackFrameViewSet
-from .suppression_rules import ErrorTrackingSuppressionRuleViewSet
-from .symbol_sets import ErrorTrackingSymbolSetViewSet
-
-__all__ = [
- "ErrorTrackingExternalReferenceViewSet",
- "ErrorTrackingIssueViewSet",
- "ErrorTrackingQueryViewSet",
- "ErrorTrackingRecommendationViewSet",
- "ErrorTrackingStackFrameViewSet",
- "ErrorTrackingSymbolSetViewSet",
- "ErrorTrackingFingerprintViewSet",
- "ErrorTrackingGroupingRuleViewSet",
- "ErrorTrackingReleaseViewSet",
- "ErrorTrackingSettingsViewSet",
- "ErrorTrackingSpikeDetectionConfigViewSet",
- "ErrorTrackingSpikeEventViewSet",
- "ErrorTrackingSuppressionRuleViewSet",
- "ErrorTrackingAssignmentRuleViewSet",
- "GitProviderFileLinksViewSet",
-]
diff --git a/products/error_tracking/backend/api/external_references.py b/products/error_tracking/backend/api/external_references.py
deleted file mode 100644
index 5b6c4d475aed..000000000000
--- a/products/error_tracking/backend/api/external_references.py
+++ /dev/null
@@ -1,16 +0,0 @@
-"""Compatibility shim for external reference API classes.
-
-The canonical location is now `products.error_tracking.backend.presentation`.
-"""
-
-from products.error_tracking.backend.presentation.external_references import (
- ErrorTrackingExternalReferenceIntegrationSerializer,
- ErrorTrackingExternalReferenceSerializer,
- ErrorTrackingExternalReferenceViewSet,
-)
-
-__all__ = [
- "ErrorTrackingExternalReferenceIntegrationSerializer",
- "ErrorTrackingExternalReferenceSerializer",
- "ErrorTrackingExternalReferenceViewSet",
-]
diff --git a/products/error_tracking/backend/api/fingerprints.py b/products/error_tracking/backend/api/fingerprints.py
deleted file mode 100644
index 8c3bc1973676..000000000000
--- a/products/error_tracking/backend/api/fingerprints.py
+++ /dev/null
@@ -1,14 +0,0 @@
-"""Compatibility shim for fingerprint API classes.
-
-The canonical location is now `products.error_tracking.backend.presentation`.
-"""
-
-from products.error_tracking.backend.presentation.fingerprints import (
- ErrorTrackingFingerprintSerializer,
- ErrorTrackingFingerprintViewSet,
-)
-
-__all__ = [
- "ErrorTrackingFingerprintSerializer",
- "ErrorTrackingFingerprintViewSet",
-]
diff --git a/products/error_tracking/backend/api/git_provider_file_link_resolver.py b/products/error_tracking/backend/api/git_provider_file_link_resolver.py
deleted file mode 100644
index 19e96d9988dd..000000000000
--- a/products/error_tracking/backend/api/git_provider_file_link_resolver.py
+++ /dev/null
@@ -1,20 +0,0 @@
-"""Compatibility shim for git provider file link resolver API classes/functions.
-
-The canonical location is now `products.error_tracking.backend.presentation`.
-"""
-
-from products.error_tracking.backend.presentation.git_provider_file_link_resolver import (
- GitProviderFileLinksViewSet,
- get_github_file_url,
- get_gitlab_file_url,
- prepare_github_search_query,
- prepare_gitlab_search_query,
-)
-
-__all__ = [
- "prepare_github_search_query",
- "prepare_gitlab_search_query",
- "get_github_file_url",
- "get_gitlab_file_url",
- "GitProviderFileLinksViewSet",
-]
diff --git a/products/error_tracking/backend/facade/__init__.py b/products/error_tracking/backend/facade/__init__.py
index 303e63eef844..de0421fe2892 100644
--- a/products/error_tracking/backend/facade/__init__.py
+++ b/products/error_tracking/backend/facade/__init__.py
@@ -1,4 +1,4 @@
-from . import types
+from . import contracts
from .api import (
ExternalReferenceValidationError,
IssueNotFoundError,
@@ -39,7 +39,7 @@ __all__ = [
"get_daily_exception_counts",
"get_exception_counts",
"get_exception_summary_for_team",
- "types",
+ "contracts",
"get_external_reference",
"get_fingerprint",
"get_issue",
diff --git a/products/error_tracking/backend/facade/api.py b/products/error_tracking/backend/facade/api.py
index 9f407dde8ac7..873556ec3d6e 100644
--- a/products/error_tracking/backend/facade/api.py
+++ b/products/error_tracking/backend/facade/api.py
@@ -12,7 +12,7 @@ import posthoganalytics
from posthog.event_usage import groups
from .. import logic, weekly_digest
-from . import types as contracts
+from . import contracts
IssueNotFoundError = logic.ErrorTrackingIssueNotFoundError
ExternalReferenceValidationError = logic.ErrorTrackingExternalReferenceValidationError
diff --git a/products/error_tracking/backend/facade/types.py b/products/error_tracking/backend/facade/contracts.py
similarity index 74%
rename from products/error_tracking/backend/facade/types.py
rename to products/error_tracking/backend/facade/contracts.py
index 3bdc1520ef96..858e9b142775 100644
--- a/products/error_tracking/backend/facade/types.py
+++ b/products/error_tracking/backend/facade/contracts.py
@@ -1,13 +1,20 @@
-"""Transitional contract types for error tracking facade.
+"""Contract types for error tracking.
-These dataclasses are framework-free and represent the facade boundary.
-They will move to contracts.py when the product structure migration is complete.
+Stable, framework-free frozen dataclasses that define what this product
+exposes to the rest of the codebase. No Django imports.
+
+These use ``pydantic.dataclasses.dataclass`` rather than the stdlib variant — same
+syntax, same ``is_dataclass()`` compatibility, but with runtime validation on
+construction so structural mistakes from mappers or internal callers surface at the
+facade boundary instead of producing a malformed payload further downstream.
"""
-from dataclasses import dataclass, field
+from dataclasses import field
from datetime import datetime
from uuid import UUID
+from pydantic.dataclasses import dataclass
+
@dataclass(frozen=True)
class ErrorTrackingIssueAssignee:
diff --git a/products/error_tracking/backend/facade/import_map.md b/products/error_tracking/backend/facade/import_map.md
deleted file mode 100644
index 3b6da51690cf..000000000000
--- a/products/error_tracking/backend/facade/import_map.md
+++ /dev/null
@@ -1,48 +0,0 @@
-# Error tracking internal import map (phase 0)
-
-Generated during facade isolation kickoff.
-This tracks cross-product imports that currently bypass the facade.
-
-## Current public-ish surfaces consumed externally
-
-| Internal module | External consumers | Capability class |
-| --------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- |
-| `backend.models` | `posthog/models/remote_config.py`, `posthog/models/product_intent/product_intent.py`, `posthog/management/commands/*`, plus tests/admin/demo | read/list/detail, counters, async/task |
-| `backend.hogql_queries.*` | `posthog/hogql_queries/query_runner.py`, `products/signals/backend/temporal/backfill_error_tracking.py`, `products/posthog_ai/scripts/hogql_example/__init__.py` | read/list analytics query execution |
-| `backend.api` package | `posthog/api/__init__.py` | HTTP routing entrypoint |
-| `backend.api.issues` serializer | `backend/hogql_queries/error_tracking_issue_correlation_query_runner.py` | read/list serialization coupling |
-| `backend.remote_config` and `backend.api.suppression_rules` | `posthog/models/remote_config.py` | config read |
-| `backend.embedding`, `backend.indexed_embedding`, `backend.sql` | `posthog/clickhouse/schema.py`, `posthog/clickhouse/migrations/*`, `posthog/api/embedding_worker.py`, `products/signals/backend/management/commands/cleanup_signals.py`, `posthog/conftest.py` | schema/constants (infra) |
-| `backend.tools.search_issues` | `ee/hogai/core/agent_modes/presets/error_tracking.py` | tool invocation |
-
-## Initial migration focus (stack order)
-
-1. **Read-only issue access** (lowest risk): move model reads to `backend/facade/api.py` (`list_issues`, `get_issue`, `issue_exists`, fingerprint lookup, values lookup).
-2. **Cross-product issue readers**: migrate `ee/hogai/context/error_tracking/context.py`, `products/tasks/backend/repository_readiness.py`, `posthog/tasks/usage_report.py`. ✅ completed in PR 2.
-3. **Task and digest callers**: migrate `posthog/tasks/email.py` and `backend/weekly_digest.py` consumers. ✅ completed in PR 3.
-4. **Presentation migration**: move `backend/api/*.py` viewsets into `backend/presentation/views.py`/`serializers.py` and route through facade. ▶️ started in PR 4 by moving external references, fingerprints, and git provider file link resolver view/functions into `backend/presentation/` with compatibility shims.5. **Boundary enforcement + cleanup**: add `backend/facade/contracts.py`, `backend:contract-check`, and `tach` interface block once legacy paths are removed.
-
-## Graphite stack template
-
-```bash
-# Base branch
-
-gt checkout master
-
-gt create -m "chore(error-tracking): add facade kickoff and import map"
-# PR 1
-
-gt create -m "refactor(error-tracking): migrate issue readers to facade"
-# PR 2
-
-gt create -m "refactor(error-tracking): migrate digest and task callers"
-# PR 3
-
-gt create -m "refactor(error-tracking): move api viewsets to presentation layer"
-# PR 4
-
-gt create -m "chore(error-tracking): enforce facade interfaces and contracts"
-# PR 5
-```
-
-Use `gt modify -a` to amend each branch and `gt submit --stack` to open/update the full stacked PR chain.
diff --git a/products/error_tracking/backend/facade/queries.py b/products/error_tracking/backend/facade/queries.py
new file mode 100644
index 000000000000..7e376b87c045
--- /dev/null
+++ b/products/error_tracking/backend/facade/queries.py
@@ -0,0 +1,26 @@
+"""Facade re-exports for error tracking HogQL query runners.
+
+Core's query-runner registry (``posthog/hogql_queries/query_runner.py``) dispatches
+on query ``kind`` and constructs these runners by class identity. Re-exporting the
+classes keeps that registry coupling at the facade boundary while the heavy HogQL
+imports stay out of ``facade/api.py`` so config-only consumers don't drag them onto
+the ``django.setup()`` path.
+"""
+
+from products.error_tracking.backend.hogql_queries.error_tracking_breakdowns_query_runner import (
+ ErrorTrackingBreakdownsQueryRunner,
+)
+from products.error_tracking.backend.hogql_queries.error_tracking_issue_correlation_query_runner import (
+ ErrorTrackingIssueCorrelationQueryRunner,
+)
+from products.error_tracking.backend.hogql_queries.error_tracking_query_runner import ErrorTrackingQueryRunner
+from products.error_tracking.backend.hogql_queries.error_tracking_similar_issues_query_runner import (
+ ErrorTrackingSimilarIssuesQueryRunner,
+)
+
+__all__ = [
+ "ErrorTrackingBreakdownsQueryRunner",
+ "ErrorTrackingIssueCorrelationQueryRunner",
+ "ErrorTrackingQueryRunner",
+ "ErrorTrackingSimilarIssuesQueryRunner",
+]
diff --git a/products/error_tracking/backend/api/query_utils.py b/products/error_tracking/backend/facade/query_utils.py
similarity index 99%
rename from products/error_tracking/backend/api/query_utils.py
rename to products/error_tracking/backend/facade/query_utils.py
index 1a662f90d0da..5ca62f60e1e3 100644
--- a/products/error_tracking/backend/api/query_utils.py
+++ b/products/error_tracking/backend/facade/query_utils.py
@@ -36,6 +36,11 @@ LIST_ISSUE_FIELDS = [
# Keep in sync with ERROR_TRACKING_LISTING_RESOLUTION in products/error_tracking/frontend/utils.ts
ERROR_TRACKING_LISTING_VOLUME_RESOLUTION = 20
+
+def normalize_volume_resolution(volume_resolution: int) -> int:
+ return max(volume_resolution, 1)
+
+
CONTEXT_EVENT_SELECTS = ["properties.$exception_list", "properties.$exception_releases"]
EVENT_PROPERTY_SELECTS = [
"properties.$exception_types",
diff --git a/products/error_tracking/backend/facade/temporal.py b/products/error_tracking/backend/facade/temporal.py
new file mode 100644
index 000000000000..cb658f1a8042
--- /dev/null
+++ b/products/error_tracking/backend/facade/temporal.py
@@ -0,0 +1,24 @@
+"""Facade re-exports for error tracking Temporal wiring.
+
+Core registers these with the Temporal worker (``start_temporal_worker``) and the
+schedule bootstrap (``posthog/temporal/schedule.py``). They cross the boundary as
+objects, not data, so they live in their own facade submodule — keeping the
+``temporalio`` imports out of ``facade/api.py``.
+"""
+
+from products.error_tracking.backend.temporal import ACTIVITIES, WORKFLOWS
+from products.error_tracking.backend.temporal.recommendations_refresh.types import RecommendationsRefreshInputs
+from products.error_tracking.backend.temporal.spike_event_cleanup.schedule import (
+ create_error_tracking_spike_event_cleanup_schedule,
+)
+from products.error_tracking.backend.temporal.symbol_set_cleanup.schedule import (
+ create_error_tracking_symbol_set_cleanup_schedule,
+)
+
+__all__ = [
+ "ACTIVITIES",
+ "WORKFLOWS",
+ "RecommendationsRefreshInputs",
+ "create_error_tracking_spike_event_cleanup_schedule",
+ "create_error_tracking_symbol_set_cleanup_schedule",
+]
diff --git a/products/error_tracking/backend/facade/tools.py b/products/error_tracking/backend/facade/tools.py
new file mode 100644
index 000000000000..9524f243a6a8
--- /dev/null
+++ b/products/error_tracking/backend/facade/tools.py
@@ -0,0 +1,12 @@
+"""Facade re-export for error tracking Max tools.
+
+The AI agent presets (``ee/hogai``) register this tool class with the assistant.
+It crosses the boundary as an object, not data, so it lives in its own facade
+submodule. ``search_issues`` imports ``ee.hogai`` itself, so consumers must keep
+importing this lazily (inside the registration call site) to avoid a circular
+import on the ``django.setup()`` path.
+"""
+
+from products.error_tracking.backend.logic.tools.search_issues import SearchErrorTrackingIssuesTool
+
+__all__ = ["SearchErrorTrackingIssuesTool"]
diff --git a/products/error_tracking/backend/hogql_queries/test/test_error_tracking_breakdowns_query_runner.py b/products/error_tracking/backend/hogql_queries/test/test_error_tracking_breakdowns_query_runner.py
index 1c444f372de6..71c0201a92a5 100644
--- a/products/error_tracking/backend/hogql_queries/test/test_error_tracking_breakdowns_query_runner.py
+++ b/products/error_tracking/backend/hogql_queries/test/test_error_tracking_breakdowns_query_runner.py
@@ -21,6 +21,17 @@ class TestErrorTrackingBreakdownsQueryRunner(ClickhouseTestMixin, APIBaseTest):
issue_id = "01936e7f-d7ff-7314-b2d4-7627981e34f0"
fingerprint = "test_fingerprint"
+ @classmethod
+ def setUpClass(cls):
+ # Materialize $exception_issue_id so the rendered SQL deterministically uses the
+ # materialized column (as in production) regardless of test execution order, rather
+ # than depending on another test having materialized it first on the shared table.
+ from ee.clickhouse.materialized_columns.columns import get_materialized_columns, materialize
+
+ if ("$exception_issue_id", "properties") not in get_materialized_columns("events"):
+ materialize("events", "$exception_issue_id", is_nullable=True)
+ super().setUpClass()
+
def create_issue(self, issue_id, fingerprint):
issue = ErrorTrackingIssue.objects.create(id=issue_id, team=self.team)
ErrorTrackingIssueFingerprintV2.objects.create(team=self.team, issue=issue, fingerprint=fingerprint)
diff --git a/products/error_tracking/backend/hogql_queries/test/test_error_tracking_issue_correlation_query_runner.py b/products/error_tracking/backend/hogql_queries/test/test_error_tracking_issue_correlation_query_runner.py
index 5ba71dd71e03..eeb3277b7ea9 100644
--- a/products/error_tracking/backend/hogql_queries/test/test_error_tracking_issue_correlation_query_runner.py
+++ b/products/error_tracking/backend/hogql_queries/test/test_error_tracking_issue_correlation_query_runner.py
@@ -9,6 +9,17 @@ from products.error_tracking.backend.hogql_queries.error_tracking_issue_correlat
class TestErrorTrackingIssueCorrelationQueryRunner(ClickhouseTestMixin, APIBaseTest):
+ @classmethod
+ def setUpClass(cls):
+ # Materialize $exception_issue_id so the rendered SQL deterministically uses the
+ # materialized column (as in production) regardless of test execution order, rather
+ # than depending on another test having materialized it first on the shared table.
+ from ee.clickhouse.materialized_columns.columns import get_materialized_columns, materialize
+
+ if ("$exception_issue_id", "properties") not in get_materialized_columns("events"):
+ materialize("events", "$exception_issue_id", is_nullable=True)
+ super().setUpClass()
+
def _calculate(
self,
):
diff --git a/products/error_tracking/backend/logic.py b/products/error_tracking/backend/logic/__init__.py
similarity index 100%
rename from products/error_tracking/backend/logic.py
rename to products/error_tracking/backend/logic/__init__.py
diff --git a/products/error_tracking/backend/recommendations/__init__.py b/products/error_tracking/backend/logic/recommendations/__init__.py
similarity index 100%
rename from products/error_tracking/backend/recommendations/__init__.py
rename to products/error_tracking/backend/logic/recommendations/__init__.py
diff --git a/products/error_tracking/backend/recommendations/alerts.py b/products/error_tracking/backend/logic/recommendations/alerts.py
similarity index 100%
rename from products/error_tracking/backend/recommendations/alerts.py
rename to products/error_tracking/backend/logic/recommendations/alerts.py
diff --git a/products/error_tracking/backend/recommendations/base.py b/products/error_tracking/backend/logic/recommendations/base.py
similarity index 100%
rename from products/error_tracking/backend/recommendations/base.py
rename to products/error_tracking/backend/logic/recommendations/base.py
diff --git a/products/error_tracking/backend/recommendations/long_running_issues.py b/products/error_tracking/backend/logic/recommendations/long_running_issues.py
similarity index 100%
rename from products/error_tracking/backend/recommendations/long_running_issues.py
rename to products/error_tracking/backend/logic/recommendations/long_running_issues.py
diff --git a/products/error_tracking/backend/recommendations/rate_limits.py b/products/error_tracking/backend/logic/recommendations/rate_limits.py
similarity index 100%
rename from products/error_tracking/backend/recommendations/rate_limits.py
rename to products/error_tracking/backend/logic/recommendations/rate_limits.py
diff --git a/products/error_tracking/backend/recommendations/refresh.py b/products/error_tracking/backend/logic/recommendations/refresh.py
similarity index 98%
rename from products/error_tracking/backend/recommendations/refresh.py
rename to products/error_tracking/backend/logic/recommendations/refresh.py
index 360f89129844..c86ff348d18b 100644
--- a/products/error_tracking/backend/recommendations/refresh.py
+++ b/products/error_tracking/backend/logic/recommendations/refresh.py
@@ -11,9 +11,9 @@ from posthoganalytics import capture_exception
from posthog.models import Team
+from products.error_tracking.backend.logic.recommendations import RECOMMENDATIONS
+from products.error_tracking.backend.logic.recommendations.base import Recommendation
from products.error_tracking.backend.models import ErrorTrackingRecommendation
-from products.error_tracking.backend.recommendations import RECOMMENDATIONS
-from products.error_tracking.backend.recommendations.base import Recommendation
from products.error_tracking.backend.tasks import compute_error_tracking_recommendation
logger = structlog.get_logger(__name__)
diff --git a/products/error_tracking/backend/recommendations/source_maps.py b/products/error_tracking/backend/logic/recommendations/source_maps.py
similarity index 100%
rename from products/error_tracking/backend/recommendations/source_maps.py
rename to products/error_tracking/backend/logic/recommendations/source_maps.py
diff --git a/products/error_tracking/backend/tools/__init__.py b/products/error_tracking/backend/logic/tools/__init__.py
similarity index 100%
rename from products/error_tracking/backend/tools/__init__.py
rename to products/error_tracking/backend/logic/tools/__init__.py
diff --git a/products/error_tracking/backend/tools/search_issues.py b/products/error_tracking/backend/logic/tools/search_issues.py
similarity index 100%
rename from products/error_tracking/backend/tools/search_issues.py
rename to products/error_tracking/backend/logic/tools/search_issues.py
diff --git a/products/error_tracking/backend/tools/test/__init__.py b/products/error_tracking/backend/logic/tools/test/__init__.py
similarity index 100%
rename from products/error_tracking/backend/tools/test/__init__.py
rename to products/error_tracking/backend/logic/tools/test/__init__.py
diff --git a/products/error_tracking/backend/tools/test/test_search_issues.py b/products/error_tracking/backend/logic/tools/test/test_search_issues.py
similarity index 99%
rename from products/error_tracking/backend/tools/test/test_search_issues.py
rename to products/error_tracking/backend/logic/tools/test/test_search_issues.py
index b90529f65792..298d422f6329 100644
--- a/products/error_tracking/backend/tools/test/test_search_issues.py
+++ b/products/error_tracking/backend/logic/tools/test/test_search_issues.py
@@ -22,12 +22,12 @@ from posthog.schema import (
MaxErrorTrackingSearchResponse,
)
+from products.error_tracking.backend.logic.tools.search_issues import SearchErrorTrackingIssuesTool
from products.error_tracking.backend.models import (
ErrorTrackingIssue,
ErrorTrackingIssueFingerprintV2,
sync_issues_to_clickhouse,
)
-from products.error_tracking.backend.tools.search_issues import SearchErrorTrackingIssuesTool
from ee.hogai.context.context import AssistantContextManager
from ee.hogai.utils.types import AssistantState
diff --git a/products/error_tracking/backend/presentation/views/__init__.py b/products/error_tracking/backend/presentation/views/__init__.py
new file mode 100644
index 000000000000..778dbdccfcd2
--- /dev/null
+++ b/products/error_tracking/backend/presentation/views/__init__.py
@@ -0,0 +1,37 @@
+from products.error_tracking.backend.presentation.views.assignment_rules import ErrorTrackingAssignmentRuleViewSet
+from products.error_tracking.backend.presentation.views.external_references import ErrorTrackingExternalReferenceViewSet
+from products.error_tracking.backend.presentation.views.fingerprints import ErrorTrackingFingerprintViewSet
+from products.error_tracking.backend.presentation.views.git_provider_file_link_resolver import (
+ GitProviderFileLinksViewSet,
+)
+from products.error_tracking.backend.presentation.views.grouping_rules import ErrorTrackingGroupingRuleViewSet
+from products.error_tracking.backend.presentation.views.issues import ErrorTrackingIssueViewSet
+from products.error_tracking.backend.presentation.views.query import ErrorTrackingQueryViewSet
+from products.error_tracking.backend.presentation.views.recommendations import ErrorTrackingRecommendationViewSet
+from products.error_tracking.backend.presentation.views.releases import ErrorTrackingReleaseViewSet
+from products.error_tracking.backend.presentation.views.settings import ErrorTrackingSettingsViewSet
+from products.error_tracking.backend.presentation.views.spike_detection_config import (
+ ErrorTrackingSpikeDetectionConfigViewSet,
+)
+from products.error_tracking.backend.presentation.views.spike_events import ErrorTrackingSpikeEventViewSet
+from products.error_tracking.backend.presentation.views.stack_frames import ErrorTrackingStackFrameViewSet
+from products.error_tracking.backend.presentation.views.suppression_rules import ErrorTrackingSuppressionRuleViewSet
+from products.error_tracking.backend.presentation.views.symbol_sets import ErrorTrackingSymbolSetViewSet
+
+__all__ = [
+ "ErrorTrackingExternalReferenceViewSet",
+ "ErrorTrackingIssueViewSet",
+ "ErrorTrackingQueryViewSet",
+ "ErrorTrackingRecommendationViewSet",
+ "ErrorTrackingStackFrameViewSet",
+ "ErrorTrackingSymbolSetViewSet",
+ "ErrorTrackingFingerprintViewSet",
+ "ErrorTrackingGroupingRuleViewSet",
+ "ErrorTrackingReleaseViewSet",
+ "ErrorTrackingSettingsViewSet",
+ "ErrorTrackingSpikeDetectionConfigViewSet",
+ "ErrorTrackingSpikeEventViewSet",
+ "ErrorTrackingSuppressionRuleViewSet",
+ "ErrorTrackingAssignmentRuleViewSet",
+ "GitProviderFileLinksViewSet",
+]
diff --git a/products/error_tracking/backend/api/assignment_rules.py b/products/error_tracking/backend/presentation/views/assignment_rules.py
similarity index 97%
rename from products/error_tracking/backend/api/assignment_rules.py
rename to products/error_tracking/backend/presentation/views/assignment_rules.py
index bad56624209e..77234cd10ad7 100644
--- a/products/error_tracking/backend/api/assignment_rules.py
+++ b/products/error_tracking/backend/presentation/views/assignment_rules.py
@@ -14,8 +14,12 @@ from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.event_usage import groups
from products.error_tracking.backend.models import ErrorTrackingAssignmentRule
-
-from .utils import RuleReorderingMixin, generate_byte_code, generate_match_all_bytecode, has_filter_values
+from products.error_tracking.backend.presentation.views.utils import (
+ RuleReorderingMixin,
+ generate_byte_code,
+ generate_match_all_bytecode,
+ has_filter_values,
+)
logger = structlog.get_logger(__name__)
diff --git a/products/error_tracking/backend/presentation/external_references.py b/products/error_tracking/backend/presentation/views/external_references.py
similarity index 98%
rename from products/error_tracking/backend/presentation/external_references.py
rename to products/error_tracking/backend/presentation/views/external_references.py
index 7f7fe568cefa..ba429867671a 100644
--- a/products/error_tracking/backend/presentation/external_references.py
+++ b/products/error_tracking/backend/presentation/views/external_references.py
@@ -9,7 +9,7 @@ from rest_framework.response import Response
from posthog.api.forbid_destroy_model import ForbidDestroyModel
from posthog.api.routing import TeamAndOrgViewSetMixin
-from products.error_tracking.backend.facade import types as contracts
+from products.error_tracking.backend.facade import contracts
from products.error_tracking.backend.facade.api import (
ExternalReferenceValidationError,
create_external_reference,
diff --git a/products/error_tracking/backend/presentation/fingerprints.py b/products/error_tracking/backend/presentation/views/fingerprints.py
similarity index 100%
rename from products/error_tracking/backend/presentation/fingerprints.py
rename to products/error_tracking/backend/presentation/views/fingerprints.py
diff --git a/products/error_tracking/backend/presentation/git_provider_file_link_resolver.py b/products/error_tracking/backend/presentation/views/git_provider_file_link_resolver.py
similarity index 100%
rename from products/error_tracking/backend/presentation/git_provider_file_link_resolver.py
rename to products/error_tracking/backend/presentation/views/git_provider_file_link_resolver.py
diff --git a/products/error_tracking/backend/api/grouping_rules.py b/products/error_tracking/backend/presentation/views/grouping_rules.py
similarity index 98%
rename from products/error_tracking/backend/api/grouping_rules.py
rename to products/error_tracking/backend/presentation/views/grouping_rules.py
index 5ab908614bfd..ae37398f3037 100644
--- a/products/error_tracking/backend/api/grouping_rules.py
+++ b/products/error_tracking/backend/presentation/views/grouping_rules.py
@@ -15,8 +15,11 @@ from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.event_usage import groups
from products.error_tracking.backend.models import ErrorTrackingGroupingRule, ErrorTrackingIssueFingerprintV2
-
-from .utils import RuleReorderingMixin, generate_byte_code, has_filter_values
+from products.error_tracking.backend.presentation.views.utils import (
+ RuleReorderingMixin,
+ generate_byte_code,
+ has_filter_values,
+)
logger = structlog.get_logger(__name__)
diff --git a/products/error_tracking/backend/api/issues.py b/products/error_tracking/backend/presentation/views/issues.py
similarity index 99%
rename from products/error_tracking/backend/api/issues.py
rename to products/error_tracking/backend/presentation/views/issues.py
index 27244d9588cb..c19c0fe4c673 100644
--- a/products/error_tracking/backend/api/issues.py
+++ b/products/error_tracking/backend/presentation/views/issues.py
@@ -32,8 +32,9 @@ from products.error_tracking.backend.models import (
sync_issues_to_clickhouse,
)
from products.error_tracking.backend.notifications import dispatch_issue_assigned_realtime
-
-from .external_references import ErrorTrackingExternalReferenceSerializer
+from products.error_tracking.backend.presentation.views.external_references import (
+ ErrorTrackingExternalReferenceSerializer,
+)
IssueNotFoundError = facade_api.IssueNotFoundError
diff --git a/products/error_tracking/backend/api/query.py b/products/error_tracking/backend/presentation/views/query.py
similarity index 98%
rename from products/error_tracking/backend/api/query.py
rename to products/error_tracking/backend/presentation/views/query.py
index 6e2653274e42..089e7788295e 100644
--- a/products/error_tracking/backend/api/query.py
+++ b/products/error_tracking/backend/presentation/views/query.py
@@ -15,18 +15,7 @@ from posthog.api.utils import action
from posthog.clickhouse.query_tagging import Feature, Product, tags_context
from posthog.hogql_queries.events_query_runner import EventsQueryRunner
-from products.error_tracking.backend.hogql_queries.error_tracking_query_runner import ErrorTrackingQueryRunner
-from products.error_tracking.backend.models import ErrorTrackingIssue, resolve_fingerprints_for_issues
-
-from .query_serializers import (
- ErrorTrackingIssueDetailSerializer,
- ErrorTrackingIssueEventsQueryRequestSerializer,
- ErrorTrackingIssueEventsResponseSerializer,
- ErrorTrackingIssueQueryRequestSerializer,
- ErrorTrackingIssuesListQueryRequestSerializer,
- ErrorTrackingIssuesListResponseSerializer,
-)
-from .query_utils import (
+from products.error_tracking.backend.facade.query_utils import (
CONTEXT_EVENT_SELECTS,
EVENT_SELECTS,
ISSUE_FIELDS,
@@ -45,16 +34,23 @@ from .query_utils import (
get_page_info,
map_context_event_properties,
map_event_row,
+ normalize_volume_resolution,
pick_fields,
)
+from products.error_tracking.backend.hogql_queries.error_tracking_query_runner import ErrorTrackingQueryRunner
+from products.error_tracking.backend.models import ErrorTrackingIssue, resolve_fingerprints_for_issues
+from products.error_tracking.backend.presentation.views.query_serializers import (
+ ErrorTrackingIssueDetailSerializer,
+ ErrorTrackingIssueEventsQueryRequestSerializer,
+ ErrorTrackingIssueEventsResponseSerializer,
+ ErrorTrackingIssueQueryRequestSerializer,
+ ErrorTrackingIssuesListQueryRequestSerializer,
+ ErrorTrackingIssuesListResponseSerializer,
+)
logger = structlog.get_logger(__name__)
-def normalize_volume_resolution(volume_resolution: int) -> int:
- return max(volume_resolution, 1)
-
-
def build_fingerprint_filter_group(fingerprints: list[str]) -> dict[str, object]:
filter_group = build_property_group(
[{"type": "event", "key": "$exception_fingerprint", "operator": "exact", "value": fingerprints}]
diff --git a/products/error_tracking/backend/api/query_serializers.py b/products/error_tracking/backend/presentation/views/query_serializers.py
similarity index 100%
rename from products/error_tracking/backend/api/query_serializers.py
rename to products/error_tracking/backend/presentation/views/query_serializers.py
diff --git a/products/error_tracking/backend/api/recommendations.py b/products/error_tracking/backend/presentation/views/recommendations.py
similarity index 97%
rename from products/error_tracking/backend/api/recommendations.py
rename to products/error_tracking/backend/presentation/views/recommendations.py
index f16d0ceb5ba1..67d86798a3c3 100644
--- a/products/error_tracking/backend/api/recommendations.py
+++ b/products/error_tracking/backend/presentation/views/recommendations.py
@@ -10,13 +10,13 @@ from rest_framework.response import Response
from posthog.api.routing import TeamAndOrgViewSetMixin
-from products.error_tracking.backend.models import ErrorTrackingRecommendation
-from products.error_tracking.backend.recommendations import RECOMMENDATIONS_BY_TYPE
-from products.error_tracking.backend.recommendations.refresh import (
+from products.error_tracking.backend.logic.recommendations import RECOMMENDATIONS_BY_TYPE
+from products.error_tracking.backend.logic.recommendations.refresh import (
claim_for_compute,
refresh_team_recommendations,
revert_to_ready,
)
+from products.error_tracking.backend.models import ErrorTrackingRecommendation
from products.error_tracking.backend.tasks import compute_error_tracking_recommendation
diff --git a/products/error_tracking/backend/api/releases.py b/products/error_tracking/backend/presentation/views/releases.py
similarity index 100%
rename from products/error_tracking/backend/api/releases.py
rename to products/error_tracking/backend/presentation/views/releases.py
diff --git a/products/error_tracking/backend/api/settings.py b/products/error_tracking/backend/presentation/views/settings.py
similarity index 100%
rename from products/error_tracking/backend/api/settings.py
rename to products/error_tracking/backend/presentation/views/settings.py
diff --git a/products/error_tracking/backend/api/spike_detection_config.py b/products/error_tracking/backend/presentation/views/spike_detection_config.py
similarity index 100%
rename from products/error_tracking/backend/api/spike_detection_config.py
rename to products/error_tracking/backend/presentation/views/spike_detection_config.py
diff --git a/products/error_tracking/backend/api/spike_events.py b/products/error_tracking/backend/presentation/views/spike_events.py
similarity index 100%
rename from products/error_tracking/backend/api/spike_events.py
rename to products/error_tracking/backend/presentation/views/spike_events.py
diff --git a/products/error_tracking/backend/api/stack_frames.py b/products/error_tracking/backend/presentation/views/stack_frames.py
similarity index 95%
rename from products/error_tracking/backend/api/stack_frames.py
rename to products/error_tracking/backend/presentation/views/stack_frames.py
index ed423697aa80..c5269fc68275 100644
--- a/products/error_tracking/backend/api/stack_frames.py
+++ b/products/error_tracking/backend/presentation/views/stack_frames.py
@@ -10,8 +10,7 @@ from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.utils import action
from products.error_tracking.backend.models import ErrorTrackingStackFrame
-
-from .releases import ErrorTrackingReleaseSerializer
+from products.error_tracking.backend.presentation.views.releases import ErrorTrackingReleaseSerializer
logger = structlog.get_logger(__name__)
diff --git a/products/error_tracking/backend/api/suppression_rules.py b/products/error_tracking/backend/presentation/views/suppression_rules.py
similarity index 97%
rename from products/error_tracking/backend/api/suppression_rules.py
rename to products/error_tracking/backend/presentation/views/suppression_rules.py
index 69f0074d089e..1e13d2aa3dc7 100644
--- a/products/error_tracking/backend/api/suppression_rules.py
+++ b/products/error_tracking/backend/presentation/views/suppression_rules.py
@@ -15,8 +15,12 @@ from posthog.event_usage import groups
from posthog.models.team.team import Team
from products.error_tracking.backend.models import ErrorTrackingSuppressionRule
-
-from .utils import RuleReorderingMixin, generate_byte_code, generate_match_all_bytecode, has_filter_values
+from products.error_tracking.backend.presentation.views.utils import (
+ RuleReorderingMixin,
+ generate_byte_code,
+ generate_match_all_bytecode,
+ has_filter_values,
+)
logger = structlog.get_logger(__name__)
diff --git a/products/error_tracking/backend/api/symbol_sets.py b/products/error_tracking/backend/presentation/views/symbol_sets.py
similarity index 99%
rename from products/error_tracking/backend/api/symbol_sets.py
rename to products/error_tracking/backend/presentation/views/symbol_sets.py
index a4ced0da183e..c719c83baf2f 100644
--- a/products/error_tracking/backend/api/symbol_sets.py
+++ b/products/error_tracking/backend/presentation/views/symbol_sets.py
@@ -113,7 +113,7 @@ class ErrorTrackingSymbolSetSerializer(serializers.ModelSerializer):
@extend_schema_field(serializers.DictField(allow_null=True, help_text="Release associated with this symbol set"))
def get_release(self, obj):
- from products.error_tracking.backend.api.releases import ErrorTrackingReleaseSerializer
+ from products.error_tracking.backend.presentation.views.releases import ErrorTrackingReleaseSerializer
if obj.release:
return ErrorTrackingReleaseSerializer(obj.release).data
diff --git a/products/error_tracking/backend/api/utils.py b/products/error_tracking/backend/presentation/views/utils.py
similarity index 100%
rename from products/error_tracking/backend/api/utils.py
rename to products/error_tracking/backend/presentation/views/utils.py
diff --git a/products/error_tracking/backend/remote_config.py b/products/error_tracking/backend/remote_config.py
index d26f1f91d477..49c33e9c7e1c 100644
--- a/products/error_tracking/backend/remote_config.py
+++ b/products/error_tracking/backend/remote_config.py
@@ -1,6 +1,6 @@
from posthog.models.team.team import Team
-from products.error_tracking.backend.api.suppression_rules import get_client_safe_suppression_rules
+from products.error_tracking.backend.presentation.views.suppression_rules import get_client_safe_suppression_rules
def build_error_tracking_config(team: Team) -> dict:
diff --git a/products/error_tracking/backend/routes.py b/products/error_tracking/backend/routes.py
index 1e6e0b887761..8b4ec41a8bf6 100644
--- a/products/error_tracking/backend/routes.py
+++ b/products/error_tracking/backend/routes.py
@@ -1,6 +1,6 @@
from posthog.api.routing import RouterRegistry
-from products.error_tracking.backend.api import (
+from products.error_tracking.backend.presentation.views import (
ErrorTrackingAssignmentRuleViewSet,
ErrorTrackingExternalReferenceViewSet,
ErrorTrackingFingerprintViewSet,
diff --git a/products/error_tracking/backend/tasks/__init__.py b/products/error_tracking/backend/tasks/__init__.py
new file mode 100644
index 000000000000..66ea641cee41
--- /dev/null
+++ b/products/error_tracking/backend/tasks/__init__.py
@@ -0,0 +1 @@
+from products.error_tracking.backend.tasks.tasks import compute_error_tracking_recommendation # noqa: F401
diff --git a/products/error_tracking/backend/tasks.py b/products/error_tracking/backend/tasks/tasks.py
similarity index 87%
rename from products/error_tracking/backend/tasks.py
rename to products/error_tracking/backend/tasks/tasks.py
index cec81a8df5f5..2ae31d0b8173 100644
--- a/products/error_tracking/backend/tasks.py
+++ b/products/error_tracking/backend/tasks/tasks.py
@@ -6,13 +6,17 @@ from posthoganalytics import capture_exception
from posthog.models.scoping import with_team_scope
+from products.error_tracking.backend.logic.recommendations import RECOMMENDATIONS_BY_TYPE
from products.error_tracking.backend.models import ErrorTrackingRecommendation
-from products.error_tracking.backend.recommendations import RECOMMENDATIONS_BY_TYPE
logger = structlog.get_logger(__name__)
-@shared_task(ignore_result=True, max_retries=0)
+@shared_task(
+ name="products.error_tracking.backend.tasks.compute_error_tracking_recommendation",
+ ignore_result=True,
+ max_retries=0,
+)
@with_team_scope()
def compute_error_tracking_recommendation(recommendation_id: str, team_id: int) -> None:
try:
diff --git a/products/error_tracking/backend/temporal/recommendations_refresh/activities.py b/products/error_tracking/backend/temporal/recommendations_refresh/activities.py
index c4649644ad53..2a77ea2d22be 100644
--- a/products/error_tracking/backend/temporal/recommendations_refresh/activities.py
+++ b/products/error_tracking/backend/temporal/recommendations_refresh/activities.py
@@ -4,7 +4,7 @@ from temporalio import activity
from posthog.clickhouse.client import sync_execute
from posthog.clickhouse.workload import Workload
-from products.error_tracking.backend.recommendations.refresh import refresh_teams_recommendations_batched
+from products.error_tracking.backend.logic.recommendations.refresh import refresh_teams_recommendations_batched
from products.error_tracking.backend.temporal.recommendations_refresh.types import (
RecommendationsRefreshInputs,
RefreshBatchInputs,
diff --git a/products/error_tracking/backend/temporal/recommendations_refresh/test/test_recommendations_refresh.py b/products/error_tracking/backend/temporal/recommendations_refresh/test/test_recommendations_refresh.py
index 6aad4f8b9aec..9d368713bfcd 100644
--- a/products/error_tracking/backend/temporal/recommendations_refresh/test/test_recommendations_refresh.py
+++ b/products/error_tracking/backend/temporal/recommendations_refresh/test/test_recommendations_refresh.py
@@ -14,13 +14,13 @@ from temporalio.worker import UnsandboxedWorkflowRunner, Worker
from posthog.models import Team
+from products.error_tracking.backend.logic.recommendations.long_running_issues import LongRunningIssuesRecommendation
from products.error_tracking.backend.models import (
ErrorTrackingIssue,
ErrorTrackingIssueFingerprintV2,
ErrorTrackingRecommendation,
sync_issues_to_clickhouse,
)
-from products.error_tracking.backend.recommendations.long_running_issues import LongRunningIssuesRecommendation
from products.error_tracking.backend.sql import TRUNCATE_ERROR_TRACKING_FINGERPRINT_ISSUE_STATE_TABLE_SQL
from products.error_tracking.backend.temporal.recommendations_refresh.activities import (
get_team_batches_activity,
@@ -37,15 +37,15 @@ from products.error_tracking.backend.temporal.recommendations_refresh.workflow i
ErrorTrackingRecommendationsRefreshWorkflow,
)
-_ALERTS_COMPUTE_BATCH = "products.error_tracking.backend.recommendations.alerts.AlertsRecommendation.compute_batch"
-_LONG_RUNNING_COMPUTE_BATCH = (
- "products.error_tracking.backend.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute_batch"
+_ALERTS_COMPUTE_BATCH = (
+ "products.error_tracking.backend.logic.recommendations.alerts.AlertsRecommendation.compute_batch"
)
+_LONG_RUNNING_COMPUTE_BATCH = "products.error_tracking.backend.logic.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute_batch"
_SOURCE_MAPS_COMPUTE_BATCH = (
- "products.error_tracking.backend.recommendations.source_maps.SourceMapsRecommendation.compute_batch"
+ "products.error_tracking.backend.logic.recommendations.source_maps.SourceMapsRecommendation.compute_batch"
)
_RATE_LIMITS_COMPUTE_BATCH = (
- "products.error_tracking.backend.recommendations.rate_limits.RateLimitsRecommendation.compute_batch"
+ "products.error_tracking.backend.logic.recommendations.rate_limits.RateLimitsRecommendation.compute_batch"
)
_ALERTS_META = {"alerts": [{"key": "error-tracking-issue-created", "enabled": False}]}
diff --git a/products/error_tracking/backend/test/test_facade_api.py b/products/error_tracking/backend/test/test_facade_api.py
index 5e92ed358f6d..fe0866679280 100644
--- a/products/error_tracking/backend/test/test_facade_api.py
+++ b/products/error_tracking/backend/test/test_facade_api.py
@@ -8,10 +8,7 @@ from parameterized import parameterized
from posthog.models import Team
-from products.error_tracking.backend.facade import (
- api,
- types as contracts,
-)
+from products.error_tracking.backend.facade import api, contracts
from products.error_tracking.backend.models import (
ErrorTrackingIssue,
ErrorTrackingIssueAssignment,
diff --git a/products/error_tracking/backend/api/test/fixtures/source.js.map b/products/error_tracking/backend/tests/api/fixtures/source.js.map
similarity index 100%
rename from products/error_tracking/backend/api/test/fixtures/source.js.map
rename to products/error_tracking/backend/tests/api/fixtures/source.js.map
diff --git a/products/error_tracking/backend/api/test/test_assignment_rules.py b/products/error_tracking/backend/tests/api/test_assignment_rules.py
similarity index 99%
rename from products/error_tracking/backend/api/test/test_assignment_rules.py
rename to products/error_tracking/backend/tests/api/test_assignment_rules.py
index d104fbd5e02e..b974d1090792 100644
--- a/products/error_tracking/backend/api/test/test_assignment_rules.py
+++ b/products/error_tracking/backend/tests/api/test_assignment_rules.py
@@ -6,8 +6,8 @@ from posthog.test.base import APIBaseTest
from parameterized import parameterized
from rest_framework import status
-from products.error_tracking.backend.api.utils import generate_match_all_bytecode
from products.error_tracking.backend.models import ErrorTrackingAssignmentRule
+from products.error_tracking.backend.presentation.views.utils import generate_match_all_bytecode
VALID_FILTERS = {
"type": "AND",
diff --git a/products/error_tracking/backend/api/test/test_error_tracking_api.py b/products/error_tracking/backend/tests/api/test_error_tracking_api.py
similarity index 99%
rename from products/error_tracking/backend/api/test/test_error_tracking_api.py
rename to products/error_tracking/backend/tests/api/test_error_tracking_api.py
index 71a2801a7ef5..ad1ae04c6808 100644
--- a/products/error_tracking/backend/api/test/test_error_tracking_api.py
+++ b/products/error_tracking/backend/tests/api/test_error_tracking_api.py
@@ -491,7 +491,7 @@ class TestErrorTracking(APIBaseTest):
symbol_set.refresh_from_db()
self.assertEqual(symbol_set.storage_ptr, "symbolsets/source_1")
- @patch("products.error_tracking.backend.api.symbol_sets.object_storage.get_presigned_url")
+ @patch("products.error_tracking.backend.presentation.views.symbol_sets.object_storage.get_presigned_url")
def test_download_symbol_set(self, patched_get_presigned_url: Mock) -> None:
patched_get_presigned_url.return_value = "https://example.com/source.map"
symbol_set = ErrorTrackingSymbolSet.objects.create(
@@ -606,8 +606,8 @@ class TestErrorTracking(APIBaseTest):
# cannot assign issues from other teams
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
- @patch("products.error_tracking.backend.api.issues.dispatch_issue_assigned_realtime")
- @patch("products.error_tracking.backend.api.issues.send_error_tracking_issue_assigned")
+ @patch("products.error_tracking.backend.presentation.views.issues.dispatch_issue_assigned_realtime")
+ @patch("products.error_tracking.backend.presentation.views.issues.send_error_tracking_issue_assigned")
def test_assign_issue_dispatches_realtime_after_assignment(self, _send_email, mock_realtime):
issue = self.create_issue()
other_user = User.objects.create_and_join(self.organization, "[email protected]", "password")
@@ -1025,7 +1025,7 @@ class TestErrorTracking(APIBaseTest):
assert ErrorTrackingSymbolSet.objects.get(id=symbol_set_one.id).content_hash == "hash_one"
assert ErrorTrackingSymbolSet.objects.get(id=symbol_set_two.id).content_hash == "hash_two"
- @patch("products.error_tracking.backend.api.symbol_sets.posthoganalytics.capture")
+ @patch("products.error_tracking.backend.presentation.views.symbol_sets.posthoganalytics.capture")
def test_bulk_finish_upload_rejects_unknown_symbol_set_ids(self, patched_capture: Mock) -> None:
response = self.client.post(
f"/api/environments/{self.team.id}/error_tracking/symbol_sets/bulk_finish_upload",
@@ -1044,7 +1044,7 @@ class TestErrorTracking(APIBaseTest):
"failure_code": "symbol_set_not_found",
}
- @patch("products.error_tracking.backend.api.symbol_sets.posthoganalytics.capture")
+ @patch("products.error_tracking.backend.presentation.views.symbol_sets.posthoganalytics.capture")
@patch("posthog.storage.object_storage.head_object")
def test_bulk_finish_upload_preserves_pending_symbol_set_when_file_is_not_found(
self, patched_object_storage, patched_capture: Mock
diff --git a/products/error_tracking/backend/api/test/test_grouping_rules.py b/products/error_tracking/backend/tests/api/test_grouping_rules.py
similarity index 100%
rename from products/error_tracking/backend/api/test/test_grouping_rules.py
rename to products/error_tracking/backend/tests/api/test_grouping_rules.py
diff --git a/products/error_tracking/backend/api/test/test_query_api.py b/products/error_tracking/backend/tests/api/test_query_api.py
similarity index 93%
rename from products/error_tracking/backend/api/test/test_query_api.py
rename to products/error_tracking/backend/tests/api/test_query_api.py
index 714861885b7f..3e53adebae52 100644
--- a/products/error_tracking/backend/api/test/test_query_api.py
+++ b/products/error_tracking/backend/tests/api/test_query_api.py
@@ -12,7 +12,7 @@ from dateutil.relativedelta import relativedelta
from posthog.clickhouse.query_tagging import Feature, Product, get_query_tags
-from products.error_tracking.backend.api.query_utils import (
+from products.error_tracking.backend.facade.query_utils import (
build_fingerprint_event_where,
build_issue_filters,
build_search_query,
@@ -230,7 +230,9 @@ class TestErrorTrackingQueryAPI(ClickhouseTestMixin, APIBaseTest):
observed_tags.append((tags.product, tags.feature))
return FakeQueryResponse({"results": [], "hasMore": False, "limit": 25, "offset": 0})
- with patch("products.error_tracking.backend.api.query.ErrorTrackingQueryRunner.calculate", calculate):
+ with patch(
+ "products.error_tracking.backend.presentation.views.query.ErrorTrackingQueryRunner.calculate", calculate
+ ):
response = self.client.post(
f"/api/environments/{self.team.id}/error_tracking/query/issues",
data={"limit": 1},
@@ -247,7 +249,9 @@ class TestErrorTrackingQueryAPI(ClickhouseTestMixin, APIBaseTest):
observed_volume_resolutions.append(runner.query.volumeResolution)
return FakeQueryResponse({"results": [], "hasMore": False, "limit": 25, "offset": 0})
- with patch("products.error_tracking.backend.api.query.ErrorTrackingQueryRunner.calculate", calculate):
+ with patch(
+ "products.error_tracking.backend.presentation.views.query.ErrorTrackingQueryRunner.calculate", calculate
+ ):
response = self.client.post(
f"/api/environments/{self.team.id}/error_tracking/query/issues",
data={"volumeResolution": 0},
@@ -278,8 +282,13 @@ class TestErrorTrackingQueryAPI(ClickhouseTestMixin, APIBaseTest):
return FakeQueryResponse({"columns": [], "results": []})
with (
- patch("products.error_tracking.backend.api.query.ErrorTrackingQueryRunner.calculate", calculate_issue),
- patch("products.error_tracking.backend.api.query.EventsQueryRunner.calculate", calculate_event),
+ patch(
+ "products.error_tracking.backend.presentation.views.query.ErrorTrackingQueryRunner.calculate",
+ calculate_issue,
+ ),
+ patch(
+ "products.error_tracking.backend.presentation.views.query.EventsQueryRunner.calculate", calculate_event
+ ),
):
response = self.client.post(
f"/api/environments/{self.team.id}/error_tracking/query/issue",
@@ -312,8 +321,13 @@ class TestErrorTrackingQueryAPI(ClickhouseTestMixin, APIBaseTest):
return FakeQueryResponse({"columns": [], "results": []})
with (
- patch("products.error_tracking.backend.api.query.ErrorTrackingQueryRunner.calculate", calculate_issue),
- patch("products.error_tracking.backend.api.query.EventsQueryRunner.calculate", calculate_event),
+ patch(
+ "products.error_tracking.backend.presentation.views.query.ErrorTrackingQueryRunner.calculate",
+ calculate_issue,
+ ),
+ patch(
+ "products.error_tracking.backend.presentation.views.query.EventsQueryRunner.calculate", calculate_event
+ ),
):
response = self.client.post(
f"/api/environments/{self.team.id}/error_tracking/query/issue",
@@ -347,8 +361,13 @@ class TestErrorTrackingQueryAPI(ClickhouseTestMixin, APIBaseTest):
return FakeQueryResponse({"columns": [], "results": []})
with (
- patch("products.error_tracking.backend.api.query.ErrorTrackingQueryRunner.calculate", calculate_issue),
- patch("products.error_tracking.backend.api.query.EventsQueryRunner.calculate", calculate_event),
+ patch(
+ "products.error_tracking.backend.presentation.views.query.ErrorTrackingQueryRunner.calculate",
+ calculate_issue,
+ ),
+ patch(
+ "products.error_tracking.backend.presentation.views.query.EventsQueryRunner.calculate", calculate_event
+ ),
):
response = self.client.post(
f"/api/environments/{self.team.id}/error_tracking/query/issue",
@@ -426,7 +445,7 @@ class TestErrorTrackingQueryAPI(ClickhouseTestMixin, APIBaseTest):
self.create_exception_event()
flush_persons_and_events()
- with patch("products.error_tracking.backend.api.query.EventsQueryRunner") as events_query_runner:
+ with patch("products.error_tracking.backend.presentation.views.query.EventsQueryRunner") as events_query_runner:
events_query_runner.side_effect = RuntimeError("boom")
response = self.client.post(
f"/api/environments/{self.team.id}/error_tracking/query/issue",
@@ -483,7 +502,7 @@ class TestErrorTrackingQueryAPI(ClickhouseTestMixin, APIBaseTest):
observed_tags.append((tags.product, tags.feature))
return FakeQueryResponse({"columns": [], "results": [], "hasMore": False, "limit": 1, "offset": 0})
- with patch("products.error_tracking.backend.api.query.EventsQueryRunner.calculate", calculate):
+ with patch("products.error_tracking.backend.presentation.views.query.EventsQueryRunner.calculate", calculate):
response = self.client.post(
f"/api/environments/{self.team.id}/error_tracking/query/issue_events",
data={"issueId": self.issue_id},
diff --git a/products/error_tracking/backend/api/test/test_recommendations.py b/products/error_tracking/backend/tests/api/test_recommendations.py
similarity index 89%
rename from products/error_tracking/backend/api/test/test_recommendations.py
rename to products/error_tracking/backend/tests/api/test_recommendations.py
index 31fe398c26b9..b80c0826ba9a 100644
--- a/products/error_tracking/backend/api/test/test_recommendations.py
+++ b/products/error_tracking/backend/tests/api/test_recommendations.py
@@ -12,6 +12,10 @@ from rest_framework import status
from posthog.models.utils import uuid7
from products.cdp.backend.models.hog_functions.hog_function import HogFunction
+from products.error_tracking.backend.logic.recommendations.alerts import AlertsRecommendation
+from products.error_tracking.backend.logic.recommendations.long_running_issues import LongRunningIssuesRecommendation
+from products.error_tracking.backend.logic.recommendations.rate_limits import RateLimitsRecommendation
+from products.error_tracking.backend.logic.recommendations.source_maps import SourceMapsRecommendation
from products.error_tracking.backend.models import (
ErrorTrackingIssue,
ErrorTrackingIssueFingerprintV2,
@@ -20,10 +24,6 @@ from products.error_tracking.backend.models import (
ErrorTrackingStackFrame,
sync_issues_to_clickhouse,
)
-from products.error_tracking.backend.recommendations.alerts import AlertsRecommendation
-from products.error_tracking.backend.recommendations.long_running_issues import LongRunningIssuesRecommendation
-from products.error_tracking.backend.recommendations.rate_limits import RateLimitsRecommendation
-from products.error_tracking.backend.recommendations.source_maps import SourceMapsRecommendation
from ee.clickhouse.materialized_columns.columns import materialize
@@ -66,11 +66,11 @@ class TestRecommendationsAPI(ClickhouseTestMixin, APIBaseTest):
return self.client.post(f"/api/environments/{self.team.id}/error_tracking/recommendations/{rec_id}/refresh/")
@patch(
- "products.error_tracking.backend.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
return_value={"issues": []},
)
@patch(
- "products.error_tracking.backend.recommendations.alerts.AlertsRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.alerts.AlertsRecommendation.compute",
return_value=MOCK_ALERTS_META,
)
def test_first_list_creates_all_recommendations(self, mock_alerts, mock_long_running):
@@ -84,11 +84,11 @@ class TestRecommendationsAPI(ClickhouseTestMixin, APIBaseTest):
self.assertEqual(types, {"alerts", "long_running_issues", "rate_limits", "source_maps"})
@patch(
- "products.error_tracking.backend.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
return_value={"issues": []},
)
@patch(
- "products.error_tracking.backend.recommendations.alerts.AlertsRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.alerts.AlertsRecommendation.compute",
)
def test_alerts_recomputes_on_every_list(self, mock_alerts, mock_long_running):
mock_alerts.return_value = MOCK_ALERTS_META
@@ -103,10 +103,10 @@ class TestRecommendationsAPI(ClickhouseTestMixin, APIBaseTest):
@freeze_time("2026-01-01T00:00:00Z", as_kwarg="frozen_time")
@patch(
- "products.error_tracking.backend.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
)
@patch(
- "products.error_tracking.backend.recommendations.alerts.AlertsRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.alerts.AlertsRecommendation.compute",
return_value=MOCK_ALERTS_META,
)
def test_long_running_is_cached_until_interval_elapses(self, mock_alerts, mock_long_running, frozen_time):
@@ -124,11 +124,11 @@ class TestRecommendationsAPI(ClickhouseTestMixin, APIBaseTest):
self.assertEqual(mock_long_running.call_count, 2)
@patch(
- "products.error_tracking.backend.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
return_value={"issues": []},
)
@patch(
- "products.error_tracking.backend.recommendations.alerts.AlertsRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.alerts.AlertsRecommendation.compute",
return_value=MOCK_ALERTS_META,
)
def test_dismiss_persists_across_requests(self, mock_alerts, mock_long_running):
@@ -339,11 +339,11 @@ class TestRecommendationsAPI(ClickhouseTestMixin, APIBaseTest):
self.assertFalse(RateLimitsRecommendation().is_completed({"rate_limits": []}))
@patch(
- "products.error_tracking.backend.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
return_value={"issues": []},
)
@patch(
- "products.error_tracking.backend.recommendations.alerts.AlertsRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.alerts.AlertsRecommendation.compute",
return_value=MOCK_ALERTS_META,
)
def test_refresh_with_force_false_does_not_recompute(self, mock_alerts, mock_long_running):
@@ -359,11 +359,11 @@ class TestRecommendationsAPI(ClickhouseTestMixin, APIBaseTest):
mock_long_running.assert_not_called()
@patch(
- "products.error_tracking.backend.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
return_value={"issues": []},
)
@patch(
- "products.error_tracking.backend.recommendations.alerts.AlertsRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.alerts.AlertsRecommendation.compute",
return_value=MOCK_ALERTS_META,
)
def test_refresh_with_force_true_recomputes(self, mock_alerts, mock_long_running):
@@ -377,11 +377,11 @@ class TestRecommendationsAPI(ClickhouseTestMixin, APIBaseTest):
mock_long_running.assert_called_once()
@patch(
- "products.error_tracking.backend.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
return_value={"issues": []},
)
@patch(
- "products.error_tracking.backend.recommendations.alerts.AlertsRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.alerts.AlertsRecommendation.compute",
return_value=MOCK_ALERTS_META,
)
def test_list_marks_recommendations_ready_after_compute(self, mock_alerts, mock_long_running):
@@ -398,11 +398,11 @@ class TestRecommendationsAPI(ClickhouseTestMixin, APIBaseTest):
self.assertEqual(mock_long_running.call_count, 1)
@patch(
- "products.error_tracking.backend.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
return_value={"issues": []},
)
@patch(
- "products.error_tracking.backend.recommendations.alerts.AlertsRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.alerts.AlertsRecommendation.compute",
return_value=MOCK_ALERTS_META,
)
def test_poll_does_not_kick_off_new_computations(self, mock_alerts, mock_long_running):
@@ -512,11 +512,11 @@ class TestRecommendationsAPI(ClickhouseTestMixin, APIBaseTest):
self.assertTrue(SourceMapsRecommendation().is_completed(meta))
@patch(
- "products.error_tracking.backend.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.long_running_issues.LongRunningIssuesRecommendation.compute",
return_value={"issues": []},
)
@patch(
- "products.error_tracking.backend.recommendations.alerts.AlertsRecommendation.compute",
+ "products.error_tracking.backend.logic.recommendations.alerts.AlertsRecommendation.compute",
return_value=MOCK_ALERTS_META,
)
def test_stuck_computing_rows_are_re_kicked(self, mock_alerts, mock_long_running):
diff --git a/products/error_tracking/backend/api/test/test_suppression_rules.py b/products/error_tracking/backend/tests/api/test_suppression_rules.py
similarity index 99%
rename from products/error_tracking/backend/api/test/test_suppression_rules.py
rename to products/error_tracking/backend/tests/api/test_suppression_rules.py
index 7f65f2054a7d..9943dc305932 100644
--- a/products/error_tracking/backend/api/test/test_suppression_rules.py
+++ b/products/error_tracking/backend/tests/api/test_suppression_rules.py
@@ -7,12 +7,12 @@ from rest_framework import status
from posthog.schema import PropertyGroupFilterValue
-from products.error_tracking.backend.api.suppression_rules import (
+from products.error_tracking.backend.models import ErrorTrackingSuppressionRule
+from products.error_tracking.backend.presentation.views.suppression_rules import (
_get_client_safe_filters,
get_client_safe_suppression_rules,
)
-from products.error_tracking.backend.api.utils import generate_byte_code
-from products.error_tracking.backend.models import ErrorTrackingSuppressionRule
+from products.error_tracking.backend.presentation.views.utils import generate_byte_code
from common.hogvm.python.execute import execute_bytecode
diff --git a/products/error_tracking/tsconfig.json b/products/error_tracking/tsconfig.json
new file mode 100644
index 000000000000..fe425d6fcba8
--- /dev/null
+++ b/products/error_tracking/tsconfig.json
@@ -0,0 +1,6 @@
+{
+ "extends": "../../tsconfig.json",
+ "compilerOptions": {
+ "composite": true
+ }
+}
diff --git a/products/posthog_ai/scripts/hogql_example/__init__.py b/products/posthog_ai/scripts/hogql_example/__init__.py
index 0ae2ac5eabbd..4e4d98048c93 100644
--- a/products/posthog_ai/scripts/hogql_example/__init__.py
+++ b/products/posthog_ai/scripts/hogql_example/__init__.py
@@ -89,7 +89,7 @@ def render_hogql_example(query_dict: dict[str, Any]) -> str:
from posthog.hogql_queries.ai.trace_query_runner import TraceQueryRunner
- from products.error_tracking.backend.hogql_queries.error_tracking_query_runner import ErrorTrackingQueryRunner
+ from products.error_tracking.backend.facade.queries import ErrorTrackingQueryRunner
from products.logs.backend.logs_query_runner import LogsQueryRunner
hogql_filters = HogQLFilters()
diff --git a/products/signals/backend/temporal/backfill_error_tracking.py b/products/signals/backend/temporal/backfill_error_tracking.py
index ebdf1d4e67f7..93552323a011 100644
--- a/products/signals/backend/temporal/backfill_error_tracking.py
+++ b/products/signals/backend/temporal/backfill_error_tracking.py
@@ -39,7 +39,7 @@ async def fetch_error_tracking_issues_activity(input: BackfillErrorTrackingInput
from posthog.models import Team
from posthog.sync import database_sync_to_async
- from products.error_tracking.backend.hogql_queries.error_tracking_query_runner import ErrorTrackingQueryRunner
+ from products.error_tracking.backend.facade.queries import ErrorTrackingQueryRunner
team = await Team.objects.aget(id=input.team_id)
diff --git a/pyproject.toml b/pyproject.toml
index 7fa2dd099700..35f34ca43e8d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -526,6 +526,29 @@ ignore_imports = [
"products.user_interviews.backend.presentation.views -> products.user_interviews.backend.models",
"products.user_interviews.backend.presentation.views -> products.user_interviews.backend.invite_email",
"products.user_interviews.backend.presentation.webhooks -> products.user_interviews.backend.models",
+ # TODO: error_tracking presentation wave — these views still reach internals directly.
+ # Thin each view to parse -> facade -> serialize and delete its entry. backend:contract-check
+ # stays off until this list (and the frozen-migration DDL leak) is resolved.
+ "products.error_tracking.backend.presentation.views.assignment_rules -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.grouping_rules -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.issues -> products.cohorts.backend.models.cohort",
+ "products.error_tracking.backend.presentation.views.issues -> products.error_tracking.backend.issue_serializers",
+ "products.error_tracking.backend.presentation.views.issues -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.issues -> products.error_tracking.backend.notifications",
+ "products.error_tracking.backend.presentation.views.query -> products.error_tracking.backend.hogql_queries.error_tracking_query_runner",
+ "products.error_tracking.backend.presentation.views.query -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.recommendations -> products.error_tracking.backend.logic.recommendations",
+ "products.error_tracking.backend.presentation.views.recommendations -> products.error_tracking.backend.logic.recommendations.refresh",
+ "products.error_tracking.backend.presentation.views.recommendations -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.recommendations -> products.error_tracking.backend.tasks",
+ "products.error_tracking.backend.presentation.views.releases -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.settings -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.spike_detection_config -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.spike_events -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.stack_frames -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.suppression_rules -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.symbol_sets -> products.error_tracking.backend.models",
+ "products.error_tracking.backend.presentation.views.utils -> products.error_tracking.backend.hogvm_stl",
]
[tool.ty.rules]
diff --git a/tach.toml b/tach.toml
index c63cb54a0a47..efa76a0aeb7c 100644
--- a/tach.toml
+++ b/tach.toml
@@ -671,7 +671,7 @@ expose = [
"backend\\.routes.*",
]
from = [
- "products\\.(experiments|mcp_analytics|mcp_store|metrics|notifications|tracing|user_interviews|visual_review)",
+ "products\\.(error_tracking|experiments|mcp_analytics|mcp_store|metrics|notifications|tracing|user_interviews|visual_review)",
]
# TODO: Experiments-specific temporary interface
@@ -742,6 +742,24 @@ from = [
"products.mcp_store",
]
+# error_tracking exposes its ClickHouse DDL (sql / embedding / indexed_embedding) to
+# core's ClickHouse schema + frozen migrations, and its models / remote_config to core
+# model-class consumers (product_intent, remote_config, team deletion) and test fixtures.
+# The frozen-migration coupling cannot be rerouted, so this block is permanent rather than
+# shrinking to zero — which is why backend:contract-check stays off for this product.
+
+[[interfaces]]
+expose = [
+ "backend\\.embedding.*",
+ "backend\\.indexed_embedding.*",
+ "backend\\.models.*",
+ "backend\\.remote_config.*",
+ "backend\\.sql.*",
+]
+from = [
+ "products.error_tracking",
+]
+
[[interfaces]]
expose = [
"backend\\.logic.*",
diff --git a/tools/hogli-commands/hogli_commands/product/paths.py b/tools/hogli-commands/hogli_commands/product/paths.py
index 05ffb3db3065..d27ae57c866b 100644
--- a/tools/hogli-commands/hogli_commands/product/paths.py
+++ b/tools/hogli-commands/hogli_commands/product/paths.py
@@ -49,6 +49,14 @@ def find_views_path(backend_dir: Path) -> tuple[Path | None, bool]:
from .ast_helpers import count_viewset_files
+ # `hogli product:isolate:move` relocates multi-viewset products into a
+ # `presentation/views/` package (one module per resource) rather than a single
+ # `presentation/views.py`. Both satisfy the tach `presentation\.views.*` interface,
+ # so treat the package form as a correct location too.
+ pres_views_pkg = backend_dir / "presentation" / "views"
+ if pres_views_pkg.is_dir() and count_viewset_files(pres_views_pkg) > 0:
+ return pres_views_pkg, True
+
api_dir = backend_dir / "api"
if api_dir.is_dir() and count_viewset_files(api_dir) > 0:
return api_dir, False
diff --git a/tools/hogli-commands/hogli_commands/tests/test_isolate.py b/tools/hogli-commands/hogli_commands/tests/test_isolate.py
index cd8e37e103b2..b2f04b366c44 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_isolate.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_isolate.py
@@ -224,6 +224,22 @@ def test_detect_viewset_modules_includes_api_subpackage(tmp_path: Path) -> None:
assert [p.name for p in detect_viewset_modules(backend, include_api=True)] == ["views.py"]
+def test_find_views_path_accepts_presentation_views_package(tmp_path: Path) -> None:
+ from hogli_commands.product.paths import find_views_path
+
+ backend = tmp_path / "backend"
+ views_pkg = backend / "presentation" / "views"
+ views_pkg.mkdir(parents=True)
+ (views_pkg / "__init__.py").write_text("")
+ (views_pkg / "issues.py").write_text(
+ "from rest_framework import viewsets\nclass IssueViewSet(viewsets.ViewSet):\n pass\n"
+ )
+
+ path, correct_location = find_views_path(backend)
+ assert path == views_pkg
+ assert correct_location is True
+
+
def test_module_dotted_keeps_intermediate_package() -> None:
assert _module_dotted("wa", Path("api/heatmaps_api.py")) == "products.wa.backend.api.heatmaps_api"
assert _module_dotted("wa", Path("views.py")) == "products.wa.backend.views"