Expose session-based ANR / App Hang rate in sessions API
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 44.8k
- Forks
- 4.9k
- Avg merge
- 21h 23m
- Merged PRs (30d)
- 607
Description
Sessions API exposes ANR / App Hang rate only as a user-based metric (anr_rate(), foreground_anr_rate()). There is no session-based equivalent, so teams defining mobile SLOs on a session denominator must mix session-based crash metrics with user-based ANR metrics.
Current behavior
anr_rate()/foreground_anr_rate()useuniqIfover the user set filtered by theabnormal_mechanismtag (anr_foreground,anr_background) —src/sentry/snuba/metrics/fields/snql.py- In Relay,
abnormal_mechanismis attached only tos:sessions/user@none, not to the session counterc:sessions/session@none:SessionSessionTagscarries onlystatus+ common tags;SessionUserTagscarriesabnormal_mechanism(relay-server/src/metrics_extraction/sessions/types.rs)- In the abnormal branch of
extract_session_metrics, the session counter is taggedsession.status = "abnormal"with no mechanism (relay-server/src/metrics_extraction/sessions/mod.rs) test_extract_session_metrics_abnormalasserts the session counter's tag keys are exactly["release", "session.status"]
abnormal_mechanismis not a filterable/groupable dimension on sessions in the sessions or metrics API today
Proposed change
Phase 1 — Relay (prerequisite): Add abnormal_mechanism to SessionSessionTags and populate it in the abnormal branch of extract_session_metrics. Low cardinality (anr_foreground, anr_background). No SDK change required — the SDK already sends the mechanism on the session payload; Relay is not propagating it to the counter metric.
Phase 2 — Sentry server (after Relay):
- Register new MRIs
e:sessions/session.anr_rate@ratioande:sessions/session.foreground_anr_rate@ratio - Add
sumIf-on-counter snql functions filtered byabnormal_mechanism(mirroringcrashed_sessions()) - Expose session-based fields in the sessions API (e.g.
anr_rate(session)/foreground_anr_rate(session); naming TBD)
Acceptance criteria
- Sessions API returns a session-based ANR rate, queryable with
groupBy=project,releaseandinterval, on the same pipeline as crash-free sessions - Value matches a manual
sessions{abnormal_mechanism in (anr_foreground, anr_background)} / total sessionscomputation
Notes
- No historical backfill: session-based values accumulate only from the Relay deploy date
- iOS App Hang rate reuses the same
abnormal_mechanismpath, so the change benefits both Android ANR and iOS App Hang
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in relay-server/src/metrics_extraction/sessions/types.rs and relay-server/src/metrics_extraction/sessions/mod.rs, including test_extract_session_metrics_abnormal, to trace session counter tags. Then inspect src/sentry/snuba/metrics/fields/snql.py and the sessions API metric registration. Done means the API exposes session-based ANR and foreground App Hang rates whose grouped values match the stated manual session calculation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- api, backend-api-design, observability-sre
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100