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 @@ -9,6 +9,7 @@

### Fixes

- Save app context information (release name, dist, environment) on app hang events before saving to disk to prevent incorrect version information when an app hang turns fatal (#6998)
- Disabled automatic session tracking in system extensions to prevent extension blocking and unwanted dock icon behavior (#6962) (#6962)
- Fixes crash when null values are passed to `UIApplication sendAction:to:from:forEvent:` (#6970)

Expand Down
19 changes: 19 additions & 0 deletions Sources/Sentry/SentryANRTrackingIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,31 @@ - (void)anrDetectedWithType:(enum SentryANRType)type
[scope applyToEvent:event maxBreadcrumb:options.maxBreadcrumbs];
}

[self applyOptions:options toEvent:event];

[self.fileManager storeAppHangEvent:event];
#else
[SentrySDK captureEvent:event];
#endif
}

- (void)applyOptions:(SentryOptions *)options toEvent:(SentryEvent *)event
{
// We need to apply the release name now, if the app hang turns into a fatal one
// we might en up submitting a wrong version.
event.releaseName = options.releaseName;

// Only apply dist if it wasn't set by the Scope previously
if (event.dist == nil && options.dist != nil) {
event.dist = options.dist;
}

// Only apply environment if it wasn't set by the Scope previously
if (event.environment == nil && options.environment != nil) {
event.environment = options.environment;
}
}

- (void)anrStoppedWithResult:(SentryANRStoppedResult *_Nullable)result
{
#if SENTRY_HAS_UIKIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SentryANRTrackingIntegrationTests: SentrySDKIntegrationTestsBase {
options.dsn = SentryANRTrackingIntegrationTests.dsn
options.enableAppHangTracking = true
options.appHangTimeoutInterval = 4.5
options.releaseName = "release-name-test"

debugImageProvider.debugImages = [TestData.debugImage]
}
Expand Down Expand Up @@ -364,6 +365,24 @@ class SentryANRTrackingIntegrationTests: SentrySDKIntegrationTestsBase {
}

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
func testV2_ANRDetected_StoresAppHangEventInFile() throws {
// Arrange
options.releaseName = "my-release-name-test"
options.environment = "testing-environment"
options.dist = "adhoc"
setUpThreadInspector()
givenInitializedTracker()

// Act
Dynamic(sut).anrDetectedWithType(SentryANRType.nonFullyBlocking)

// Assert
let event = try XCTUnwrap(SentrySDKInternal.currentHub().client()?.fileManager.readAppHangEvent())
XCTAssertEqual(event.releaseName, "my-release-name-test")
XCTAssertEqual(event.environment, "testing-environment")
XCTAssertEqual(event.dist, "adhoc")
}

func testV2_ANRDetected_DoesNotCaptureEvent() throws {
// Arrange
setUpThreadInspector()
Expand Down Expand Up @@ -424,6 +443,8 @@ class SentryANRTrackingIntegrationTests: SentrySDKIntegrationTestsBase {
// Ensure we capture the event with an empty scope
XCTAssertEqual(scope?.tags.count, 0)
XCTAssertEqual(scope?.breadcrumbs().count, 0)

XCTAssertEqual(event?.releaseName, "release-name-test")
}
}

Expand Down Expand Up @@ -472,6 +493,8 @@ class SentryANRTrackingIntegrationTests: SentrySDKIntegrationTestsBase {
// Ensure we capture the event with an empty scope
XCTAssertEqual(scope?.tags.count, 0)
XCTAssertEqual(scope?.breadcrumbs().count, 0)

XCTAssertEqual(event?.releaseName, "release-name-test")
}
}

Expand Down Expand Up @@ -529,6 +552,8 @@ class SentryANRTrackingIntegrationTests: SentrySDKIntegrationTestsBase {
let breadcrumbs = try XCTUnwrap(event?.breadcrumbs)
XCTAssertEqual(1, breadcrumbs.count)
XCTAssertEqual("crumb", breadcrumbs.first?.message)

XCTAssertEqual(event?.releaseName, "release-name-test")
}
}

Expand Down Expand Up @@ -566,6 +591,8 @@ class SentryANRTrackingIntegrationTests: SentrySDKIntegrationTestsBase {
let breadcrumbs = try XCTUnwrap(event?.breadcrumbs)
XCTAssertEqual(1, breadcrumbs.count)
XCTAssertEqual("crumb", breadcrumbs.first?.message)

XCTAssertEqual(event?.releaseName, "release-name-test")
}
}

Expand Down Expand Up @@ -618,6 +645,8 @@ class SentryANRTrackingIntegrationTests: SentrySDKIntegrationTestsBase {
XCTAssertEqual("distinct", actualSession.distinctId)
XCTAssertEqual(fixture.currentDate.date(), actualSession.timestamp)
XCTAssertEqual("anr_foreground", actualSession.abnormalMechanism)

XCTAssertEqual(event.releaseName, "release-name-test")
}

func testV2_ANRDetected_StopNotCalledAndCrashed_SendsNormalAppHangEvent() throws {
Expand Down
Loading