From 427b48407545ec78242b5de5547d3f29fe35a4ae Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Tue, 21 Feb 2017 19:24:27 -0500 Subject: [PATCH] be forgiving in log api log message fields list --- awx/main/utils/formatters.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/awx/main/utils/formatters.py b/awx/main/utils/formatters.py index 65cb8186a7..68d0917985 100644 --- a/awx/main/utils/formatters.py +++ b/awx/main/utils/formatters.py @@ -102,13 +102,16 @@ class LogstashFormatter(LogstashFormatterVersion1): request = raw_data['python_objects']['request'] response = raw_data['python_objects']['response'] + # Note: All of the below keys may not be in the response "dict" + # For example, X-API-Query-Time and X-API-Query-Count will only + # exist if SQL_DEBUG is turned on in settings. headers = [ (float, 'X-API-Time'), # may end with an 's' "0.33s" (int, 'X-API-Query-Count'), (float, 'X-API-Query-Time'), # may also end with an 's' (str, 'X-API-Node'), ] - data_for_log['x_api'] = {k: convert_to_type(t, response[k]) for (t, k) in headers} + data_for_log['x_api'] = {k: convert_to_type(t, response[k]) for (t, k) in headers if k in response} data_for_log['request'] = { 'method': request.method,