Skip to content

feat(analytics): typesafe-event-record #92943

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

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

constantinius
Copy link
Contributor

@constantinius constantinius commented Jun 5, 2025

Closes https://linear.app/getsentry/issue/TET-472/analytics-refactor-analyticsrecord-to-be-type-safe
Closes https://linear.app/getsentry/issue/TET-471/analytics-refactor-analyticsevent-to-be-dataclass-based

Contributes to https://linear.app/getsentry/issue/TET-474/analytics-migrate-all-subclasses-of-analyticsevent
Contributes to https://linear.app/getsentry/issue/TET-473/analytics-update-callsites-of-analyticsrecord-in-both-sentry-and

Making analytics.record and analytics.Event typesafer

Deprecate stringly typed analytics.record() in favor of version that uses analytics.Event objects.
Migrating analytics.Event to dataclasses. For convenience introduce the analytics.eventclass decorator, which sets the type and applies the dataclass decorator with common parameters underneath.

Migrate all subclasses in Sentry to the new dataclass based scheme.

Deprecate stringly typed analytics.record() in favor of version that uses Event objects.
Migrating Event to dataclasses. For convenience introduce the 'eventclass' macro, which sets the 'type' and configures the dataclass underneath.
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 5, 2025
Copy link

codecov bot commented Jun 10, 2025

❌ 209 Tests Failed:

Tests completed Failed Passed Skipped
26601 209 26392 230
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.095s 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('bf5f8c5a-4c4c-11f0-8992-6045bd7b0204'), datetime_=datetime.datetime(2025, 6, 18,...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.101s 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_methods
Stack Traces | 0.109s run time
#x1B[1m#x1B[.../sentry/middleware/test_devtoolbar.py#x1B[0m:137: in test_methods
    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.


@classmethod
def from_instance(cls, instance: Any, **kwargs: Any) -> Event:
@deprecated("This constructor function is discuraged, as it is not type-safe.")
def from_instance(cls, instance: Any, **kwargs: Any) -> Self:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now we need to remove the deprecation, as this causes failures in tests

@getsantry
Copy link
Contributor

getsantry bot commented Jul 15, 2025

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added Stale and removed Stale labels Jul 15, 2025
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