Skip to content
Merged
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 @@ -12,6 +12,7 @@
- Keep replayType as `buffer` for Session Replay triggered by an error (#7804)
- Fix race condition in scope observer notifications causing EXC_BAD_ACCESS during cold launch (#7807)
- Unsubscribe to system event during background to avoid reporting breadcrumbs with wrong timestamps on return to foreground (#7702)
- Add foreground state to app context in app hang events (#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