Skip to content

ref(analytics): Transform analytics events for TET-830 #95210

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

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

Closes TET-830
@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: Incorrect Type for Project IDs List

The project_ids field in ReleaseGetPreviousCommitsEvent and ReleaseSetCommitsLocalEvent is incorrectly typed as str. It is consistently used to pass a list of project IDs, such as [project.id for project in release.projects.all()] in src/sentry/issues/endpoints/organization_release_previous_commits.py. This type mismatch should be corrected to list[int].

src/sentry/analytics/events/release_get_previous_commits.py#L7-L8

organization_id: str
project_ids: str

src/sentry/analytics/events/release_set_commits.py#L7-L8

organization_id: str
project_ids: str

Fix in CursorFix in Web


Bug: Type Mismatch in Alert Event IDs

The AlertSentEvent class defines organization_id, project_id, and alert_id as str. However, the AlertSentEvent is instantiated with integer IDs (e.g., event.organization.id, event.project_id, rule.id) for these fields. Specifically, alert_id receives an integer or an empty string. This type mismatch could cause runtime errors or unexpected analytics behavior.

src/sentry/rules/actions/integrations/base.py#L124-L133

analytics.record(
AlertSentEvent(
provider=self.provider,
alert_id=rule.id if rule else "",
alert_type="issue_alert",
organization_id=event.organization.id,
project_id=event.project_id,
external_id=external_id,
notification_uuid=notification_uuid if notification_uuid else "",
)

src/sentry/analytics/events/alert_sent.py#L5-L16

class AlertSentEvent(analytics.Event):
organization_id: str
project_id: str
# The id of the Alert or AlertRule
alert_id: str
# "issue_alert" or "metric_alert"
alert_type: str
# Slack, msteams, email, etc.
provider: str
# User_id if sent via email, channel id if sent via slack, etc.
external_id: str | None = None
notification_uuid: str | None = None

Fix in CursorFix in Web


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

Copy link

codecov bot commented Jul 10, 2025

❌ 40 Tests Failed:

Tests completed Failed Passed Skipped
27176 40 27136 241
View the top 3 failed test(s) by shortest run time
tests.sentry.monitors.processing_errors.test_manager.HandleProcessingErrorsTest::test
Stack Traces | 2.09s run time
#x1B[1m#x1B[.../monitors/processing_errors/test_manager.py#x1B[0m:251: in test
    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('checkin_processing_error.stored', organization_id=4556391560970240, project_id=4556391560970242, monitor_slug='9b0bf129fe35', error_types=[<ProcessingErrorType.CHECKIN_INVALID_GUID: 4>])#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(CheckinProcessingErrorStored(uuid_=UUID('77f6b65b-5d6f-11f0-b894-7c1e52d46ce8'), datetime_=datetime.datetime(2025, 7, 10, 9, 22, 59, 539969, tzinfo=datetime.timezone.utc), organization_id='4556391560970240', project_id='4556391560970242', monitor_slug='9b0bf129fe35', error_types=[<ProcessingErrorType.CHECKIN_INVALID_GUID: 4>]))#x1B[0m
tests.sentry.receivers.test_onboarding.OrganizationOnboardingTaskTest::test_new_onboarding_complete
Stack Traces | 2.2s run time
#x1B[1m#x1B[.../sentry/receivers/test_onboarding.py#x1B[0m:880: in test_new_onboarding_complete
    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('first_transaction.sent', default_user_id=567, organization_id=4556391560708096, project_id=4556391560708098, platform='python')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(FirstTransactionSentEvent(uuid_=UUID('75ebcec5-5d6f-11f0-b894-6045bdfdf593'), datetime_=datetime.datetime(2025, 7, 10, 9, 22, 55, 915850, tzinfo=datetime.timezone.utc), organization_id='4556391560708096', project_id='4556391560708098', platform='python', default_user_id='567'))#x1B[0m
tests.sentry.incidents.action_handlers.test_pagerduty.PagerDutyActionHandlerTest::test_alert_sent_recorded
Stack Traces | 2.31s run time
#x1B[1m#x1B[.../incidents/action_handlers/test_pagerduty.py#x1B[0m:266: in test_alert_sent_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('alert.sent', organization_id=4556391539015680, project_id=4556391539015682, provider='pagerduty', alert_id=17, alert_type='metric_alert', external_id='28', notification_uuid='')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(AlertSentEvent(uuid_=UUID('b0b525e1-5d6e-11f0-8df7-6045bdfdf593'), datetime_=datetime.datetime(2025, 7, 10, 9, 17, 24, 93281, tzinfo=datetime.timezone.utc), organization_id='4556391539015680', project_id='4556391539015682', alert_id='17', alert_type='metric_alert', provider='pagerduty', external_id='28', notification_uuid=''))#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