--- a/src/pyams_apm/tween.py Wed Feb 06 09:23:14 2019 +0100
+++ b/src/pyams_apm/tween.py Mon Nov 25 13:39:35 2019 +0100
@@ -10,7 +10,11 @@
# FOR A PARTICULAR PURPOSE.
#
-__docformat__ = 'restructuredtext'
+"""PyAMS_apm.tween module
+
+This module provides a custom tween which is used to integrate the Pyramid application
+with APM, sending requests frames to the APM server.
+"""
import sys
@@ -21,8 +25,11 @@
from pyramid.compat import reraise
from pyramid.settings import asbool
+__docformat__ = 'restructuredtext'
+
def list_from_setting(config, setting):
+ """Split configuration setting"""
value = config.get(setting)
if not value:
return None
@@ -30,6 +37,7 @@
def get_data_from_request(request):
+ """Extract main APM data from request properties"""
data = {
"headers": dict(**request.headers),
"method": request.method,
@@ -46,6 +54,7 @@
def get_data_from_response(response):
+ """Extract APM data from response properties"""
data = {"status_code": response.status_int}
if response.headers:
data["headers"] = {
@@ -55,7 +64,7 @@
return data
-class elastic_apm_tween_factory(object):
+class elastic_apm_tween_factory: # pylint: disable=invalid-name
"""Elasticsearch APM tween factory"""
def __init__(self, handler, registry):
@@ -89,7 +98,7 @@
transaction_result = response.status[0] + "xx"
elasticapm.set_context(lambda: get_data_from_response(response), "response")
return response
- except Exception:
+ except Exception: # pylint: disable=broad-except
transaction_result = '5xx'
self.client.capture_exception(
context={
@@ -107,6 +116,7 @@
view_name = ''
transaction_name = request.matched_route.pattern if request.matched_route else view_name
# prepend request method
- transaction_name = " ".join((request.method, transaction_name)) if transaction_name else ""
+ transaction_name = " ".join((request.method, transaction_name)) \
+ if transaction_name else ""
elasticapm.set_context(lambda: get_data_from_request(request), "request")
self.client.end_transaction(transaction_name, transaction_result)