Skip to content

Ensure app hangs have is_foreground true #5725

@philipphofmann

Description

@philipphofmann

Description

There might be a few edge cases for which the SentryANRTrackingIntegration captures app hang events for which is_foreground isn't true. The client sets this field here

#if SENTRY_HAS_UIKIT
if (!isFatalEvent && eventIsNotReplay) {
NSMutableDictionary *context =
[event.context mutableCopy] ?: [NSMutableDictionary dictionary];
if (context[@"app"] == nil
|| ([context[@"app"] isKindOfClass:NSDictionary.self]
&& context[@"app"][@"in_foreground"] == nil)) {
NSMutableDictionary *app =
[(NSDictionary *)context[@"app"] mutableCopy] ?: [NSMutableDictionary dictionary];
context[@"app"] = app;
UIApplicationState appState =
[SentryDependencyContainer sharedInstance].application.applicationState;
BOOL inForeground = appState == UIApplicationStateActive;
app[@"in_foreground"] = @(inForeground);
event.context = context;
}
}

The SentryANRTrackingIntegration could already set this field, because the SDK only reports app hangs when the app is in the foreground to ensure this field is always set. A customer reported that they get some fatal app hang events for which this field isn't set.

We fixed an issue with #5681 that led to wrongly reported app hangs when the app came back from the background, which should minimize the occurrence of the above-mentioned edge cases.

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions