Skip to content

Commit 123cadb

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

File tree

8 files changed

+63
-66
lines changed

8 files changed

+63
-66
lines changed

src/sentry/analytics/events/first_event_sent.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22

33

44
# first error for an organization
5+
@analytics.eventclass("first_event.sent")
56
class FirstEventSentEvent(analytics.Event):
6-
type = "first_event.sent"
7-
8-
attributes = (
9-
analytics.Attribute("user_id"),
10-
analytics.Attribute("organization_id"),
11-
analytics.Attribute("project_id"),
12-
analytics.Attribute("platform", required=False),
13-
analytics.Attribute("url", required=False),
14-
analytics.Attribute("has_minified_stack_trace", required=False),
15-
analytics.Attribute("project_platform", required=False),
16-
)
7+
user_id: str
8+
organization_id: str
9+
project_id: str
10+
platform: str | None = None
11+
url: str | None = None
12+
has_minified_stack_trace: str | None = None
13+
project_platform: str | None = None
1714

1815

1916
# first error for a project
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("issue_alert.fired")
45
class IssueAlertFiredEvent(analytics.Event):
5-
type = "issue_alert.fired"
6-
7-
attributes = (
8-
analytics.Attribute("issue_id"),
9-
analytics.Attribute("project_id"),
10-
analytics.Attribute("organization_id"),
11-
analytics.Attribute("rule_id"),
12-
)
6+
issue_id: str
7+
project_id: str
8+
organization_id: str
9+
rule_id: str
1310

1411

1512
analytics.register(IssueAlertFiredEvent)
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
from sentry import analytics
22

33

4+
@analytics.eventclass("issue.auto_resolved")
45
class IssueAutoResolvedEvent(analytics.Event):
5-
type = "issue.auto_resolved"
6-
7-
attributes = (
8-
analytics.Attribute("project_id", required=False),
9-
analytics.Attribute("organization_id"),
10-
analytics.Attribute("group_id"),
11-
analytics.Attribute("issue_category", required=False),
12-
analytics.Attribute("issue_type", required=False),
13-
)
6+
project_id: str | None = None
7+
organization_id: str
8+
group_id: str
9+
issue_category: str | None = None
10+
issue_type: str | None = None
1411

1512

1613
analytics.register(IssueAutoResolvedEvent)
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
from sentry import analytics
22

33

4+
@analytics.eventclass("manual.issue_assignment")
45
class ManualIssueAssignment(analytics.Event):
5-
type = "manual.issue_assignment"
6-
7-
attributes = (
8-
analytics.Attribute("organization_id"),
9-
analytics.Attribute("project_id"),
10-
analytics.Attribute("group_id"),
11-
analytics.Attribute("assigned_by", required=False),
12-
analytics.Attribute("had_to_deassign", required=False),
13-
)
6+
organization_id: str
7+
project_id: str
8+
group_id: str
9+
assigned_by: str | None = None
10+
had_to_deassign: str | None = None
1411

1512

1613
analytics.register(ManualIssueAssignment)

src/sentry/api/helpers/group_index/update.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from rest_framework.response import Response
1919

2020
from sentry import analytics, features, options
21+
from sentry.analytics.events.manual_issue_assignment import ManualIssueAssignment
2122
from sentry.api.serializers import serialize
2223
from sentry.api.serializers.models.actor import ActorSerializer, ActorSerializerResponse
2324
from sentry.db.models.query import create_or_update
@@ -1032,23 +1033,25 @@ def handle_assigned_to(
10321033
group, resolved_actor, acting_user, extra=extra
10331034
)
10341035
analytics.record(
1035-
"manual.issue_assignment",
1036-
organization_id=project_lookup[group.project_id].organization_id,
1037-
project_id=group.project_id,
1038-
group_id=group.id,
1039-
assigned_by=assigned_by,
1040-
had_to_deassign=assignment["updated_assignment"],
1036+
ManualIssueAssignment(
1037+
organization_id=project_lookup[group.project_id].organization_id,
1038+
project_id=group.project_id,
1039+
group_id=group.id,
1040+
assigned_by=assigned_by,
1041+
had_to_deassign=assignment["updated_assignment"],
1042+
)
10411043
)
10421044
return serialize(resolved_actor, acting_user, ActorSerializer())
10431045
else:
10441046
for group in group_list:
10451047
GroupAssignee.objects.deassign(group, acting_user)
10461048
analytics.record(
1047-
"manual.issue_assignment",
1048-
organization_id=project_lookup[group.project_id].organization_id,
1049-
project_id=group.project_id,
1050-
group_id=group.id,
1051-
assigned_by=assigned_by,
1052-
had_to_deassign=True,
1049+
ManualIssueAssignment(
1050+
organization_id=project_lookup[group.project_id].organization_id,
1051+
project_id=group.project_id,
1052+
group_id=group.id,
1053+
assigned_by=assigned_by,
1054+
had_to_deassign=True,
1055+
)
10531056
)
10541057
return None

src/sentry/receivers/onboarding.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.db.models import F
88

99
from sentry import analytics
10+
from sentry.analytics.events.first_event_sent import FirstEventSentEvent
1011
from sentry.integrations.base import IntegrationDomain, get_integration_types
1112
from sentry.integrations.services.integration import RpcIntegration, integration_service
1213
from sentry.models.organization import Organization
@@ -154,12 +155,13 @@ def record_first_event(project, event, **kwargs):
154155

155156
if completed:
156157
analytics.record(
157-
"first_event.sent",
158-
user_id=owner_id,
159-
organization_id=project.organization_id,
160-
project_id=project.id,
161-
platform=event.platform,
162-
project_platform=project.platform,
158+
FirstEventSentEvent(
159+
user_id=owner_id,
160+
organization_id=project.organization_id,
161+
project_id=project.id,
162+
platform=event.platform,
163+
project_platform=project.platform,
164+
)
163165
)
164166

165167

src/sentry/rules/processing/processor.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from django.utils import timezone
1313

1414
from sentry import analytics, buffer, features
15+
from sentry.analytics.events.issue_alert_fired import IssueAlertFiredEvent
1516
from sentry.eventstore.models import GroupEvent
1617
from sentry.models.environment import Environment
1718
from sentry.models.group import Group
@@ -390,11 +391,12 @@ def apply_rule(self, rule: Rule, status: GroupRuleStatus) -> None:
390391

391392
if randrange(10) == 0:
392393
analytics.record(
393-
"issue_alert.fired",
394-
issue_id=self.group.id,
395-
project_id=rule.project.id,
396-
organization_id=rule.project.organization.id,
397-
rule_id=rule.id,
394+
IssueAlertFiredEvent(
395+
issue_id=self.group.id,
396+
project_id=rule.project.id,
397+
organization_id=rule.project.organization.id,
398+
rule_id=rule.id,
399+
)
398400
)
399401

400402
if features.has(

src/sentry/tasks/auto_resolve_issues.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.utils import timezone as django_timezone
99

1010
from sentry import analytics
11+
from sentry.analytics.events.issue_auto_resolved import IssueAutoResolvedEvent
1112
from sentry.integrations.tasks.kick_off_status_syncs import kick_off_status_syncs
1213
from sentry.issues import grouptype
1314
from sentry.models.activity import Activity
@@ -138,12 +139,13 @@ def auto_resolve_project_issues(project_id, cutoff=None, chunk_size=1000, **kwar
138139
)
139140

140141
analytics.record(
141-
"issue.auto_resolved",
142-
project_id=project.id,
143-
organization_id=project.organization_id,
144-
group_id=group.id,
145-
issue_type=group.issue_type.slug,
146-
issue_category=group.issue_category.name.lower(),
142+
IssueAutoResolvedEvent(
143+
project_id=project.id,
144+
organization_id=project.organization_id,
145+
group_id=group.id,
146+
issue_type=group.issue_type.slug,
147+
issue_category=group.issue_category.name.lower(),
148+
)
147149
)
148150
# auto-resolve is a kind of resolve and this signal makes
149151
# sure all things that need to happen after resolve are triggered

0 commit comments

Comments
 (0)