: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(integrations): instrument member integration access-request action (#65243)
posthog[bot]45fbd9ca522e
diff --git a/posthog/api/integration.py b/posthog/api/integration.pyindex f072c7fd6dba..8a635566352c 100644--- a/posthog/api/integration.py+++ b/posthog/api/integration.py@@ -29,6 +29,7 @@ from posthog.api.shared import UserBasicSerializerfrom posthog.api.utils import actionfrom posthog.auth import SessionAuthenticationfrom posthog.domain_connect import discover_domain_connect, extract_root_domain_and_host, get_available_providers+from posthog.event_usage import report_user_actionfrom posthog.exceptions_capture import capture_exceptionfrom posthog.helpers.fuzzy_search import fuzzy_filterfrom posthog.models import OrganizationMembership, User@@ -1302,6 +1303,17 @@ class IntegrationViewSet(kind=serializer.validated_data["kind"],reason=serializer.validated_data["reason"],)+ # Keep the free-text reason out of properties (PII + cardinality); a length signal is enough.+ report_user_action(+ cast(User, request.user),+ "integration access requested",+ {+ "integration_kind": serializer.validated_data["kind"],+ "requester_level": requesting_level,+ "reason_length": len(serializer.validated_data["reason"]),+ },+ team=self.team,+ )return Response({"success": True})@extend_schema(request=None, responses={200: GitHubReposRefreshResponseSerializer})diff --git a/posthog/api/test/test_integration.py b/posthog/api/test/test_integration.pyindex 6992d0181449..77a44846b722 100644--- a/posthog/api/test/test_integration.py+++ b/posthog/api/test/test_integration.py@@ -3675,8 +3675,9 @@ class TestIntegrationRequestAccessAPI(APIBaseTest):def _url(self) -> str:return f"/api/projects/{self.team.id}/integrations/request_access/"+ @patch("posthog.api.integration.report_user_action")@patch("posthog.api.integration.send_integration_access_request")- def test_member_can_request_access(self, mock_task):+ def test_member_can_request_access(self, mock_task, mock_report):response = self.client.post(self._url(), {"kind": "slack", "reason": "We need Slack alerts"}, format="json")assert response.status_code == status.HTTP_200_OK, response.content@@ -3687,6 +3688,16 @@ class TestIntegrationRequestAccessAPI(APIBaseTest):kind="slack",reason="We need Slack alerts",)+ mock_report.assert_called_once_with(+ self.user,+ "integration access requested",+ {+ "integration_kind": "slack",+ "requester_level": OrganizationMembership.Level.MEMBER,+ "reason_length": len("We need Slack alerts"),+ },+ team=self.team,+ )@parameterized.expand([@@ -3694,8 +3705,9 @@ class TestIntegrationRequestAccessAPI(APIBaseTest):("owner", OrganizationMembership.Level.OWNER),])+ @patch("posthog.api.integration.report_user_action")@patch("posthog.api.integration.send_integration_access_request")- def test_admins_cannot_request_access(self, _name, level, mock_task):+ def test_admins_cannot_request_access(self, _name, level, mock_task, mock_report):self.organization_membership.level = levelself.organization_membership.save()@@ -3705,6 +3717,7 @@ class TestIntegrationRequestAccessAPI(APIBaseTest):assert response.status_code == status.HTTP_403_FORBIDDEN, response.contentmock_task.delay.assert_not_called()+ mock_report.assert_not_called()@parameterized.expand([@@ -3714,9 +3727,11 @@ class TestIntegrationRequestAccessAPI(APIBaseTest):("invalid_kind", {"kind": "not-a-real-kind", "reason": "We need it"}),])+ @patch("posthog.api.integration.report_user_action")@patch("posthog.api.integration.send_integration_access_request")- def test_invalid_payload_is_rejected(self, _name, payload, mock_task):+ def test_invalid_payload_is_rejected(self, _name, payload, mock_task, mock_report):response = self.client.post(self._url(), payload, format="json")assert response.status_code == status.HTTP_400_BAD_REQUEST, response.contentmock_task.delay.assert_not_called()+ mock_report.assert_not_called()