Skip to content

Commit

Permalink
feat(notifications): Add actor_id to Analytics Events (#28347)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaeta authored and shruthilayaj committed Sep 7, 2021
1 parent 712757c commit 84d2929
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
14 changes: 0 additions & 14 deletions src/sentry/analytics/events/notifications_sent.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
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 changes: 12 additions & 0 deletions src/sentry/integrations/slack/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion src/sentry/integrations/slack/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/sentry/notifications/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ def update_settings(
* 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.
Expand All @@ -129,8 +131,6 @@ def update_settings(
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(
Expand Down Expand Up @@ -354,4 +354,5 @@ def update_settings_bulk(
analytics.record(
"notifications.settings_updated",
target_type="user" if user else "team",
actor_id=target_id,
)

0 comments on commit 84d2929

Please sign in to comment.