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

Add "Is Foreground" to app tags #4559

Closed
aellett opened this issue Nov 20, 2024 · 4 comments · Fixed by #4561
Closed

Add "Is Foreground" to app tags #4559

aellett opened this issue Nov 20, 2024 · 4 comments · Fixed by #4561

Comments

@aellett
Copy link

aellett commented Nov 20, 2024

Problem Statement

I was comparing some events between our iOS and Android native apps recently, and I saw that our Android transactions had an automatic tag for App.In Foreground, but the iOS transactions didn't seem to have that. I looked around a little bit, but couldn't find the same tag; wondering if that could be surfaced in the cocoa sdk.

Looks like Android is using 7.15.0 of sentry.java.android and iOS is currently at 8.36.0 of sentry-cocoa.

Solution Brainstorm

No response

Are you willing to submit a PR?

No response

@brustolin
Copy link
Contributor

Hello @aellett, thanks for the suggestion.
We will discuss this in our internal meeting.

@philipphofmann
Copy link
Member

We have is_foreground in the app context, which we already attach to an event. We only need to ensure that it is attached for transactions as well.

// We don't want to attach debug meta and stacktraces for transactions and replays.
if (eventIsNotATransaction && eventIsNotReplay) {
BOOL shouldAttachStacktrace = alwaysAttachStacktrace || self.options.attachStacktrace
|| (nil != event.exceptions && [event.exceptions count] > 0);
BOOL threadsNotAttached = !(nil != event.threads && event.threads.count > 0);
if (!isCrashEvent && shouldAttachStacktrace && threadsNotAttached) {
event.threads = [self.threadInspector getCurrentThreads];
}
#if SENTRY_HAS_UIKIT
if (!isCrashEvent) {
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;
}
}

philipphofmann added a commit that referenced this issue Nov 21, 2024
The SDK already attaches the in_foreground to events, but it didn't for
transactions. This is fixed now.

Fixes GH-4559
@philipphofmann
Copy link
Member

PR is open: #4561

@philipphofmann
Copy link
Member

@aellett, FYI we are aware you'd like to also have this field for crashes, so we created an issue: #4563.

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

Successfully merging a pull request may close this issue.

3 participants