Browse Source

feat(notifications): Add `actor_id` to Analytics Events (#28347)

Marcos Gaeta 3 years ago
parent
commit
c601cb125e

+ 0 - 14
src/sentry/analytics/events/notifications_sent.py

@@ -1,14 +0,0 @@
-from sentry import analytics
-
-
-class NotificationSent(analytics.Event):
-    type = "notifications.sent"
-
-    attributes = (
-        analytics.Attribute("organization_id"),
-        analytics.Attribute("project_id"),
-        analytics.Attribute("category"),
-    )
-
-
-analytics.register(NotificationSent)

+ 4 - 1
src/sentry/analytics/events/notifications_settings_updated.py

@@ -4,7 +4,10 @@ from sentry import analytics
 class NotificationSettingsUpdated(analytics.Event):
     type = "notifications.settings_updated"
 
-    attributes = (analytics.Attribute("target_type"),)
+    attributes = (
+        analytics.Attribute("target_type"),
+        analytics.Attribute("actor_id"),
+    )
 
 
 analytics.register(NotificationSettingsUpdated)

+ 12 - 0
src/sentry/integrations/slack/analytics.py

@@ -17,5 +17,17 @@ class SlackIntegrationStatus(analytics.Event):
     )
 
 
+class SlackIntegrationNotificationSent(analytics.Event):
+    type = "integrations.slack.notification_sent"
+
+    attributes = (
+        analytics.Attribute("organization_id"),
+        analytics.Attribute("project_id"),
+        analytics.Attribute("category"),
+        analytics.Attribute("actor_id"),
+    )
+
+
 analytics.register(SlackIntegrationAssign)
+analytics.register(SlackIntegrationNotificationSent)
 analytics.register(SlackIntegrationStatus)

+ 2 - 1
src/sentry/integrations/slack/notifications.py

@@ -168,10 +168,11 @@ def send_notification_as_slack(
                     },
                 )
             analytics.record(
-                "notifications.sent",
+                "integrations.slack.notification_sent",
                 organization_id=notification.organization.id,
                 project_id=notification.project.id,
                 category=notification.get_category(),
+                actor_id=recipient.actor_id,
             )
 
     key = get_key(notification)

+ 3 - 2
src/sentry/notifications/manager.py

@@ -109,9 +109,11 @@ class NotificationsManager(BaseManager["NotificationSetting"]):
           * Updating a user's per-project preferences
           * Updating a user's per-organization preferences
         """
+        target_id = get_target_id(user, team)
         analytics.record(
             "notifications.settings_updated",
             target_type="user" if user else "team",
+            actor_id=target_id,
         )
 
         # A missing DB row is equivalent to DEFAULT.
@@ -129,8 +131,6 @@ class NotificationsManager(BaseManager["NotificationSetting"]):
             raise Exception(f"value '{value}' is not valid for type '{type}'")
 
         scope_type, scope_identifier = get_scope(user, team, project, organization)
-        target_id = get_target_id(user, team)
-
         self._update_settings(provider, type, value, scope_type, scope_identifier, target_id)
 
     def remove_settings(
@@ -354,4 +354,5 @@ class NotificationsManager(BaseManager["NotificationSetting"]):
         analytics.record(
             "notifications.settings_updated",
             target_type="user" if user else "team",
+            actor_id=target_id,
         )