feat: Add integration for App Hangs V3#8117
Conversation
Instructions and example for changelogPlease add an entry to 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 |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ 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 |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit 6ec1b95. Configure here.
| !SentrySDKOverrides.Crash.disableUncaughtNSExceptionReporting.boolValue | ||
| #endif | ||
|
|
||
| options.experimental.appHangs.enableV3 = true |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit 6ec1b95. Configure here.
| } | ||
|
|
||
| func processHitch(duration: TimeInterval, isOngoing: Bool) { | ||
| hitchDurationCounter += duration |
There was a problem hiding this comment.
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.
c4039d4 to
e5b7c9b
Compare


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