Skip to content

feat(release health): Update snuba metrics to know about session unhandled state #96707

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 9 commits into
base: master
Choose a base branch
from

Conversation

ryan953
Copy link
Member

@ryan953 ryan953 commented Jul 29, 2025

In support of https://www.notion.so/sentry/RFC-Session-Status-unhandled-2308b10e4b5d801d9805fece61533ac5#2308b10e4b5d80e9b312ecbea27a4af3 this change adds support for reading back sessions data with the unhandled status type.

Some of the places in the ui that read this value will be asking for it directly. In this PR we need to make the backend aware of the new type, and update the TypedDicts that will return it. Also we do some special handling to create some fields like unhandled_sessions and unhandled_users that will appear in the main section of the Release Details page.

All the existing tests in test_sessions.py and test_sessions_v2.py were updated to account for the new fields to be returned. I added some extra tests to make use of the new fields directly as well.

Related to REPLAY-580

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 29, 2025
Copy link

codecov bot commented Jul 29, 2025

❌ 8 Tests Failed:

Tests completed Failed Passed Skipped
303 8 295 19
View the top 3 failed test(s) by shortest run time
::tests.snuba.api.endpoints.test_organization_sessions
Stack Traces | 0s run time
#x1B[1m#x1B[.../api/endpoints/test_organization_sessions.py#x1B[0m:10: in <module>
    from sentry.release_health.metrics import MetricsReleaseHealthBackend
#x1B[1m#x1B[.../sentry/release_health/metrics.py#x1B[0m:35: in <module>
    from sentry.release_health.metrics_sessions_v2 import run_sessions_query
#x1B[1m#x1B[.../sentry/release_health/metrics_sessions_v2.py#x1B[0m:263: in <module>
    class SumSessionField(CountField):
#x1B[1m#x1B[.../sentry/release_health/metrics_sessions_v2.py#x1B[0m:269: in SumSessionField
    SessionStatus.UNHANDLED: MetricField(None, SessionMRI.UNHANDLED.value),
#x1B[1m#x1B[31mE   AttributeError: type object 'SessionStatus' has no attribute 'UNHANDLED'#x1B[0m
::tests.snuba.api.endpoints.test_organization_sessions
Stack Traces | 0s run time
#x1B[1m#x1B[.../api/endpoints/test_organization_sessions.py#x1B[0m:10: in <module>
    from sentry.release_health.metrics import MetricsReleaseHealthBackend
#x1B[1m#x1B[.../sentry/release_health/metrics.py#x1B[0m:35: in <module>
    from sentry.release_health.metrics_sessions_v2 import run_sessions_query
#x1B[1m#x1B[.../sentry/release_health/metrics_sessions_v2.py#x1B[0m:263: in <module>
    class SumSessionField(CountField):
#x1B[1m#x1B[.../sentry/release_health/metrics_sessions_v2.py#x1B[0m:269: in SumSessionField
    SessionStatus.UNHANDLED: MetricField(None, SessionMRI.UNHANDLED.value),
#x1B[1m#x1B[31mE   AttributeError: type object 'SessionStatus' has no attribute 'UNHANDLED'#x1B[0m
::tests.snuba.sessions.test_sessions
Stack Traces | 0s run time
#x1B[1m#x1B[.../snuba/sessions/test_sessions.py#x1B[0m:11: in <module>
    from sentry.release_health.metrics import MetricsReleaseHealthBackend
#x1B[1m#x1B[.../sentry/release_health/metrics.py#x1B[0m:35: in <module>
    from sentry.release_health.metrics_sessions_v2 import run_sessions_query
#x1B[1m#x1B[.../sentry/release_health/metrics_sessions_v2.py#x1B[0m:263: in <module>
    class SumSessionField(CountField):
#x1B[1m#x1B[.../sentry/release_health/metrics_sessions_v2.py#x1B[0m:269: in SumSessionField
    SessionStatus.UNHANDLED: MetricField(None, SessionMRI.UNHANDLED.value),
#x1B[1m#x1B[31mE   AttributeError: type object 'SessionStatus' has no attribute 'UNHANDLED'#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.

@ryan953 ryan953 marked this pull request as ready for review July 31, 2025 00:14
@ryan953 ryan953 requested review from a team as code owners July 31, 2025 00:14
@ryan953 ryan953 requested review from cmanallen and a team July 31, 2025 00:14
cursor[bot]

This comment was marked as outdated.

Copy link

linear bot commented Jul 31, 2025

cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

@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 Enum Member Causes Runtime Error

The SessionStatus enum is missing the UNHANDLED member. Code attempts to reference SessionStatus.UNHANDLED in _get_required_fields and the status_to_metric_field mappings for SumSessionField and CountUniqueSessionField, which will cause an AttributeError at runtime.

src/sentry/release_health/metrics_sessions_v2.py#L69-L77

class SessionStatus(Enum):
ABNORMAL = "abnormal"
CRASHED = "crashed"
ERRORED = "errored"
HEALTHY = "healthy"

src/sentry/release_health/metrics_sessions_v2.py#L268-L269

SessionStatus.ERRORED: MetricField(None, SessionMRI.ERRORED.value),
SessionStatus.UNHANDLED: MetricField(None, SessionMRI.UNHANDLED.value),

src/sentry/release_health/metrics_sessions_v2.py#L244-L245

self.status_to_metric_field[SessionStatus.ERRORED],
self.status_to_metric_field[SessionStatus.UNHANDLED],

Fix in Cursor Fix in Web

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