summaryrefslogtreecommitdiff
path: root/raven/contrib
diff options
context:
space:
mode:
authorDavid Cramer <dcramer@gmail.com>2017-02-15 13:25:08 -0800
committerDavid Cramer <dcramer@gmail.com>2017-02-15 13:41:09 -0800
commitf901ad591299beee330e351e02d273303c176b35 (patch)
treec4d327b493e85a671a0eefbb952f6fe91254b603 /raven/contrib
parent632c343470a668ef08dd943e5b22489b469444f5 (diff)
downloadraven-f901ad591299beee330e351e02d273303c176b35.tar.gz
[django] improve various request behaviorref/tastypie-tests
- expand tests to cover basic tastypie - correct leaking of request local in middleware - improve django test fundamentals
Diffstat (limited to 'raven/contrib')
-rw-r--r--raven/contrib/django/middleware/__init__.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/raven/contrib/django/middleware/__init__.py b/raven/contrib/django/middleware/__init__.py
index b4c6c20..5d3f024 100644
--- a/raven/contrib/django/middleware/__init__.py
+++ b/raven/contrib/django/middleware/__init__.py
@@ -81,7 +81,16 @@ class SentryMiddleware(MiddlewareMixin):
def process_request(self, request):
self._txid = None
+
SentryMiddleware.thread.request = request
+ # we utilize request_finished as the exception gets reported
+ # *after* process_response is executed, and thus clearing the
+ # transaction there would leave it empty
+ # XXX(dcramer): weakref's cause a threading issue in certain
+ # versions of Django (e.g. 1.6). While they'd be ideal, we're under
+ # the assumption that Django will always call our function except
+ # in the situation of a process or thread dying.
+ request_finished.connect(self.request_finished, weak=False)
def process_view(self, request, func, args, kwargs):
from raven.contrib.django.models import client
@@ -91,16 +100,7 @@ class SentryMiddleware(MiddlewareMixin):
client.get_transaction_from_request(request)
)
except Exception as exc:
- client.error_logger.exception(repr(exc))
- else:
- # we utilize request_finished as the exception gets reported
- # *after* process_response is executed, and thus clearing the
- # transaction there would leave it empty
- # XXX(dcramer): weakref's cause a threading issue in certain
- # versions of Django (e.g. 1.6). While they'd be ideal, we're under
- # the assumption that Django will always call our function except
- # in the situation of a process or thread dying.
- request_finished.connect(self.request_finished, weak=False)
+ client.error_logger.exception(repr(exc), extra={'request': request})
return None
@@ -111,6 +111,8 @@ class SentryMiddleware(MiddlewareMixin):
client.transaction.pop(self._txid)
self._txid = None
+ SentryMiddleware.thread.request = None
+
request_finished.disconnect(self.request_finished)