Skip to content

ref(analytics): Transform analytics events for TET-833 #95213

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 1 commit 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-833

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

Closes TET-833
@constantinius constantinius requested review from a team as code owners July 10, 2025 09:16
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 10, 2025
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: Undefined Provider Argument in IssueResolvedEvent

The IssueResolvedEvent is instantiated with a provider argument that is not defined in its class, causing a TypeError. This prevents the issue.resolved analytics event from being recorded with the provider information, which was previously captured.

src/sentry/integrations/tasks/sync_status_inbound.py#L296-L307

analytics.record(
IssueResolvedEvent(
project_id=group.project.id,
default_user_id="Sentry Jira",
organization_id=organization_id,
group_id=group.id,
resolution_type="with_third_party_app",
provider=provider.key,
issue_type=group.issue_type.slug,
issue_category=group.issue_category.name.lower(),
)
)

Fix in CursorFix in Web


Bug: Missing `user_id` Field Causes Event Recording Error

The IntegrationIssueCommentsSyncedEvent class in src/sentry/integrations/analytics.py lacks a user_id field. Despite this, user_id is passed to its constructor in analytics.record() calls within src/sentry/integrations/tasks/create_comment.py and src/sentry/integrations/tasks/update_comment.py. This mismatch results in a TypeError when the event is recorded, as user_id is an unexpected argument.

src/sentry/integrations/analytics.py#L53-L58

@analytics.eventclass("integration.issue.comments.synced")
class IntegrationIssueCommentsSyncedEvent(analytics.Event):
provider: str
id: str
organization_id: str

src/sentry/integrations/tasks/create_comment.py#L71-L77

analytics.record(
IntegrationIssueCommentsSyncedEvent(
provider=installation.model.provider,
id=installation.model.id,
organization_id=external_issue.organization_id,
user_id=user_id,
)

src/sentry/integrations/tasks/update_comment.py#L71-L77

analytics.record(
IntegrationIssueCommentsSyncedEvent(
provider=installation.model.provider,
id=installation.model.id,
organization_id=external_issue.organization_id,
user_id=user_id,
)

Fix in CursorFix in Web


Bug: Type Mismatch in Analytics Event Fields

Type mismatch: Analytics event classes, such as IssueResolvedEvent and GroupOwnerAssignment, declare organization_id, project_id, and group_id fields as str types. However, integer database IDs are being passed to these fields at various call sites, which can lead to runtime type errors or incorrect analytics data.

src/sentry/receivers/features.py#L241-L250

IssueResolvedEvent(
user_id=user_id,
project_id=project.id,
default_user_id=default_user_id,
organization_id=organization_id,
group_id=group.id,
resolution_type=resolution_type,
issue_type=group.issue_type.slug,
issue_category=group.issue_category.name.lower(),
)

src/sentry/analytics/events/groupowner_assignment.py#L5-L8

class GroupOwnerAssignment(analytics.Event):
organization_id: str
project_id: str
group_id: str

Fix in CursorFix in Web


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

Copy link

codecov bot commented Jul 10, 2025

❌ 20 Tests Failed:

Tests completed Failed Passed Skipped
27177 20 27157 240
View the top 3 failed test(s) by shortest run time
tests.sentry.receivers.test_onboarding.OrganizationOnboardingTaskTest::test_real_time_notifications_added
Stack Traces | 1.34s run time
#x1B[1m#x1B[.../sentry/receivers/test_onboarding.py#x1B[0m:748: in test_real_time_notifications_added
    record_analytics.assert_called_with(
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:977: in assert_called_with
    raise AssertionError(_error_message()) from cause
#x1B[1m#x1B[31mE   AssertionError: expected call not found.#x1B[0m
#x1B[1m#x1B[31mE   Expected: record('integration.added', user_id=566, default_user_id=566, organization_id=4556391568310272, id=118, provider='slack')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(IntegrationAddedEvent(uuid_=UUID('ba82b044-5d6f-11f0-b894-6045bd043b7f'), datetime_=datetime.datetime(2025, 7, 10, 9, 24, 51, 756271, tzinfo=datetime.timezone.utc), provider='slack', id='118', organization_id='4556391568310272', user_id='566', default_user_id='566'))#x1B[0m
tests.sentry.receivers.test_onboarding.OrganizationOnboardingTaskTest::test_source_code_management_added
Stack Traces | 1.55s run time
#x1B[1m#x1B[.../sentry/receivers/test_onboarding.py#x1B[0m:773: in test_source_code_management_added
    record_analytics.assert_called_with(
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:977: in assert_called_with
    raise AssertionError(_error_message()) from cause
#x1B[1m#x1B[31mE   AssertionError: expected call not found.#x1B[0m
#x1B[1m#x1B[31mE   Expected: record('integration.added', user_id=572, default_user_id=572, organization_id=4556391568441344, id=124, provider='github')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(IntegrationAddedEvent(uuid_=UUID('bbb2aae6-5d6f-11f0-b894-6045bd043b7f'), datetime_=datetime.datetime(2025, 7, 10, 9, 24, 53, 731996, tzinfo=datetime.timezone.utc), provider='github', id='124', organization_id='4556391568441344', user_id='572', default_user_id='572'))#x1B[0m
tests.sentry.receivers.test_signals.SignalsTest::test_issue_resolved_with_default_owner
Stack Traces | 2.31s run time
#x1B[1m#x1B[.../sentry/receivers/test_signals.py#x1B[0m:91: in test_issue_resolved_with_default_owner
    mock_record.assert_called_once_with(
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1....../x64/lib/python3.13/unittest/mock.py#x1B[0m:989: in assert_called_once_with
    return self.assert_called_with(*args, **kwargs)
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1....../x64/lib/python3.13/unittest/mock.py#x1B[0m:977: in assert_called_with
    raise AssertionError(_error_message()) from cause
#x1B[1m#x1B[31mE   AssertionError: expected call not found.#x1B[0m
#x1B[1m#x1B[31mE   Expected: record('issue.resolved', user_id=None, project_id=4556391569686529, default_user_id=601, organization_id=4556391569620992, group_id=180, resolution_type='now', issue_type='error', issue_category='error')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(IssueResolvedEvent(uuid_=UUID('c7a9ea08-5d6f-11f0-b894-0022480aa811'), datetime_=datetime.datetime(2025, 7, 10, 9, 25, 12, 104043, tzinfo=datetime.timezone.utc), user_id=None, project_id='4556391569686529', default_user_id='601', organization_id='4556391569620992', group_id='180', resolution_type='now', issue_category='error', issue_type='error'))#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

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