Skip to content

ref(analytics): Transform analytics events for TET-826 #95206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions src/sentry/preprod/analytics.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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])

Expand All @@ -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])

Expand Down
Loading