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
ignore frames from frame collection logic #167
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -147,24 +147,43 @@ def iter_traceback_frames(tb): | |||||||||||||
while tb: | ||||||||||||||
# support for __traceback_hide__ which is used by a few libraries | ||||||||||||||
# to hide internal frames. | ||||||||||||||
f_locals = getattr(tb.tb_frame, 'f_locals', {}) | ||||||||||||||
frame = tb.tb_frame | ||||||||||||||
f_locals = getattr(frame, 'f_locals', {}) | ||||||||||||||
if not _getitem_from_frame(f_locals, '__traceback_hide__'): | ||||||||||||||
yield tb.tb_frame, getattr(tb, 'tb_lineno', None) | ||||||||||||||
yield frame, getattr(tb, 'tb_lineno', None) | ||||||||||||||
tb = tb.tb_next | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def iter_stack_frames(frames=None, skip=0): | ||||||||||||||
def iter_stack_frames(frames=None, skip=0, skip_top_modules=()): | ||||||||||||||
""" | ||||||||||||||
Given an optional list of frames (defaults to current stack), | ||||||||||||||
iterates over all frames that do not contain the ``__traceback_hide__`` | ||||||||||||||
local variable. | ||||||||||||||
|
||||||||||||||
Frames can be skipped by either providing a number, or a tuple | ||||||||||||||
of module names. If the module of a frame matches one of the names | ||||||||||||||
(using `.startswith`, that frame will be skipped. This matching will only | ||||||||||||||
be done until the first frame doesn't match. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i know you are doing this in a generic way, but for now you are only using it for the elasticapm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Glad you asked :D I actually intend to filter more than just Another argument for not filtering out all frames that match is that this should only be used to cut away the top frames of the stack trace that are introduced by stack collection itself. If you call into any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that makes perfect sense. i am wiser now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there it is: apm-agent-python/elasticapm/base.py Lines 132 to 137 in 46e59e6
|
||||||||||||||
|
||||||||||||||
This is useful to filter out frames that are caused by frame collection | ||||||||||||||
itself. | ||||||||||||||
|
||||||||||||||
:param frames: a list of frames, or None | ||||||||||||||
:param skip: number of frames to skip from the beginning | ||||||||||||||
:param skip_top_modules: tuple of strings | ||||||||||||||
|
||||||||||||||
""" | ||||||||||||||
if not frames: | ||||||||||||||
frame = inspect.currentframe().f_back | ||||||||||||||
frames = _walk_stack(frame) | ||||||||||||||
stop_ignoring = False | ||||||||||||||
for i, frame in enumerate(frames): | ||||||||||||||
if i < skip: | ||||||||||||||
continue | ||||||||||||||
f_globals = getattr(frame, 'f_globals', {}) | ||||||||||||||
if not stop_ignoring and f_globals.get('__name__', '').startswith(skip_top_modules): | ||||||||||||||
continue | ||||||||||||||
stop_ignoring = True | ||||||||||||||
f_locals = getattr(frame, 'f_locals', {}) | ||||||||||||||
if not _getitem_from_frame(f_locals, '__traceback_hide__'): | ||||||||||||||
yield frame, frame.f_lineno | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens with
contextlib
, don't we want to filter it out anymore?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a relic from the olden days. We don't use
contextlib
anywhere in the code base