Skip to content

Commit fad2ec5

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

File tree

7 files changed

+44
-45
lines changed

7 files changed

+44
-45
lines changed
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
from sentry import analytics
22

33

4+
@analytics.eventclass("relocation.created")
45
class RelocationCreatedEvent(analytics.Event):
5-
type = "relocation.created"
6-
7-
attributes = (
8-
analytics.Attribute("creator_id"),
9-
analytics.Attribute("owner_id"),
10-
analytics.Attribute("uuid"),
11-
)
6+
creator_id: str
7+
owner_id: str
8+
uuid: str
129

1310

1411
analytics.register(RelocationCreatedEvent)
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
from sentry import analytics
22

33

4+
@analytics.eventclass("relocation.forked")
45
class RelocationForkedEvent(analytics.Event):
5-
type = "relocation.forked"
6-
7-
attributes = (
8-
analytics.Attribute("creator_id"),
9-
analytics.Attribute("owner_id"),
10-
analytics.Attribute("uuid"),
11-
analytics.Attribute("from_org_slug"),
12-
analytics.Attribute("requesting_region_name"),
13-
analytics.Attribute("replying_region_name"),
14-
)
6+
creator_id: str
7+
owner_id: str
8+
uuid: str
9+
from_org_slug: str
10+
requesting_region_name: str
11+
replying_region_name: str
1512

1613

1714
analytics.register(RelocationForkedEvent)

src/sentry/analytics/events/user_signup.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
from sentry import analytics
22

33

4+
@analytics.eventclass("user.signup")
45
class UserSignUpEvent(analytics.Event):
5-
type = "user.signup"
6-
7-
attributes = (
8-
analytics.Attribute("user_id"),
9-
analytics.Attribute("source"),
10-
analytics.Attribute("provider", required=False),
11-
analytics.Attribute("referrer", required=False),
12-
)
6+
user_id: str
7+
source: str
8+
provider: str | None = None
9+
referrer: str | None = None
1310

1411

1512
class RelocationUserSignUpEvent(UserSignUpEvent):

src/sentry/api/endpoints/organization_fork.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from sentry_sdk import capture_exception
99

1010
from sentry import analytics
11+
from sentry.analytics.events.relocation_forked import RelocationForkedEvent
1112
from sentry.api.api_owners import ApiOwner
1213
from sentry.api.api_publish_status import ApiPublishStatus
1314
from sentry.api.base import Endpoint, region_silo_endpoint
@@ -168,13 +169,14 @@ def post(self, request: Request, organization_id_or_slug) -> Response:
168169

169170
try:
170171
analytics.record(
171-
"relocation.forked",
172-
creator_id=request.user.id,
173-
owner_id=owner.id,
174-
uuid=str(new_relocation.uuid),
175-
from_org_slug=org_mapping.slug,
176-
requesting_region_name=requesting_region_name,
177-
replying_region_name=replying_region_name,
172+
RelocationForkedEvent(
173+
creator_id=request.user.id,
174+
owner_id=owner.id,
175+
uuid=str(new_relocation.uuid),
176+
from_org_slug=org_mapping.slug,
177+
requesting_region_name=requesting_region_name,
178+
replying_region_name=replying_region_name,
179+
)
178180
)
179181
except Exception as e:
180182
capture_exception(e)

src/sentry/receivers/experiments.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from sentry import analytics
2+
from sentry.analytics.events.user_signup import UserSignUpEvent
23
from sentry.signals import join_request_created, join_request_link_viewed, user_signup
34

45

@@ -20,9 +21,10 @@ def record_join_request_link_viewed(organization, **kwargs):
2021
@user_signup.connect(weak=False)
2122
def record_user_signup(user, source, **kwargs):
2223
analytics.record(
23-
"user.signup",
24-
user_id=user.id,
25-
source=source,
26-
provider=kwargs.get("provider"),
27-
referrer=kwargs.get("referrer"),
24+
UserSignUpEvent(
25+
user_id=user.id,
26+
source=source,
27+
provider=kwargs.get("provider"),
28+
referrer=kwargs.get("referrer"),
29+
)
2830
)

src/sentry/relocation/api/endpoints/index.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from sentry_sdk import capture_exception
1414

1515
from sentry import analytics, options
16+
from sentry.analytics.events.relocation_created import RelocationCreatedEvent
1617
from sentry.api.api_owners import ApiOwner
1718
from sentry.api.api_publish_status import ApiPublishStatus
1819
from sentry.api.base import Endpoint, region_silo_endpoint
@@ -298,10 +299,11 @@ def post(self, request: Request) -> Response:
298299
uploading_start.apply_async(args=[str(relocation.uuid), None, None])
299300
try:
300301
analytics.record(
301-
"relocation.created",
302-
creator_id=request.user.id,
303-
owner_id=owner.id,
304-
uuid=str(relocation.uuid),
302+
RelocationCreatedEvent(
303+
creator_id=request.user.id,
304+
owner_id=owner.id,
305+
uuid=str(relocation.uuid),
306+
)
305307
)
306308
except Exception as e:
307309
capture_exception(e)

src/sentry/relocation/api/endpoints/retry.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from sentry_sdk import capture_exception
99

1010
from sentry import analytics
11+
from sentry.analytics.events.relocation_created import RelocationCreatedEvent
1112
from sentry.api.api_owners import ApiOwner
1213
from sentry.api.api_publish_status import ApiPublishStatus
1314
from sentry.api.base import Endpoint, region_silo_endpoint
@@ -134,10 +135,11 @@ def post(self, request: Request, relocation_uuid: str) -> Response:
134135
uploading_start.delay(new_relocation.uuid, None, None)
135136
try:
136137
analytics.record(
137-
"relocation.created",
138-
creator_id=request.user.id,
139-
owner_id=owner.id,
140-
uuid=str(new_relocation.uuid),
138+
RelocationCreatedEvent(
139+
creator_id=request.user.id,
140+
owner_id=owner.id,
141+
uuid=str(new_relocation.uuid),
142+
)
141143
)
142144
except Exception as e:
143145
capture_exception(e)

0 commit comments

Comments
 (0)