: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
feat(health): capture health issue snooze and dismiss outcomes (#95414)
posthog[bot]fbc5ffad3927
diff --git a/posthog/api/health_issue.py b/posthog/api/health_issue.pyindex 01cf84217aea..85442c0ce1ef 100644--- a/posthog/api/health_issue.py+++ b/posthog/api/health_issue.py@@ -25,8 +25,10 @@ from rest_framework.status import HTTP_202_ACCEPTED, HTTP_400_BAD_REQUESTfrom rest_framework.viewsets import GenericViewSetfrom posthog.api.routing import TeamAndOrgViewSetMixin+from posthog.event_usage import report_user_actionfrom posthog.exceptions_capture import capture_exceptionfrom posthog.models.health_issue import HealthIssue+from posthog.models.team import Teamfrom posthog.permissions import is_service_authfrom posthog.rate_limit import HealthIssueRefreshThrottlefrom posthog.utils import relative_date_parse@@ -315,6 +317,50 @@ def _issue_counts(queryset: QuerySet) -> dict[str, Any]:return {"total": sum(by_severity.values()), "by_severity": by_severity, "by_kind": by_kind}+def _report_triage_actions(+ request: Request,+ issue: HealthIssue,+ team: Team,+ *,+ was_dismissed: bool,+ was_snoozed: bool,+) -> None:+ """Capture each triage decision the caller made on an issue, after the write succeeded.++ Several Health scenes and any API or MCP caller reach the same PATCH, so this is the one+ place every snooze and dismiss passes through. `report_user_action` adds the caller's+ access method, which keeps UI triage separable from automated triage.+ """+ properties = {"issue_kind": issue.kind, "issue_severity": issue.severity}++ if "dismissed" in request.data and issue.dismissed != was_dismissed:+ report_user_action(+ request.user,+ "health issue dismissed" if issue.dismissed else "health issue undismissed",+ properties,+ team=team,+ request=request,+ )++ if "snoozed_until" in request.data:+ if issue.snoozed_until is not None:+ report_user_action(+ request.user,+ "health issue snoozed",+ {+ **properties,+ # The requested duration ("7d", "30d", ...) says more about intent than the+ # absolute time it resolved to.+ "snooze_duration": request.data["snoozed_until"],+ "snoozed_until": issue.snoozed_until.isoformat(),+ },+ team=team,+ request=request,+ )+ elif was_snoozed:+ report_user_action(request.user, "health issue unsnoozed", properties, team=team, request=request)++@extend_schema(extensions={"x-product": "health_issues"})@extend_schema_view(list=extend_schema(@@ -383,9 +429,12 @@ class HealthIssueViewSet(TeamAndOrgViewSetMixin, ListModelMixin, RetrieveModelMiraise serializers.ValidationError(dict.fromkeys(unknown_fields, "This field is read-only."))issue = self.get_object()+ was_dismissed = issue.dismissed+ was_snoozed = issue.snoozed_until is not Noneserializer = self.get_serializer(issue, data=request.data, partial=True)serializer.is_valid(raise_exception=True)serializer.save()+ _report_triage_actions(request, issue, self.team, was_dismissed=was_dismissed, was_snoozed=was_snoozed)return Response(serializer.data)def safely_get_queryset(self, queryset: QuerySet) -> QuerySet:diff --git a/posthog/api/test/test_health_issue.py b/posthog/api/test/test_health_issue.pyindex 9b0138f2e60a..f88ecb4bc82f 100644--- a/posthog/api/test/test_health_issue.py+++ b/posthog/api/test/test_health_issue.py@@ -312,6 +312,43 @@ class TestHealthIssueAPI(APIBaseTest):issue.refresh_from_db()self.assertIsNone(issue.snoozed_until)+ @parameterized.expand(+ [+ ("dismiss", {}, {"dismissed": True}, "health issue dismissed", {}),+ ("undismiss", {"dismissed": True}, {"dismissed": False}, "health issue undismissed", {}),+ ("snooze", {}, {"snoozed_until": "7d"}, "health issue snoozed", {"snooze_duration": "7d"}),+ (+ "unsnooze",+ {"snoozed_until": datetime.now(UTC) + timedelta(days=7)},+ {"snoozed_until": None},+ "health issue unsnoozed",+ {},+ ),+ ("dismiss_unchanged", {}, {"dismissed": False}, None, {}),+ ("unsnooze_unsnoozed", {}, {"snoozed_until": None}, None, {}),+ ]+ )+ @patch("posthog.api.health_issue.report_user_action")+ def test_patch_reports_triage_action(+ self, _name, initial, payload, expected_event, expected_properties, mock_report+ ):+ issue = self._create_issue(**initial)++ response = self.client.patch(self._url(f"/{issue.id}/"), payload, content_type="application/json")+ self.assertEqual(response.status_code, status.HTTP_200_OK)++ if expected_event is None:+ mock_report.assert_not_called()+ return++ mock_report.assert_called_once()+ _user, event, properties = mock_report.call_args.args+ self.assertEqual(event, expected_event)+ self.assertEqual(properties["issue_kind"], "sdk_outdated")+ self.assertEqual(properties["issue_severity"], HealthIssue.Severity.WARNING)+ for key, value in expected_properties.items():+ self.assertEqual(properties[key], value)+def test_patch_invalid_snooze_returns_400(self):issue = self._create_issue()