Skip to content

Commit 8bf0573

Browse files
committed
ref(analytics): Transform analytics events for TET-826
- Transform event classes to use @analytics.eventclass decorator - Transform analytics.record calls to use event class instances - Update imports as needed Closes TET-826
1 parent 986ceec commit 8bf0573

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

src/sentry/preprod/analytics.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
11
from sentry import analytics
22

33

4+
@analytics.eventclass("preprod_artifact.api.assemble")
45
class PreprodArtifactApiAssembleEvent(analytics.Event):
5-
type = "preprod_artifact.api.assemble"
6-
7-
attributes = (
8-
analytics.Attribute("organization_id"),
9-
analytics.Attribute("project_id"),
10-
analytics.Attribute("user_id", required=False),
11-
)
6+
organization_id: str
7+
project_id: str
8+
user_id: str | None = None
129

1310

11+
@analytics.eventclass("preprod_artifact.api.update")
1412
class PreprodArtifactApiUpdateEvent(analytics.Event):
15-
type = "preprod_artifact.api.update"
16-
17-
attributes = (
18-
analytics.Attribute("organization_id"),
19-
analytics.Attribute("project_id"),
20-
)
13+
organization_id: str
14+
project_id: str
2115

2216

17+
@analytics.eventclass("preprod_artifact.api.assemble_generic")
2318
class PreprodArtifactApiAssembleGenericEvent(analytics.Event):
24-
type = "preprod_artifact.api.assemble_generic"
25-
26-
attributes = (
27-
analytics.Attribute("organization_id"),
28-
analytics.Attribute("project_id"),
29-
)
19+
organization_id: str
20+
project_id: str
3021

3122

3223
analytics.register(PreprodArtifactApiAssembleEvent)

src/sentry/preprod/api/endpoints/organization_preprod_artifact_assemble.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from sentry.api.bases.project import ProjectEndpoint, ProjectReleasePermission
1313
from sentry.debug_files.upload import find_missing_chunks
1414
from sentry.models.orgauthtoken import is_org_auth_token_auth, update_org_auth_token_last_used
15+
from sentry.preprod.analytics import PreprodArtifactApiAssembleEvent
1516
from sentry.preprod.tasks import assemble_preprod_artifact
1617
from sentry.tasks.assemble import (
1718
AssembleTask,
@@ -80,10 +81,11 @@ def post(self, request: Request, project) -> Response:
8081
"""
8182

8283
analytics.record(
83-
"preprod_artifact.api.assemble",
84-
organization_id=project.organization_id,
85-
project_id=project.id,
86-
user_id=request.user.id,
84+
PreprodArtifactApiAssembleEvent(
85+
organization_id=project.organization_id,
86+
project_id=project.id,
87+
user_id=request.user.id,
88+
)
8789
)
8890

8991
if not settings.IS_DEV and not features.has(

src/sentry/preprod/api/endpoints/project_preprod_artifact_assemble_generic.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from sentry.api.bases.project import ProjectEndpoint
1616
from sentry.debug_files.upload import find_missing_chunks
1717
from sentry.models.orgauthtoken import is_org_auth_token_auth, update_org_auth_token_last_used
18+
from sentry.preprod.analytics import PreprodArtifactApiAssembleGenericEvent
1819
from sentry.preprod.authentication import LaunchpadRpcSignatureAuthentication
1920
from sentry.preprod.tasks import (
2021
assemble_preprod_artifact_installable_app,
@@ -104,9 +105,10 @@ def post(self, request: Request, project, artifact_id) -> Response:
104105
raise PermissionDenied
105106

106107
analytics.record(
107-
"preprod_artifact.api.assemble_generic",
108-
organization_id=project.organization_id,
109-
project_id=project.id,
108+
PreprodArtifactApiAssembleGenericEvent(
109+
organization_id=project.organization_id,
110+
project_id=project.id,
111+
)
110112
)
111113

112114
with sentry_sdk.start_span(op="preprod_artifact.assemble_generic"):

src/sentry/preprod/api/endpoints/project_preprod_artifact_update.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sentry.api.api_publish_status import ApiPublishStatus
1010
from sentry.api.base import region_silo_endpoint
1111
from sentry.api.bases.project import ProjectEndpoint
12+
from sentry.preprod.analytics import PreprodArtifactApiUpdateEvent
1213
from sentry.preprod.authentication import LaunchpadRpcSignatureAuthentication
1314
from sentry.preprod.models import PreprodArtifact
1415

@@ -109,9 +110,10 @@ def put(self, request: Request, project, artifact_id) -> Response:
109110
raise PermissionDenied
110111

111112
analytics.record(
112-
"preprod_artifact.api.update",
113-
organization_id=project.organization_id,
114-
project_id=project.id,
113+
PreprodArtifactApiUpdateEvent(
114+
organization_id=project.organization_id,
115+
project_id=project.id,
116+
)
115117
)
116118

117119
# Validate request data

0 commit comments

Comments
 (0)