Skip to content

Commit 72d5644

Browse files
committed
extract inner inApp check into a reusable static method
1 parent 00c5839 commit 72d5644

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/internal/tombstone/TombstoneParser.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import androidx.annotation.NonNull;
44
import io.sentry.SentryEvent;
55
import io.sentry.SentryLevel;
6+
import io.sentry.SentryStackTraceFactory;
67
import io.sentry.android.core.internal.util.NativeEventUtils;
78
import io.sentry.protocol.DebugImage;
89
import io.sentry.protocol.DebugMeta;
@@ -22,6 +23,7 @@
2223
import java.util.Map;
2324
import java.util.Objects;
2425
import org.jetbrains.annotations.NotNull;
26+
import org.jetbrains.annotations.Nullable;
2527

2628
public class TombstoneParser implements Closeable {
2729

@@ -116,23 +118,11 @@ private SentryStackTrace createStackTrace(@NonNull final TombstoneProtos.Thread
116118
stackFrame.setFunction(frame.getFunctionName());
117119
stackFrame.setInstructionAddr(formatHex(frame.getPc()));
118120

119-
// TODO: is this the right order?
120-
boolean inApp = false;
121-
for (String inclusion : this.inAppIncludes) {
122-
if (frame.getFunctionName().startsWith(inclusion)) {
123-
inApp = true;
124-
break;
125-
}
126-
}
127-
128-
for (String exclusion : this.inAppExcludes) {
129-
if (frame.getFunctionName().startsWith(exclusion)) {
130-
inApp = false;
131-
break;
132-
}
133-
}
121+
@Nullable
122+
Boolean inApp =
123+
SentryStackTraceFactory.isInApp(frame.getFunctionName(), inAppIncludes, inAppExcludes);
134124

135-
inApp = inApp || frame.getFileName().startsWith(this.nativeLibraryDir);
125+
inApp = (inApp != null && inApp) || frame.getFileName().startsWith(this.nativeLibraryDir);
136126

137127
stackFrame.setInApp(inApp);
138128
frames.add(0, stackFrame);

sentry/api/sentry.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,6 +3974,7 @@ public final class io/sentry/SentryStackTraceFactory {
39743974
public fun getInAppCallStack ()Ljava/util/List;
39753975
public fun getStackFrames ([Ljava/lang/StackTraceElement;Z)Ljava/util/List;
39763976
public fun isInApp (Ljava/lang/String;)Ljava/lang/Boolean;
3977+
public static fun isInApp (Ljava/lang/String;Ljava/util/List;Ljava/util/List;)Ljava/lang/Boolean;
39773978
}
39783979

39793980
public final class io/sentry/SentryThreadFactory {

sentry/src/main/java/io/sentry/SentryStackTraceFactory.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,29 @@ public List<SentryStackFrame> getStackFrames(
7272
}
7373

7474
/**
75-
* Returns if the className is InApp or not.
75+
* Provides the logic to decide whether a className is part of the includes or excludes list of
76+
* strings. The bias is towards includes, meaning once a className starts with a prefix in the
77+
* includes list, it immediately returns, ignoring any counter entry in excludes.
7678
*
7779
* @param className the className
7880
* @return true if it is or false otherwise
7981
*/
8082
@Nullable
81-
public Boolean isInApp(final @Nullable String className) {
83+
public static Boolean isInApp(
84+
final @Nullable String className,
85+
final @NotNull List<String> includes,
86+
final @NotNull List<String> excludes) {
8287
if (className == null || className.isEmpty()) {
8388
return true;
8489
}
8590

86-
final List<String> inAppIncludes = options.getInAppIncludes();
87-
for (String include : inAppIncludes) {
91+
for (String include : includes) {
8892
if (className.startsWith(include)) {
8993
return true;
9094
}
9195
}
9296

93-
final List<String> inAppExcludes = options.getInAppExcludes();
94-
for (String exclude : inAppExcludes) {
97+
for (String exclude : excludes) {
9598
if (className.startsWith(exclude)) {
9699
return false;
97100
}
@@ -100,6 +103,17 @@ public Boolean isInApp(final @Nullable String className) {
100103
return null;
101104
}
102105

106+
/**
107+
* Returns if the className is InApp or not.
108+
*
109+
* @param className the className
110+
* @return true if it is or false otherwise
111+
*/
112+
@Nullable
113+
public Boolean isInApp(final @Nullable String className) {
114+
return isInApp(className, options.getInAppIncludes(), options.getInAppExcludes());
115+
}
116+
103117
/**
104118
* Returns the call stack leading to the exception, including in-app frames and excluding sentry
105119
* and system frames.

0 commit comments

Comments
 (0)