@@ -579,24 +579,41 @@ def to_string(value):
579
579
return repr (value )[1 :- 1 ]
580
580
581
581
582
- def iter_event_frames (event ):
582
+ def iter_event_stacktraces (event ):
583
583
# type: (Dict[str, Any]) -> Iterator[Dict[str, Any]]
584
- stacktraces = []
585
584
if "stacktrace" in event :
586
- stacktraces . append ( event ["stacktrace" ])
585
+ yield event ["stacktrace" ]
587
586
if "exception" in event :
588
587
for exception in event ["exception" ].get ("values" ) or ():
589
588
if "stacktrace" in exception :
590
- stacktraces .append (exception ["stacktrace" ])
591
- for stacktrace in stacktraces :
589
+ yield exception ["stacktrace" ]
590
+
591
+
592
+ def iter_event_frames (event ):
593
+ # type: (Dict[str, Any]) -> Iterator[Dict[str, Any]]
594
+ for stacktrace in iter_event_stacktraces (event ):
592
595
for frame in stacktrace .get ("frames" ) or ():
593
596
yield frame
594
597
595
598
596
599
def handle_in_app (event , in_app_exclude = None , in_app_include = None ):
597
600
# type: (Dict[str, Any], List, List) -> Dict[str, Any]
601
+ for stacktrace in iter_event_stacktraces (event ):
602
+ handle_in_app_impl (
603
+ stacktrace .get ("frames" ),
604
+ in_app_exclude = in_app_exclude ,
605
+ in_app_include = in_app_include ,
606
+ )
607
+
608
+ return event
609
+
610
+
611
+ def handle_in_app_impl (frames , in_app_exclude , in_app_include ):
612
+ if not frames :
613
+ return
614
+
598
615
any_in_app = False
599
- for frame in iter_event_frames ( event ) :
616
+ for frame in frames :
600
617
in_app = frame .get ("in_app" )
601
618
if in_app is not None :
602
619
if in_app :
@@ -606,18 +623,18 @@ def handle_in_app(event, in_app_exclude=None, in_app_include=None):
606
623
module = frame .get ("module" )
607
624
if not module :
608
625
continue
609
-
610
- if _module_in_set (module , in_app_exclude ):
611
- frame ["in_app" ] = False
612
- if _module_in_set (module , in_app_include ):
626
+ elif _module_in_set (module , in_app_include ):
613
627
frame ["in_app" ] = True
614
628
any_in_app = True
629
+ elif _module_in_set (module , in_app_exclude ):
630
+ frame ["in_app" ] = False
615
631
616
632
if not any_in_app :
617
- for frame in iter_event_frames (event ):
618
- frame ["in_app" ] = True
633
+ for frame in frames :
634
+ if frame .get ("in_app" ) is None :
635
+ frame ["in_app" ] = True
619
636
620
- return event
637
+ return frames
621
638
622
639
623
640
def exc_info_from_error (error ):
0 commit comments