Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set in_foreground to true for watchdog terminations #4765

Open
philipphofmann opened this issue Jan 29, 2025 · 0 comments
Open

Set in_foreground to true for watchdog terminations #4765

philipphofmann opened this issue Jan 29, 2025 · 0 comments

Comments

@philipphofmann
Copy link
Member

Description

The SentryClient doesn't set the in_foreground to true, because watchdog termination events are crash events.

#if SENTRY_HAS_UIKIT
if (!isCrashEvent && 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;
}
}
#endif

Instead, the SentryWatchdogTerminationTracker could already set the field to true, as we only report watchdog terminations, we only report them when the app is in foreground.

SentryException *exception =
[[SentryException alloc] initWithValue:SentryWatchdogTerminationExceptionValue
type:SentryWatchdogTerminationExceptionType];
SentryMechanism *mechanism =
[[SentryMechanism alloc] initWithType:SentryWatchdogTerminationMechanismType];
mechanism.handled = @(NO);
exception.mechanism = mechanism;
event.exceptions = @[ exception ];
// We don't need to update the releaseName of the event to the previous app state as we
// assume it's not an OOM when the releaseName changed between app starts.
[SentrySDK captureCrashEvent:event];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Discussion
Development

No branches or pull requests

1 participant