Skip to content
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ namespace:
package and put it into the metadata of every transaction.
* `elasticapm.transactions_ignore_patterns`: Whitespace separated list of
ignore patterns.
* `elasticapm.transaction_sample_rate`: Transaction sample rate
2 changes: 1 addition & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ py==1.10.0
pycodestyle==2.7.0
pyflakes==2.3.1
pyparsing==2.4.7
pyramid==2.0
pyramid==1.8.0
pytest-cache==1.0
pytest-cov==2.11.1
pytest-flake8==1.0.7
Expand Down
9 changes: 6 additions & 3 deletions src/pyramid_elasticapm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pkg_resources
from elasticapm.utils import compat, get_url_dict
from pyramid.events import ApplicationCreated, subscriber
from pyramid.util import reraise
from pyramid._compat import reraise


def includeme(config):
Expand Down Expand Up @@ -37,6 +37,7 @@ def __init__(self, handler, registry):
'SERVER_URL': settings['elasticapm.server_url'],
'SECRET_TOKEN': settings['elasticapm.secret_token'],
'ENVIRONMENT': settings['elasticapm.environment'],
'TRANSACTION_SAMPLE_RATE': settings['elasticapm.transaction_sample_rate'],
}
if settings.get('elasticapm.transactions_ignore_patterns', ''):
config['TRANSACTIONS_IGNORE_PATTERNS'] = settings[
Expand Down Expand Up @@ -67,6 +68,8 @@ def __init__(self, handler, registry):

def __call__(self, request):
self.client.begin_transaction('request')
transaction_result = ""
response = None
try:
response = self.handler(request)
transaction_result = response.status[0] + 'xx'
Expand Down Expand Up @@ -109,7 +112,7 @@ def get_data_from_request(self, request, response):
# remove Cookie header since the same data is in
# request["cookies"] as well
data['headers'].pop('Cookie', None)
if response.status_code >= 400:
if response is not None and response.status_code >= 400:
data['body'] = request.body
data['response_body'] = response.body
return data
Expand All @@ -121,7 +124,7 @@ def get_data_from_response(self, response):
if response.headers:
data['headers'] = {
key: ';'.join(response.headers.getall(key))
for key in compat.iterkeys(response.headers)
for key in response.headers.iterkeys()
}
return data

Expand Down
1 change: 1 addition & 0 deletions src/pyramid_elasticapm/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def make_app(server_url):
'elasticapm.environment': 'testing',
'elasticapm.service_distribution': 'pytest',
'elasticapm.transactions_ignore_patterns': 'foo bar baz',
'elasticapm.transaction_sample_rate': 1.0,
}
config = Configurator(settings=settings)
config.include('pyramid_elasticapm')
Expand Down