From 3b9cd0967da914a0c401039cb3f63f6cd7c76e14 Mon Sep 17 00:00:00 2001 From: Colton Myers Date: Tue, 2 Jun 2020 18:25:52 -0600 Subject: [PATCH] Add some error handling around frame processing (#837) * 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 --- CHANGELOG.asciidoc | 5 +++++ elasticapm/contrib/django/utils.py | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 37eb9b533..cd755fd49 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -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 diff --git a/elasticapm/contrib/django/utils.py b/elasticapm/contrib/django/utils.py index 076194774..db09fb0d0 100644 --- a/elasticapm/contrib/django/utils.py +++ b/elasticapm/contrib/django/utils.py @@ -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 @@ -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