Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Detect development builds via provisioning profile and debugger attachment (#7702)
- Ensure app hangs have foreground app context (#7801)

## 9.10.0

Expand Down
10 changes: 10 additions & 0 deletions Sources/Swift/Integrations/SentryHangTrackingIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ final class SentryHangTrackingIntegration<Dependencies: HangTrackingIntegrationS
mechanism.data = [sentryANRMechanismDataAppHangDuration: appHangDurationInfo]
let scope = SentrySDKInternal.currentHub().scope
scope.applyTo(event: event, maxBreadcrumbs: options.maxBreadcrumbs)
addAppState(to: event)
apply(options: SentrySDK.startOption, toEvent: event)
fileManager.storeAppHang(event)
#else
Expand Down Expand Up @@ -204,6 +205,15 @@ final class SentryHangTrackingIntegration<Dependencies: HangTrackingIntegrationS
}

#if (os(iOS) || os(tvOS) || os(visionOS)) && !SENTRY_NO_UI_FRAMEWORK
private func addAppState(to event: Event) {
var context = event.context ?? [:]
var appContext = context["app"] ?? [:]
appContext["in_foreground"] = true
appContext["is_active"] = true
context["app"] = appContext
event.context = context
}

private func captureStoredAppHangEvent() {
dispatchQueueWrapper.dispatchAsync { [weak self] in
guard let self else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ class SentryHangTrackingIntegrationTests: SentrySDKIntegrationTestsBase {
XCTAssertEqual(event.releaseName, "my-release-name-test")
XCTAssertEqual(event.environment, "testing-environment")
XCTAssertEqual(event.dist, "adhoc")
let appContext = try XCTUnwrap(event.context?["app"] as? [String: Any])
XCTAssertEqual(true, appContext["in_foreground"] as? Bool)
XCTAssertEqual(true, appContext["is_active"] as? Bool)
}

func testV2_ANRDetected_DoesNotCaptureEvent() throws {
Expand Down
Loading