1212
1313public class IncidentHandler {
1414 private final static SDKLogger LOGGER = new SDKLogger (IncidentHandler .class );
15+ private final static String TRACEO_PACKAGE = "com.traceo.sdk" ;
1516
1617 private final ClientOptions options ;
1718
@@ -34,7 +35,7 @@ public void catchException(Throwable throwable, String message, EventCallback<Tr
3435 return ;
3536 }
3637
37- TraceoIncident payload = processIncident (throwable , message );
38+ TraceoIncident payload = processIncident (throwable , message , options );
3839 if (callback != null ) {
3940 callback .run (payload );
4041 }
@@ -47,7 +48,7 @@ public void catchException(Throwable throwable, String message, EventCallback<Tr
4748 }
4849 }
4950
50- private static TraceoIncident processIncident (Throwable throwable , String customMessage ) {
51+ private static TraceoIncident processIncident (Throwable throwable , String customMessage , ClientOptions options ) {
5152 TraceoIncident traceoIncident = new TraceoIncident ();
5253
5354 String stacktrace = ThrowableUtils .stacktraceToString (throwable );
@@ -61,7 +62,7 @@ private static TraceoIncident processIncident(Throwable throwable, String custom
6162 traceoIncident .setMessage (throwable .getMessage ());
6263 }
6364
64- List <TraceoTrace > traces = getTraceList (throwable );
65+ List <TraceoTrace > traces = getTraceList (throwable , options );
6566 traceoIncident .setTraces (traces );
6667
6768 traceoIncident .setStack (stacktrace );
@@ -70,21 +71,36 @@ private static TraceoIncident processIncident(Throwable throwable, String custom
7071 return traceoIncident ;
7172 }
7273
73- private static List <TraceoTrace > getTraceList (Throwable throwable ) {
74+ private static List <TraceoTrace > getTraceList (Throwable throwable , ClientOptions options ) {
7475 List <TraceoTrace > traces = new ArrayList <>();
7576
76- for (StackTraceElement stackTraceElement : throwable .getStackTrace ()) {
77+ for (StackTraceElement element : throwable .getStackTrace ()) {
78+ if (element == null ) {
79+ continue ;
80+ }
81+
7782 TraceoTrace trace = new TraceoTrace ();
78- trace .setFunction (stackTraceElement .getMethodName ());
7983
80- String [] splitFilename = stackTraceElement .getFileName ().split ("\\ ." );
84+ String className = element .getClassName ();
85+ if (className .startsWith (TRACEO_PACKAGE )) {
86+ continue ;
87+ }
88+
89+ String [] splitFilename = element .getFileName ().split ("\\ ." );
8190 if (splitFilename .length > 1 ) {
8291 trace .setExtension (splitFilename [1 ]);
8392 }
8493
85- trace .setFilename (stackTraceElement .getFileName ());
86- trace .setLineNo (stackTraceElement .getLineNumber ());
87- trace .setAbsPath (stackTraceElement .getClassName ());
94+ if (!element .isNativeMethod ()) {
95+ trace .setLineNo (element .getLineNumber ());
96+ }
97+
98+ trace .setFilename (element .getFileName ());
99+ trace .setFunction (element .getMethodName ());
100+ trace .setAbsPath (element .getClassName ());
101+
102+ boolean isInternalTrace = options .getPackages ().stream ().anyMatch (className ::startsWith );
103+ trace .setInternal (isInternalTrace );
88104
89105 traces .add (trace );
90106 }
0 commit comments