Skip to content

ref(analytics): Transform analytics events for TET-829 #95209

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

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

Closes TET-829
@constantinius constantinius requested review from a team as code owners July 10, 2025 09:14
@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: Type Annotations Mismatch in Analytics Event

The IntegrationServerlessSetup analytics event has incorrect type annotations. The user_id, organization_id, success_count, and failure_count fields are typed as str but should be int. These fields receive integer values (e.g., user/organization IDs, counts from len() operations) as demonstrated in src/sentry/integrations/aws_lambda/integration.py. This type mismatch can lead to runtime errors.

src/sentry/analytics/events/integration_serverless_setup.py#L5-L10

class IntegrationServerlessSetup(analytics.Event):
user_id: str
organization_id: str
integration: str
success_count: str
failure_count: str

Fix in CursorFix in Web


Bug: Analytics ID Fields Incorrectly Typed

Several analytics event classes incorrectly type ID fields (user_id, organization_id, project_id, codeowners_id) as str or str | None. These fields should be typed as int or int | None as they consistently receive integer values from Django model ID attributes.

src/sentry/analytics/events/first_feedback_sent.py#L5-L9

class FirstFeedbackSentEvent(analytics.Event):
organization_id: str
project_id: str
platform: str | None = None
user_id: str | None = None

src/sentry/analytics/events/project_issue_searched.py#L5-L9

class ProjectIssueSearchEvent(analytics.Event):
user_id: str | None = None
organization_id: str
project_id: str
query: str

src/sentry/analytics/events/codeowners_updated.py#L5-L9

class CodeownersUpdated(analytics.Event):
user_id: str | None = None
organization_id: str
project_id: str
codeowners_id: str

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

class FirstFlagSentEvent(analytics.Event):
organization_id: str
project_id: str
platform: str | None = None

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

class FirstReleaseTagSentEvent(analytics.Event):
user_id: str
organization_id: str
project_id: str

src/sentry/analytics/events/first_replay_sent.py#L5-L9

class FirstReplaySentEvent(analytics.Event):
organization_id: str
project_id: str
platform: str | None = None
user_id: str | None = None

src/sentry/analytics/events/second_platform_added.py#L5-L9

class SecondPlatformAddedEvent(analytics.Event):
user_id: str
organization_id: str
project_id: str
platform: str | None = None

src/sentry/analytics/events/weekly_report.py#L5-L9

class WeeklyReportSent(analytics.Event):
organization_id: str
user_id: str
notification_uuid: str
user_project_count: int

Fix in CursorFix in Web


Bug: Type Mismatch in `num_groups` Field

The num_groups field in IssueForecastSaved is typed as str but should be int. It receives an integer value from len(group_counts.keys()) in src/sentry/issues/escalating/forecasts.py.

src/sentry/issues/analytics.py#L5-L6

class IssueForecastSaved(analytics.Event):
num_groups: str

Fix in CursorFix in Web


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

Copy link

codecov bot commented Jul 10, 2025

❌ 34 Tests Failed:

Tests completed Failed Passed Skipped
27174 34 27140 243
View the top 3 failed test(s) by shortest run time
tests.sentry.middleware.test_devtoolbar.DevToolbarAnalyticsMiddlewareUnitTest::test_view_name_and_route
Stack Traces | 0.091s run time
#x1B[1m#x1B[.../sentry/middleware/test_devtoolbar.py#x1B[0m:74: in test_view_name_and_route
    assert mock_record.call_args[0][0] == self.analytics_event_name
#x1B[1m#x1B[31mE   AssertionError: assert DevToolbarApiRequestEvent(uuid_=UUID('5a89f3dd-5d6f-11f0-b894-7c1e52b8fcc9'), datetime_=datetime.datetime(2025, 7, 10,...ethod='GET', status_code=200, organization_id=1, organization_slug=None, project_id=1, project_slug=None, user_id=None) == 'devtoolbar.api_request'#x1B[0m
#x1B[1m#x1B[31mE    +  where 'devtoolbar.api_request' = <tests.sentry.middleware.test_devtoolbar.DevToolbarAnalyticsMiddlewareUnitTest testMethod=test_view_name_and_route>.analytics_event_name#x1B[0m
tests.sentry.middleware.test_devtoolbar.DevToolbarAnalyticsMiddlewareUnitTest::test_origin
Stack Traces | 0.105s run time
#x1B[1m#x1B[.../sentry/middleware/test_devtoolbar.py#x1B[0m:100: in test_origin
    mock_record.assert_called()
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:946: in assert_called
    raise AssertionError(msg)
#x1B[1m#x1B[31mE   AssertionError: Expected 'record' to have been called.#x1B[0m
tests.sentry.middleware.test_devtoolbar.DevToolbarAnalyticsMiddlewareUnitTest::test_origin_from_referrer
Stack Traces | 0.115s run time
#x1B[1m#x1B[.../sentry/middleware/test_devtoolbar.py#x1B[0m:113: in test_origin_from_referrer
    mock_record.assert_called()
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:946: in assert_called
    raise AssertionError(msg)
#x1B[1m#x1B[31mE   AssertionError: Expected 'record' to have been called.#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