Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Wouter van Bommel committed Sep 6, 2021
2 parents 2ccd352 + 8864e37 commit 97d2364
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:

jobs:
build:
name: "Project tests via tox"
services:
postgres:
image: postgres
Expand All @@ -33,6 +34,7 @@ jobs:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
sudo apt update
cat dependencies.txt | xargs sudo apt install -y
python -m pip install --upgrade pip
pip install tox tox-gh-actions
Expand Down
8 changes: 6 additions & 2 deletions talisker/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,21 @@ def finish_request(self, timeout=False):
# c) manual debugging

if talisker.sentry.enabled:
view_or_path = metadata.get('view', metadata['path'])
soft_timeout = Context.soft_timeout
try:
if self.exc_info:
self.send_sentry(metadata)
elif Context.debug:
self.send_sentry(
metadata,
msg='Debug: {}'.format(metadata['path']),
msg='Debug: {}'.format(view_or_path),
level='debug',
)
elif soft_timeout > 0 and response_latency > soft_timeout:
self.send_sentry(
metadata,
msg='Soft Timeout: {}'.format(metadata['path']),
msg='Soft Timeout: {}'.format(view_or_path),
level='warning',
extra={
'start_response_latency': response_latency,
Expand Down Expand Up @@ -518,6 +519,9 @@ def send_sentry(self, metadata, msg=None, data=None, **kwargs):
data = {}
if 'SENTRY_ID' in self.environ:
data['event_id'] = self.environ['SENTRY_ID']
view_name = metadata.get('view')
if view_name and 'transaction' not in data:
data['transaction'] = view_name
# sentry displays these specific fields in a different way
http_context = {
'url': get_current_url(self.environ),
Expand Down
12 changes: 12 additions & 0 deletions tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ def test_wsgi_request_soft_explicit(run_wsgi, context):
assert msg['extra']['soft_timeout'] == 100


@pytest.mark.skipif(not talisker.sentry.enabled, reason='need raven installed')
def test_wsgi_request_soft_explicit_viewname(run_wsgi, context):
talisker.Context.soft_timeout = 100
run_wsgi(duration=2, headers=[('X-View-Name', 'viewname')])
msg = context.sentry[0]
assert msg['message'] == 'Soft Timeout: viewname'
assert msg['level'] == 'warning'
assert msg['transaction'] == 'viewname'
assert msg['extra']['start_response_latency'] == 2000
assert msg['extra']['soft_timeout'] == 100


def test_wsgi_request_wrap_response(run_wsgi, context):
headers, body = run_wsgi(body=[b'output', b' ', b'here'])
output = b''.join(body)
Expand Down

0 comments on commit 97d2364

Please sign in to comment.