diff --git a/src/sentry/preprod/analytics.py b/src/sentry/preprod/analytics.py index 36cc0c44748b5e..12311ec185c059 100644 --- a/src/sentry/preprod/analytics.py +++ b/src/sentry/preprod/analytics.py @@ -1,32 +1,23 @@ from sentry import analytics +@analytics.eventclass("preprod_artifact.api.assemble") class PreprodArtifactApiAssembleEvent(analytics.Event): - type = "preprod_artifact.api.assemble" - - attributes = ( - analytics.Attribute("organization_id"), - analytics.Attribute("project_id"), - analytics.Attribute("user_id", required=False), - ) + organization_id: str + project_id: str + user_id: int | None = None +@analytics.eventclass("preprod_artifact.api.update") class PreprodArtifactApiUpdateEvent(analytics.Event): - type = "preprod_artifact.api.update" - - attributes = ( - analytics.Attribute("organization_id"), - analytics.Attribute("project_id"), - ) + organization_id: str + project_id: str +@analytics.eventclass("preprod_artifact.api.assemble_generic") class PreprodArtifactApiAssembleGenericEvent(analytics.Event): - type = "preprod_artifact.api.assemble_generic" - - attributes = ( - analytics.Attribute("organization_id"), - analytics.Attribute("project_id"), - ) + organization_id: str + project_id: str analytics.register(PreprodArtifactApiAssembleEvent) diff --git a/src/sentry/preprod/api/endpoints/organization_preprod_artifact_assemble.py b/src/sentry/preprod/api/endpoints/organization_preprod_artifact_assemble.py index f877158342e4a2..4d067406ce710e 100644 --- a/src/sentry/preprod/api/endpoints/organization_preprod_artifact_assemble.py +++ b/src/sentry/preprod/api/endpoints/organization_preprod_artifact_assemble.py @@ -12,6 +12,7 @@ from sentry.api.bases.project import ProjectEndpoint, ProjectReleasePermission from sentry.debug_files.upload import find_missing_chunks from sentry.models.orgauthtoken import is_org_auth_token_auth, update_org_auth_token_last_used +from sentry.preprod.analytics import PreprodArtifactApiAssembleEvent from sentry.preprod.tasks import assemble_preprod_artifact from sentry.tasks.assemble import ( AssembleTask, @@ -80,10 +81,11 @@ def post(self, request: Request, project) -> Response: """ analytics.record( - "preprod_artifact.api.assemble", - organization_id=project.organization_id, - project_id=project.id, - user_id=request.user.id, + PreprodArtifactApiAssembleEvent( + organization_id=project.organization_id, + project_id=project.id, + user_id=request.user.id, + ) ) if not settings.IS_DEV and not features.has( diff --git a/src/sentry/preprod/api/endpoints/project_preprod_artifact_assemble_generic.py b/src/sentry/preprod/api/endpoints/project_preprod_artifact_assemble_generic.py index e2aa7e1db78a22..1505f5d64d6987 100644 --- a/src/sentry/preprod/api/endpoints/project_preprod_artifact_assemble_generic.py +++ b/src/sentry/preprod/api/endpoints/project_preprod_artifact_assemble_generic.py @@ -15,6 +15,7 @@ from sentry.api.bases.project import ProjectEndpoint from sentry.debug_files.upload import find_missing_chunks from sentry.models.orgauthtoken import is_org_auth_token_auth, update_org_auth_token_last_used +from sentry.preprod.analytics import PreprodArtifactApiAssembleGenericEvent from sentry.preprod.authentication import LaunchpadRpcSignatureAuthentication from sentry.preprod.tasks import ( assemble_preprod_artifact_installable_app, @@ -104,9 +105,10 @@ def post(self, request: Request, project, artifact_id) -> Response: raise PermissionDenied analytics.record( - "preprod_artifact.api.assemble_generic", - organization_id=project.organization_id, - project_id=project.id, + PreprodArtifactApiAssembleGenericEvent( + organization_id=project.organization_id, + project_id=project.id, + ) ) with sentry_sdk.start_span(op="preprod_artifact.assemble_generic"): diff --git a/src/sentry/preprod/api/endpoints/project_preprod_artifact_update.py b/src/sentry/preprod/api/endpoints/project_preprod_artifact_update.py index 90a5ed64e4e086..84ed04703dc969 100644 --- a/src/sentry/preprod/api/endpoints/project_preprod_artifact_update.py +++ b/src/sentry/preprod/api/endpoints/project_preprod_artifact_update.py @@ -9,6 +9,7 @@ from sentry.api.api_publish_status import ApiPublishStatus from sentry.api.base import region_silo_endpoint from sentry.api.bases.project import ProjectEndpoint +from sentry.preprod.analytics import PreprodArtifactApiUpdateEvent from sentry.preprod.authentication import LaunchpadRpcSignatureAuthentication from sentry.preprod.models import PreprodArtifact @@ -109,9 +110,10 @@ def put(self, request: Request, project, artifact_id) -> Response: raise PermissionDenied analytics.record( - "preprod_artifact.api.update", - organization_id=project.organization_id, - project_id=project.id, + PreprodArtifactApiUpdateEvent( + organization_id=project.organization_id, + project_id=project.id, + ) ) # Validate request data diff --git a/tests/sentry/preprod/api/endpoints/test_project_preprod_artifact_assemble_generic.py b/tests/sentry/preprod/api/endpoints/test_project_preprod_artifact_assemble_generic.py index ebb642ee34ae8b..92743b7997f9c9 100644 --- a/tests/sentry/preprod/api/endpoints/test_project_preprod_artifact_assemble_generic.py +++ b/tests/sentry/preprod/api/endpoints/test_project_preprod_artifact_assemble_generic.py @@ -4,10 +4,12 @@ from django.test import override_settings from sentry.models.files.fileblob import FileBlob +from sentry.preprod import PreprodArtifactApiAssembleGenericEvent from sentry.preprod.models import PreprodArtifact from sentry.tasks.assemble import AssembleTask, ChunkFileState, set_assemble_status from sentry.testutils.auth import generate_service_request_signature from sentry.testutils.cases import TestCase +from sentry.testutils.helpers.analytics import assert_analytics_events_recorded @override_settings(LAUNCHPAD_RPC_SHARED_SECRET=["test-secret-key"]) @@ -77,10 +79,14 @@ def test_assemble_size_analysis_success(self, mock_analytics): assert resp_data["state"] == ChunkFileState.CREATED assert resp_data["missingChunks"] == [] - mock_analytics.assert_called_once_with( - "preprod_artifact.api.assemble_generic", - organization_id=self.organization.id, - project_id=self.project.id, + assert_analytics_events_recorded( + mock_analytics, + [ + PreprodArtifactApiAssembleGenericEvent( + organization_id=self.organization.id, + project_id=self.project.id, + ) + ], ) self._assert_task_called_with(mock_task, checksum, [b.checksum for b in blobs]) @@ -104,10 +110,14 @@ def test_assemble_installable_app_success(self, mock_analytics): assert resp_data["state"] == ChunkFileState.CREATED assert resp_data["missingChunks"] == [] - mock_analytics.assert_called_once_with( - "preprod_artifact.api.assemble_generic", - organization_id=self.organization.id, - project_id=self.project.id, + assert_analytics_events_recorded( + mock_analytics, + [ + PreprodArtifactApiAssembleGenericEvent( + organization_id=self.organization.id, + project_id=self.project.id, + ) + ], ) self._assert_task_called_with(mock_task, checksum, [b.checksum for b in blobs])