Skip to content

ref(analytics): Transform analytics events for TET-828 #95208

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

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

Closes TET-828
@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: Missing Fields in OrganizationCreatedEvent

The OrganizationCreatedEvent constructor is missing required fields (id, name, slug). The previous analytics.record call implicitly provided these from the org object, but the new OrganizationCreatedEvent class requires them explicitly. Only actor_id is currently passed, leading to a runtime error or incomplete event data.

src/sentry/api/endpoints/organization_index.py#L281-L286

analytics.record(
OrganizationCreatedEvent(
actor_id=request.user.id if request.user.is_authenticated else None,
)
)

Fix in CursorFix in Web


Bug: Incorrect Type Casting in Analytics Events

Analytics event definitions incorrectly type group_id, project_id, and organization_id as str. These fields are integers when passed from Django models (e.g., group.id, project.id, project.organization_id) in receivers/features.py.

src/sentry/analytics/events/issue_unresolved.py#L8-L9

organization_id: int
group_id: str

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

class IssuePriorityUpdatedEvent(analytics.Event):
group_id: str
new_priority: str
project_id: str
organization_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

❌ 44 Tests Failed:

Tests completed Failed Passed Skipped
27177 44 27133 240
View the top 3 failed test(s) by shortest run time
tests.sentry.analytics.test_base.AnalyticsTest::test_record
Stack Traces | 0.537s run time
#x1B[1m#x1B[.../sentry/analytics/test_base.py#x1B[0m:18: in test_record
    provider.record("organization.created", organization)
#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: OrganizationCreatedEvent.__init__() got an unexpected keyword argument 'data'#x1B[0m
tests.sentry.receivers.test_onboarding.OrganizationOnboardingTaskTest::test_project_created_with_origin
Stack Traces | 1.68s run time
#x1B[1m#x1B[.../sentry/receivers/test_onboarding.py#x1B[0m:173: in test_project_created_with_origin
    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('project.created', user_id=567, default_user_id=567, organization_id=4556391555334144, project_id=4556391555334146, platform=None, origin='ui')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(ProjectCreatedEvent(uuid_=UUID('44790fc9-5d6f-11f0-b894-7c1e52156447'), datetime_=datetime.datetime(2025, 7, 10, 9, 21, 33, 979498, tzinfo=datetime.timezone.utc), user_id='567', default_user_id='567', organization_id='4556391555334144', origin='ui', project_id='4556391555334146', platform=None))#x1B[0m
tests.sentry.receivers.test_onboarding.OrganizationOnboardingTaskTest::test_new_onboarding_complete
Stack Traces | 1.96s run time
#x1B[1m#x1B[.../sentry/receivers/test_onboarding.py#x1B[0m:857: 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('project.created', user_id=562, default_user_id=562, organization_id=4556391557627904, project_id=4556391557627906, platform='python', origin=None)#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(ProjectCreatedEvent(uuid_=UUID('5a01054b-5d6f-11f0-b894-0022482fd21b'), datetime_=datetime.datetime(2025, 7, 10, 9, 22, 8, 370540, tzinfo=datetime.timezone.utc), user_id='562', default_user_id='562', organization_id='4556391557627904', origin=None, project_id='4556391557627906', platform='python'))#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