in elasticapm/utils/stacks.py [0:0]
def get_culprit(frames, include_paths=None, exclude_paths=None):
# We iterate through each frame looking for a deterministic culprit
# When one is found, we mark it as last "best guess" (best_guess) and then
# check it against ``exclude_paths``. If it isnt listed, then we
# use this option. If nothing is found, we use the "best guess".
if include_paths is None:
include_paths = []
if exclude_paths is None:
exclude_paths = []
best_guess = None
culprit = None
for frame in frames:
try:
culprit = ".".join((f or "<unknown>" for f in [frame.get("module"), frame.get("function")]))
except KeyError:
continue
if any((culprit.startswith(k) for k in include_paths)):
if not (best_guess and any((culprit.startswith(k) for k in exclude_paths))):
best_guess = culprit
elif best_guess:
break
# Return either the best guess or the last frames call
return best_guess or culprit