getsentry / getsentry/sentry

Expose session-based ANR / App Hang rate in sessions API

Open
#118,081 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

4. Low Metrics Product Area: Releases Waiting for: Product Owner
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() use uniqIf over the user set filtered by the abnormal_mechanism tag (anr_foreground, anr_background) — src/sentry/snuba/metrics/fields/snql.py
  • In Relay, abnormal_mechanism is attached only to s:sessions/user@none, not to the session counter c:sessions/session@none:
    • SessionSessionTags carries only status + common tags; SessionUserTags carries abnormal_mechanism (relay-server/src/metrics_extraction/sessions/types.rs)
    • In the abnormal branch of extract_session_metrics, the session counter is tagged session.status = "abnormal" with no mechanism (relay-server/src/metrics_extraction/sessions/mod.rs)
    • test_extract_session_metrics_abnormal asserts the session counter's tag keys are exactly ["release", "session.status"]
  • abnormal_mechanism is 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@ratio and e:sessions/session.foreground_anr_rate@ratio
  • Add sumIf-on-counter snql functions filtered by abnormal_mechanism (mirroring crashed_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,release and interval, on the same pipeline as crash-free sessions
  • Value matches a manual sessions{abnormal_mechanism in (anr_foreground, anr_background)} / total sessions computation
Notes
  • No historical backfill: session-based values accumulate only from the Relay deploy date
  • iOS App Hang rate reuses the same abnormal_mechanism path, so the change benefits both Android ANR and iOS App Hang

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.