Skip to content

Commit

Permalink
refactor wsgi request logging, so that we will have more information …
Browse files Browse the repository at this point in the history
…available (#492)
  • Loading branch information
Simon Davy committed Dec 4, 2019
1 parent f3c371c commit 10923a1
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 446 deletions.
10 changes: 3 additions & 7 deletions talisker/gunicorn.py
Expand Up @@ -116,13 +116,9 @@ def gunicorn_child_exit(server, worker):
def gunicorn_worker_exit(server, worker):
"""Logs any requests that are still in flight."""
now = time.time()
for env in talisker.wsgi.REQUESTS.values():
duration = now - env['start_time']
talisker.wsgi.log_response(
env,
duration=duration,
timeout=True,
)
for wsgi_request in talisker.wsgi.REQUESTS.values():
duration = now - wsgi_request.environ['start_time']
wsgi_request.log(duration, timeout=True)


class GunicornLogger(Logger):
Expand Down
9 changes: 5 additions & 4 deletions talisker/sentry.py
Expand Up @@ -53,7 +53,7 @@
'configure_testing',
'get_client',
'record_breadcrumb',
'report_wsgi_error',
'report_wsgi',
'set_client',
]

Expand Down Expand Up @@ -81,7 +81,7 @@ def record_breadcrumb(*args, **kwargs):
def record_log_breadcrumb(record):
pass

def report_wsgi_error(environ, msg=None, **kwargs):
def report_wsgi(environ, msg=None, **kwargs):
return

class TestSentryContext():
Expand Down Expand Up @@ -155,12 +155,13 @@ def processor(data):
})
raven.breadcrumbs.record(processor=processor)

def report_wsgi_error(environ, msg=None, **kwargs):
def report_wsgi(environ, msg=None, response_data=None, **kwargs):
"""Use raven to report error"""
sentry = get_client()
# reuse code from Sentry middleware, if a bit unpleasently
mw = raven.middleware.Sentry(None, sentry)
sentry.http_context(mw.get_http_context(environ))
http_context = mw.get_http_context(environ)
sentry.http_context(http_context)
if msg is None:
return sentry.captureException(**kwargs)
else:
Expand Down
2 changes: 1 addition & 1 deletion talisker/testing.py
Expand Up @@ -283,11 +283,11 @@ def __init__(self, name=None):
self.sentry_context = talisker.sentry.TestSentryContext(self.dsn)

def start(self):
Context.new()
self.old_statsd = talisker.statsd.get_client.raw_update(
self.statsd_client)
talisker.logs.add_talisker_handler(logging.NOTSET, self.handler)
self.sentry_context.start()
Context.new()

def stop(self):
logging.getLogger().handlers.remove(self.handler)
Expand Down

0 comments on commit 10923a1

Please sign in to comment.