Skip to content

ref(analytics): Transform analytics events for TET-838 #95217

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

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

Closes TET-838
@constantinius constantinius requested review from a team as code owners July 10, 2025 09:18
@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 Subclasses

Type annotation mismatch in analytics.Event subclasses. The organization_id, project_id, and user_id fields are annotated as str or str | None, but are consistently passed integer values (Django model primary keys) from call sites. This change from the more permissive analytics.Attribute definitions to strict type annotations could lead to runtime errors or type checking failures if strict type validation is enforced.

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

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

src/sentry/analytics/events/eventuser_endpoint_request.py#L5-L7

class EventUserEndpointRequest(analytics.Event):
endpoint: str
project_id: str | None = None

Fix in CursorFix in Web


Bug: Type Mismatch in `project_id` Field

The project_id field in EventUserEndpointRequest is annotated as str | None, but calling code passes integer values (e.g., project.id, group.project_id), leading to a type mismatch that could cause runtime errors or type checking failures.

src/sentry/analytics/events/eventuser_endpoint_request.py#L6-L7

endpoint: str
project_id: 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

❌ 6 Tests Failed:

Tests completed Failed Passed Skipped
27175 6 27169 242
View the top 3 failed test(s) by shortest run time
tests.sentry.api.endpoints.test_project_users.EventUserProjectUsersTest::test_staff_simple
Stack Traces | 4.16s run time
#x1B[1m#x1B[.../api/endpoints/test_project_users.py#x1B[0m:93: in test_staff_simple
    self._assert_simple_response(response, mock_record)
#x1B[1m#x1B[.../api/endpoints/test_project_users.py#x1B[0m:58: in _assert_simple_response
    mock_record.assert_any_call(
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:1048: in assert_any_call
    raise AssertionError(
#x1B[1m#x1B[31mE   AssertionError: record('eventuser_endpoint.request', project_id=4556391562739714, endpoint='sentry.api.endpoints.project_users.get') call not found#x1B[0m
tests.sentry.api.endpoints.test_group_tagkey_values.GroupTagKeyValuesTest::test_simple
Stack Traces | 4.44s run time
#x1B[1m#x1B[.../api/endpoints/test_group_tagkey_values.py#x1B[0m:36: in test_simple
    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('eventuser_endpoint.request', project_id=4556391558545410, endpoint='sentry.api.endpoints.group_tagkey_values.get')#x1B[0m
#x1B[1m#x1B[31mE     Actual: record(EventUserEndpointRequest(uuid_=UUID('61ddd434-5d6f-11f0-b894-7c1e52868c2f'), datetime_=datetime.datetime(2025, 7, 10, 9, 22, 22, 912985, tzinfo=datetime.timezone.utc), endpoint='sentry.api.endpoints.group_tagkey_values.get', project_id='4556391558545410'))#x1B[0m
tests.sentry.api.endpoints.test_project_users.EventUserProjectUsersTest::test_superuser_simple
Stack Traces | 4.62s run time
#x1B[1m#x1B[.../api/endpoints/test_project_users.py#x1B[0m:82: in test_superuser_simple
    self._assert_simple_response(response, mock_record)
#x1B[1m#x1B[.../api/endpoints/test_project_users.py#x1B[0m:58: in _assert_simple_response
    mock_record.assert_any_call(
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/unittest/mock.py#x1B[0m:1048: in assert_any_call
    raise AssertionError(
#x1B[1m#x1B[31mE   AssertionError: record('eventuser_endpoint.request', project_id=4556391563067393, endpoint='sentry.api.endpoints.project_users.get') call not found#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