Skip to content

ref(analytics): Transform analytics events for TET-831 #95211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

constantinius
Copy link
Contributor

  • Transform event classes to use @analytics.eventclass decorator
  • Transform analytics.record calls to use event class instances
  • Update imports as needed

Closes TET-831

- Transform event classes to use @analytics.eventclass decorator
- Transform analytics.record calls to use event class instances
- Update imports as needed

Closes TET-831
@constantinius constantinius requested review from a team as code owners July 10, 2025 09:15
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 10, 2025
cursor[bot]

This comment was marked as outdated.

Copy link

codecov bot commented Jul 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #95211      +/-   ##
==========================================
- Coverage   87.85%   80.32%   -7.53%     
==========================================
  Files       10469    10468       -1     
  Lines      605377   605268     -109     
  Branches    23674    23667       -7     
==========================================
- Hits       531832   486190   -45642     
- Misses      73185   118718   +45533     
  Partials      360      360              

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Integration ID Fields Receive Unexpected Integer Values

Analytics event classes in Discord, Slack, and Codeowners integrations define ID fields (e.g., organization_id, project_id, group_id, actor_id, user_id, alert_id) as str or str | None. However, these fields consistently receive integer values, leading to a type mismatch that could cause runtime errors or data inconsistency.

src/sentry/integrations/slack/analytics.py#L5-L47

class SlackIntegrationAssign(analytics.Event):
actor_id: str | None = None
@analytics.eventclass("integrations.slack.status")
class SlackIntegrationStatus(analytics.Event):
organization_id: str
status: str
resolve_type: str | None = None
user_id: str | None = None
@analytics.eventclass("integrations.slack.notification_sent")
class SlackIntegrationNotificationSent(analytics.Event):
organization_id: str
project_id: str | None = None
category: str
actor_id: str | None = None
user_id: str | None = None
group_id: str | None = None
notification_uuid: str
alert_id: str | None = None
actor_type: str | None = None
@analytics.eventclass("integrations.identity_linked")
class IntegrationIdentityLinked(analytics.Event):
provider: str
actor_id: str
actor_type: str
@analytics.eventclass("integrations.slack.chart_unfurl")
class IntegrationSlackChartUnfurl(analytics.Event):
user_id: str | None = None
organization_id: str
unfurls_count: int
@analytics.eventclass("integrations.slack.chart_unfurl_action")
class IntegrationSlackLinkIdentity(analytics.Event):
organization_id: str
action: str

src/sentry/integrations/discord/analytics.py#L5-L47

class DiscordIntegrationNotificationSent(analytics.Event):
organization_id: str
project_id: str
category: str
group_id: str
notification_uuid: str
alert_id: str | None = None
@analytics.eventclass("integrations.discord.command_interaction")
class DiscordIntegrationCommandInteractionReceived(analytics.Event):
command_name: str
@analytics.eventclass("integrations.discord.identity_linked")
class DiscordIntegrationIdentityLinked(analytics.Event):
provider: str
actor_id: str
actor_type: str
@analytics.eventclass("integrations.discord.identity_unlinked")
class DiscordIntegrationIdentityUnlinked(analytics.Event):
provider: str
actor_id: str
actor_type: str
@analytics.eventclass("integrations.discord.message_interaction")
class DiscordIntegrationMessageInteractionReceived(analytics.Event):
custom_id: str
@analytics.eventclass("integrations.discord.assign")
class DiscordIntegrationAssign(analytics.Event):
actor_id: str
@analytics.eventclass("integrations.discord.status")
class DiscordIntegrationStatus(analytics.Event):
organization_id: str
user_id: str
status: str

src/sentry/api/endpoints/codeowners/analytics.py#L5-L6

class CodeOwnersMaxLengthExceeded(analytics.Event):
organization_id: str

Fix in CursorFix in Web


Bug: Slack Integration Event System Inconsistency

The IntegrationSlackRejectMemberInvitation class is inconsistent with the new analytics event system. It inherits from IntegrationSlackApproveMemberInvitation, which uses the @analytics.eventclass decorator, but still defines its event type with the old type = "..." attribute. This prevents proper analytics registration and may cause event recording issues.

src/sentry/integrations/slack/analytics.py#L51-L59

class IntegrationSlackApproveMemberInvitation(analytics.Event):
organization_id: str
actor_id: str
invitation_type: str
invited_member_id: str
class IntegrationSlackRejectMemberInvitation(IntegrationSlackApproveMemberInvitation):
type = "integrations.slack.reject_member_invitation"

Fix in CursorFix in Web


Bug: Incorrect Type Passed to Discord Event Parameter

The DiscordIntegrationStatus event is incorrectly instantiated by passing the entire data mapping (type Mapping[str, object]) to its status parameter. This parameter expects a str, leading to a type mismatch and potential runtime errors. The correct value, a status string, should be extracted from the data mapping (e.g., data.get("status")).

src/sentry/integrations/discord/webhooks/message_component.py#L245-L250

analytics.record(
DiscordIntegrationStatus(
organization_id=self.group.organization.id,
user_id=self.user.id,
status=data,
)

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant