Skip to content

feat: Add integration for App Hangs V3#8117

Draft
philprime wants to merge 3 commits into
mainfrom
philprime/app-hangs-v3-bootstrap
Draft

feat: Add integration for App Hangs V3#8117
philprime wants to merge 3 commits into
mainfrom
philprime/app-hangs-v3-bootstrap

Conversation

@philprime

@philprime philprime commented Jun 18, 2026

Copy link
Copy Markdown
Member

Proof-of-concept for an App Hang integration based on Run Loops

Closes #8118

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor
Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- Add integration for App Hangs V3 ([#8117](https://github.com/getsentry/sentry-cocoa/pull/8117))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against e5b7c9b

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6ec1b95. Configure here.

!SentrySDKOverrides.Crash.disableUncaughtNSExceptionReporting.boolValue
#endif

options.experimental.appHangs.enableV3 = true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

V3 ignores sample hang gates

Medium Severity

experimental.appHangs.enableV3 is hard-coded to true, so App Hang V3 stays on when legacy app hang tracking is turned off for benchmarking or via --io.sentry.app-hangs.disable-tracking, unlike enableAppHangTracking on the line above.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6ec1b95. Configure here.

!SentrySDKOverrides.Crash.disableUncaughtNSExceptionReporting.boolValue
#endif

options.experimental.appHangs.enableV3 = true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sample enables dual hang trackers

Medium Severity

Turning on App Hang V3 here leaves enableAppHangTracking enabled in the normal sample path, so both SentryHangTrackerIntegrationObjC and SentryHangTrackingV3Integration install and can each emit fatal hang events for the same stall.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6ec1b95. Configure here.

}

func processHitch(duration: TimeInterval, isOngoing: Bool) {
hitchDurationCounter += duration

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The hitchDurationCounter incorrectly accumulates a cumulative duration value on each callback, leading to a wildly inflated total hang duration.
Severity: HIGH

Suggested Fix

The hitchDurationCounter should not be incremented when isOngoing is true. The duration should only be recorded from the final callback when isOngoing is false, as that duration value already represents the total hang time. Alternatively, calculate and add an incremental delta within processHitch instead of the cumulative duration.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: Sources/Swift/Integrations/HangTracking/AppHangDetection.swift#L56

Potential issue: The `processHitch` function is called repeatedly during an ongoing
hang. On each call, it adds the `duration` argument to `hitchDurationCounter`. However,
the `duration` passed is the total elapsed time since the hang started, not an
incremental delta. This causes the counter to accumulate an arithmetic series of
cumulative values, resulting in a significantly overestimated hang duration. For
example, a 2-second hang could be miscalculated as an 81-second hang. This leads to
hangs being reported incorrectly when they are below the threshold and sending
inaccurate duration data.

Did we get this right? 👍 / 👎 to inform future reviews.

Merge sampled stacktraces from hang detection into a
flamegraph tree with parentIndex and sampleCount per frame.
Send as a warning-level event with debug metadata for
server-side symbolication.
@philprime philprime force-pushed the philprime/app-hangs-v3-bootstrap branch from c4039d4 to e5b7c9b Compare June 22, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add integration for App Hangs V3

1 participant