Skip to content

ref(analytics): Transform analytics events for TET-827 #95207

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-827

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

Closes TET-827
@constantinius constantinius requested review from a team as code owners July 10, 2025 09:13
@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: Event Constructor Mismatch Causes TypeError

The IntegrationIssueCommentsSyncedEvent constructor is incorrectly called with a user_id parameter in src/sentry/integrations/tasks/create_comment.py and src/sentry/integrations/tasks/update_comment.py. The IntegrationIssueCommentsSyncedEvent class definition in src/sentry/integrations/analytics.py does not include a user_id field, which will cause a TypeError when the event is instantiated.

src/sentry/integrations/tasks/create_comment.py#L70-L78

note.save()
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#L70-L78

installation.update_comment(external_issue.key, user_id, note)
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: Event Class Decorator Inheritance Issue

The child class FirstSourcemapsSentEventForProject still uses the old type attribute for event definition, while its parent FirstSourcemapsSentEvent has been updated to use the @analytics.eventclass decorator. This inconsistency creates a mixed pattern that could prevent the child class from being correctly registered or recognized by the analytics system.

src/sentry/analytics/events/first_sourcemaps_sent.py#L13-L15

class FirstSourcemapsSentEventForProject(FirstSourcemapsSentEvent):
type = "first_sourcemaps_for_project.sent"

Fix in CursorFix in Web


Bug: Event Constructor Receives Undefined Parameter

The IssueResolvedEvent constructor is incorrectly passed a provider parameter. This argument, carried over from the previous analytics.record call, is not defined in the IssueResolvedEvent class, causing a TypeError upon instantiation.

src/sentry/integrations/tasks/sync_status_inbound.py#L295-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


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

Copy link

codecov bot commented Jul 10, 2025

❌ 19 Tests Failed:

Tests completed Failed Passed Skipped
27175 19 27156 242
View the top 3 failed test(s) by shortest run time
tests.sentry.api.helpers.test_group_index.ValidateSearchFilterPermissionsTest::test_negative
Stack Traces | 1.12s run time
#x1B[1m#x1B[.../api/helpers/test_group_index.py#x1B[0m:64: in test_negative
    self.assert_analytics_recorded(mock_record)
#x1B[1m#x1B[.../api/helpers/test_group_index.py#x1B[0m:47: in assert_analytics_recorded
    mock_record.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('advanced_search.feature_gated', user_id=210, default_user_id=210, organization_id=4556391542226944)#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(AdvancedSearchFeatureGateEvent(uuid_=UUID('cddda26e-5d6e-11f0-b894-6045bded80b0'), datetime_=datetime.datetime(2025, 7, 10, 9, 18, 13, 497045, tzinfo=datetime.timezone.utc), user_id='210', default_user_id='210', organization_id='4556391542226944'))#x1B[0m
tests.sentry.api.helpers.test_group_index.ValidateSearchFilterPermissionsTest::test_wildcard
Stack Traces | 1.17s run time
#x1B[1m#x1B[.../api/helpers/test_group_index.py#x1B[0m:86: in test_wildcard
    self.assert_analytics_recorded(mock_record)
#x1B[1m#x1B[.../api/helpers/test_group_index.py#x1B[0m:47: in assert_analytics_recorded
    mock_record.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('advanced_search.feature_gated', user_id=257, default_user_id=257, organization_id=4556391542882304)#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(AdvancedSearchFeatureGateEvent(uuid_=UUID('d47a28f2-5d6e-11f0-b894-000d3a4eb513'), datetime_=datetime.datetime(2025, 7, 10, 9, 18, 24, 104736, tzinfo=datetime.timezone.utc), user_id='257', default_user_id='257', organization_id='4556391542882304'))#x1B[0m
tests.sentry.receivers.test_onboarding.OrganizationOnboardingTaskTest::test_real_time_notifications_added
Stack Traces | 1.36s 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=571, default_user_id=571, organization_id=4556391555596288, id=118, provider='slack')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(IntegrationAddedEvent(uuid_=UUID('477d15c0-5d6f-11f0-b894-6045bda27bba'), datetime_=datetime.datetime(2025, 7, 10, 9, 21, 37, 625383, tzinfo=datetime.timezone.utc), provider='slack', id='118', organization_id='4556391555596288', user_id='571', default_user_id='571'))#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