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.

feat(error-tracking): capture issue detail reads server-side (#119422)

James Gillb43289448e3d
diff --git a/products/error_tracking/backend/presentation/views/query.py b/products/error_tracking/backend/presentation/views/query.py
index f2e6531561a7..5afecacd7b0f 100644
--- a/products/error_tracking/backend/presentation/views/query.py
+++ b/products/error_tracking/backend/presentation/views/query.py
@@ -25,6 +25,7 @@ from posthog.api.mixins import ValidatedRequest, validated_request
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.utils import action
from posthog.clickhouse.query_tagging import Feature, Product, tags_context
+from posthog.event_usage import report_user_action
from posthog.hogql_queries.events_query_runner import EventsQueryRunner
from posthog.hogql_queries.query_runner import ExecutionMode
from posthog.models import User
@@ -77,6 +78,21 @@ logger = structlog.get_logger(__name__)
class ErrorTrackingQueryViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
scope_object = "error_tracking"
+ def _report_issue_read(self, request: ValidatedRequest, issue_id: str, endpoint: str, **properties: object) -> None:
+ # The frontend issue events see only the web app, so this is the one record of which issues
+ # MCP, CLI and API callers read. A capture failure must not fail the read.
+ try:
+ report_user_action(
+ cast(User, request.user),
+ "error_tracking_issue_read",
+ {"issue_id": issue_id, "endpoint": endpoint, **properties},
+ team=self.team,
+ organization=self.team.organization,
+ request=request,
+ )
+ except Exception:
+ logger.warning("error_tracking_issue_read_capture_failed", issue_id=issue_id, exc_info=True)
+
@validated_request(
request_serializer=ErrorTrackingIssuesListQueryRequestSerializer,
responses={200: OpenApiResponse(response=ErrorTrackingIssuesListResponseSerializer)},
@@ -182,6 +198,9 @@ class ErrorTrackingQueryViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
payload["impact"] = {}
if include_sparkline:
payload["sparkline"] = []
+ self._report_issue_read(
+ request, issue_id, "issue", include_breakdown=include_breakdown, include_sparkline=include_sparkline
+ )
return Response(payload)
issue = cast(dict[str, object], raw_results[0])
event_properties: dict[str, object] = {}
@@ -234,6 +253,9 @@ class ErrorTrackingQueryViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
)
if include_breakdown:
payload["breakdown"] = self._issue_breakdown(request, issue_id, date_range, filter_test_accounts)
+ self._report_issue_read(
+ request, issue_id, "issue", include_breakdown=include_breakdown, include_sparkline=include_sparkline
+ )
return Response(payload)
def _issue_breakdown(
@@ -334,4 +356,5 @@ class ErrorTrackingQueryViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
payload: dict[str, object] = {"results": results, "hasMore": has_more, "limit": limit, "offset": offset}
if next_offset is not None:
payload["nextOffset"] = next_offset
+ self._report_issue_read(request, issue_id, "issue_events")
return Response(payload)
diff --git a/products/error_tracking/backend/tests/api/test_query_api.py b/products/error_tracking/backend/tests/api/test_query_api.py
index 1d208c294dac..138ece1c0125 100644
--- a/products/error_tracking/backend/tests/api/test_query_api.py
+++ b/products/error_tracking/backend/tests/api/test_query_api.py
@@ -695,6 +695,70 @@ class TestErrorTrackingQueryAPI(ClickhouseTestMixin, APIBaseTest):
assert response.status_code == 404
+ @parameterized.expand(
+ [
+ ("issue", True, {"includeSparkline": True}, {"include_breakdown": False, "include_sparkline": True}),
+ ("issue", False, {"includeSparkline": True}, {"include_breakdown": False, "include_sparkline": True}),
+ ("issue_events", True, {}, {}),
+ ]
+ )
+ @time_machine.travel("2026-04-24T12:00:00Z", tick=False)
+ def test_issue_reads_capture_an_event_for_existing_issues_only(
+ self,
+ endpoint: str,
+ has_exceptions: bool,
+ extra_body: dict[str, object],
+ expected_properties: dict[str, object],
+ ) -> None:
+ self.create_issue()
+ if has_exceptions:
+ self.create_exception_event()
+ flush_persons_and_events()
+ token = self.create_personal_api_key_with_scopes(["error_tracking:read"])
+
+ with patch("posthog.event_usage.posthoganalytics.capture") as mock_capture:
+ found = self.client.post(
+ f"/api/environments/{self.team.id}/error_tracking/query/{endpoint}",
+ data={"issueId": self.issue_id, **extra_body},
+ format="json",
+ HTTP_AUTHORIZATION=f"Bearer {token}",
+ )
+ missing = self.client.post(
+ f"/api/environments/{self.team.id}/error_tracking/query/{endpoint}",
+ data={"issueId": "00000000-0000-0000-0000-000000000000", **extra_body},
+ format="json",
+ HTTP_AUTHORIZATION=f"Bearer {token}",
+ )
+
+ assert found.status_code == 200
+ assert missing.status_code == 404
+ read_events = [
+ call.kwargs["properties"]
+ for call in mock_capture.call_args_list
+ if call.kwargs.get("event") == "error_tracking_issue_read"
+ ]
+ assert read_events == [
+ {
+ **read_events[0],
+ "issue_id": self.issue_id,
+ "endpoint": endpoint,
+ "access_method": "personal_api_key",
+ **expected_properties,
+ }
+ ]
+
+ def test_issue_read_succeeds_when_capture_fails(self) -> None:
+ self.create_issue()
+
+ with patch("posthog.event_usage.posthoganalytics.capture", side_effect=RuntimeError("capture down")):
+ response = self.client.post(
+ f"/api/environments/{self.team.id}/error_tracking/query/issue",
+ data={"issueId": self.issue_id},
+ format="json",
+ )
+
+ assert response.status_code == 200
+
def test_issue_events_tags_clickhouse_queries(self) -> None:
self.create_issue()
observed_tags: list[tuple[object, object]] = []