File tree Expand file tree Collapse file tree 3 files changed +48
-3
lines changed Expand file tree Collapse file tree 3 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -63,11 +63,24 @@ def processor(event):
63
63
with _internal_exceptions ():
64
64
_set_user_info (request , event )
65
65
66
- # TODO: user info
66
+ with _internal_exceptions ():
67
+ _process_frames (event )
67
68
68
69
return processor
69
70
70
71
72
+ def _process_frames (event ):
73
+ for frame in event .iter_frames ():
74
+ if "in_app" in frame :
75
+ continue
76
+
77
+ module = frame .get ("module" )
78
+ if not module :
79
+ continue
80
+ if module == "django" or module .startswith ("django." ):
81
+ frame ["in_app" ] = False
82
+
83
+
71
84
def _got_request_exception (request = None , ** kwargs ):
72
85
capture_exception ()
73
86
Original file line number Diff line number Diff line change 10
10
except ImportError :
11
11
current_user = None
12
12
13
- from flask import request
13
+ from flask import current_app , request
14
14
from flask .signals import (
15
15
appcontext_pushed ,
16
16
appcontext_tearing_down ,
@@ -56,6 +56,26 @@ def _event_processor(event):
56
56
with _internal_exceptions ():
57
57
_set_user_info (event )
58
58
59
+ with _internal_exceptions ():
60
+ _process_frames (event )
61
+
62
+
63
+ def _process_frames (event ):
64
+ for frame in event .iter_frames ():
65
+ if "in_app" in frame :
66
+ continue
67
+ module = frame .get ("module" )
68
+ if not module :
69
+ continue
70
+
71
+ if module == "flask" or module .startswith ("flask." ):
72
+ frame ["in_app" ] = False
73
+ elif current_app and (
74
+ module .startswith ("%s." % current_app .import_name )
75
+ or module == current_app .import_name
76
+ ):
77
+ frame ["in_app" ] = True
78
+
59
79
60
80
class FlaskRequestExtractor (RequestExtractor ):
61
81
@property
Original file line number Diff line number Diff line change @@ -264,7 +264,7 @@ def frame_from_traceback(tb, with_locals=True):
264
264
abs_path = None
265
265
function = None
266
266
try :
267
- module = frame .f_globals ["__module__ " ]
267
+ module = frame .f_globals ["__name__ " ]
268
268
except Exception :
269
269
module = None
270
270
@@ -354,6 +354,18 @@ def __iter__(self):
354
354
def __len__ (self ):
355
355
return len (self ._data )
356
356
357
+ def iter_frames (self ):
358
+ stacktraces = []
359
+ if "stacktrace" in self :
360
+ stacktraces .append (self ["stacktrace" ])
361
+ if "exception" in self :
362
+ for exception in self ["exception" ].get ("values" ) or ():
363
+ if "stacktrace" in exception :
364
+ stacktraces .append (exception ["stacktrace" ])
365
+ for stacktrace in stacktraces :
366
+ for frame in stacktrace .get ("frames" ) or ():
367
+ yield frame
368
+
357
369
358
370
class SkipEvent (Exception ):
359
371
"""Risen from an event processor to indicate that the event should be
You can’t perform that action at this time.
0 commit comments