Skip to content

Commit

Permalink
Add some error handling around frame processing (elastic#837)
Browse files Browse the repository at this point in the history
* Add some error handling around frame processing

See https://discuss.elastic.co/t/python-agent-raise-valueerror/233263

* Add a log to make sure the user doesn't wonder where the frames are

* Use `break` instead of `continue`

* Add to changelog
  • Loading branch information
basepi authored and romulorosa committed Oct 15, 2020
1 parent 8e4dce1 commit 3b9cd09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ endif::[]
* capture number of affected rows for INSERT/UPDATE/DELETE SQL queries {pull}614[#614]
* Added instrumentation for AsyncElasticsearch {pull}843[#843]
[float]
===== Bug fixes
* Added error handling around frame processing in Django {pull}837[#837]
[[release-notes-5.x]]
=== Python Agent version 5.x
Expand Down
10 changes: 9 additions & 1 deletion elasticapm/contrib/django/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import logging

from django.template.base import Node

from elasticapm.utils.stacks import get_frame_info
Expand All @@ -51,7 +53,13 @@ def iterate_with_template_sources(
locals_processor_func=None,
):
template = None
for frame, lineno in frames:
for f in frames:
try:
frame, lineno = f
except ValueError:
# TODO how can we possibly get anything besides a (frame, lineno) tuple here???
logging.getLogger("elasticapm").error("Malformed list of frames. Frames may be missing in Kibana.")
break
f_code = getattr(frame, "f_code", None)
if f_code:
function_name = frame.f_code.co_name
Expand Down

0 comments on commit 3b9cd09

Please sign in to comment.