Skip to content

ref(analytics): Transform analytics events for TET-836 #95215

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

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

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

Type annotations in analytics.Event classes are incorrect. ID fields (e.g., project_id, organization_id, group_id, issue_id, rule_id) are typed as str but receive integer values from model IDs. Additionally, fields like had_to_deassign and has_minified_stack_trace are annotated as str | None but receive boolean values. These type mismatches could cause runtime errors.

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

class IssueAutoResolvedEvent(analytics.Event):
project_id: str | None = None
organization_id: str
group_id: str
issue_category: str | None = None
issue_type: str | None = None

src/sentry/analytics/events/first_event_sent.py#L6-L13

class FirstEventSentEvent(analytics.Event):
user_id: str
organization_id: str
project_id: str
platform: str | None = None
url: str | None = None
has_minified_stack_trace: str | None = None
project_platform: str | None = None

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

class IssueAlertFiredEvent(analytics.Event):
issue_id: str
project_id: str
organization_id: str
rule_id: str

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

class ManualIssueAssignment(analytics.Event):
organization_id: str
project_id: str
group_id: str
assigned_by: str | None = None
had_to_deassign: str | None = None

src/sentry/rules/processing/processor.py#L393-L399

analytics.record(
IssueAlertFiredEvent(
issue_id=self.group.id,
project_id=rule.project.id,
organization_id=rule.project.organization.id,
rule_id=rule.id,
)

src/sentry/tasks/auto_resolve_issues.py#L141-L148

analytics.record(
IssueAutoResolvedEvent(
project_id=project.id,
organization_id=project.organization_id,
group_id=group.id,
issue_type=group.issue_type.slug,
issue_category=group.issue_category.name.lower(),
)

src/sentry/api/helpers/group_index/update.py#L1035-L1042

analytics.record(
ManualIssueAssignment(
organization_id=project_lookup[group.project_id].organization_id,
project_id=group.project_id,
group_id=group.id,
assigned_by=assigned_by,
had_to_deassign=assignment["updated_assignment"],
)

src/sentry/api/helpers/group_index/update.py#L1048-L1055

analytics.record(
ManualIssueAssignment(
organization_id=project_lookup[group.project_id].organization_id,
project_id=group.project_id,
group_id=group.id,
assigned_by=assigned_by,
had_to_deassign=True,
)

Fix in CursorFix in Web


Bug: Analytics Event Type Mismatch

The subclasses FirstEventSentEventForProject and FirstEventSentEventWithMinifiedStackTraceForProject inconsistently use the old type attribute, while their parent FirstEventSentEvent was updated to use the @analytics.eventclass decorator. Additionally, the has_minified_stack_trace attribute is type-hinted as str | None but receives a boolean value. These issues could lead to unexpected behavior in the analytics system.

src/sentry/analytics/events/first_event_sent.py#L11-L23

url: str | None = None
has_minified_stack_trace: str | None = None
project_platform: str | None = None
# first error for a project
class FirstEventSentEventForProject(FirstEventSentEvent):
type = "first_event_for_project.sent"
# first error with minified stack trace for a project
class FirstEventSentEventWithMinifiedStackTraceForProject(FirstEventSentEvent):
type = "first_event_with_minified_stack_trace_for_project.sent"

Fix in CursorFix in Web


Bug: Incorrect Type for `had_to_deassign` Field

The had_to_deassign field in ManualIssueAssignment is incorrectly typed as str | None. It should be bool | None as boolean values (e.g., assignment["updated_assignment"], True) are passed to it from src/sentry/api/helpers/group_index/update.py. This type mismatch could lead to runtime errors.

src/sentry/analytics/events/manual_issue_assignment.py#L9-L10

assigned_by: str | None = None
had_to_deassign: str | None = None

Fix in CursorFix in Web


Bug: Type Mismatch in Analytics Event Fields

Type annotations for analytics event fields are incorrect: ID fields (issue_id, project_id, organization_id, group_id, rule_id) are typed as str but receive integer values. Additionally, the had_to_deassign field is annotated as str | None but receives boolean values. This results in type mismatches between declared and actual parameter types.

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

class IssueAlertFiredEvent(analytics.Event):
issue_id: str
project_id: str
organization_id: str
rule_id: str

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

class ManualIssueAssignment(analytics.Event):
organization_id: str
project_id: str
group_id: str
assigned_by: str | None = None
had_to_deassign: 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

❌ 16 Tests Failed:

Tests completed Failed Passed Skipped
27175 16 27159 242
View the top 3 failed test(s) by shortest run time
tests.sentry.api.helpers.test_group_index.TestHandleAssignedTo::test_assigned_to
Stack Traces | 2.68s run time
#x1B[1m#x1B[.../api/helpers/test_group_index.py#x1B[0m:636: in test_assigned_to
    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('manual.issue_assignment', group_id=27, organization_id=4556391560708096, project_id=4556391560708098, assigned_by=None, had_to_deassign=False)#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(ManualIssueAssignment(uuid_=UUID('75fe06b8-5d6f-11f0-b894-7c1e527c0e55'), datetime_=datetime.datetime(2025, 7, 10, 9, 22, 55, 661474, tzinfo=datetime.timezone.utc), organization_id='4556391560708096', project_id='4556391560708098', group_id='27', assigned_by=None, had_to_deassign='False'))#x1B[0m
tests.sentry.receivers.test_onboarding.OrganizationOnboardingTaskTest::test_existing_complete_task
Stack Traces | 2.72s run time
#x1B[1m#x1B[.../sentry/receivers/test_onboarding.py#x1B[0m:63: in test_existing_complete_task
    first_event_received.send(project=project, event=event, sender=None)
#x1B[1m#x1B[31m.venv/lib/python3.13.../django/dispatch/dispatcher.py#x1B[0m:189: in send
    response = receiver(signal=self, sender=sender, **named)
#x1B[1m#x1B[.../sentry/receivers/onboarding.py#x1B[0m:134: in record_first_event
    analytics.record(
#x1B[1m#x1B[.../sentry/analytics/base.py#x1B[0m:52: in record
    event = event_cls.from_instance(instance, **kwargs)
#x1B[1m#x1B[.../sentry/analytics/event.py#x1B[0m:112: in from_instance
    return cls(
#x1B[1m#x1B[31mpydantic/dataclasses.py#x1B[0m:329: in pydantic.dataclasses._add_pydantic_validation_attributes.new_init
    ???
#x1B[1m#x1B[31mpydantic/dataclasses.py#x1B[0m:293: in pydantic.dataclasses._add_pydantic_validation_attributes.handle_extra_init
    ???
#x1B[1m#x1B[31mE   TypeError: FirstEventSentEvent.__init__() got an unexpected keyword argument 'data'#x1B[0m
tests.sentry.api.helpers.test_group_index.TestHandleAssignedTo::test_reassign_user
Stack Traces | 2.75s run time
#x1B[1m#x1B[.../api/helpers/test_group_index.py#x1B[0m:855: in test_reassign_user
    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('manual.issue_assignment', group_id=26, organization_id=4556391559266304, project_id=4556391559266306, assigned_by=None, had_to_deassign=True)#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(ManualIssueAssignment(uuid_=UUID('683f35c3-5d6f-11f0-b894-7c1e5245ab95'), datetime_=datetime.datetime(2025, 7, 10, 9, 22, 33, 520726, tzinfo=datetime.timezone.utc), organization_id='4556391559266304', project_id='4556391559266306', group_id='26', assigned_by=None, had_to_deassign='True'))#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