Commits

Stefano Rivera  committed 945673c

Add support for sending raven messages containing a full traceback

  • Participants
  • Parent commits 3de7da5

Comments (0)

Files changed (1)

File dogslow/__init__.py

 from django.core.mail.message import EmailMessage
 from django.core.urlresolvers import resolve, Resolver404
 
+try:
+    from raven.contrib.django.models import client
+    from raven.utils.wsgi import get_current_url, get_environ, get_headers
+    RAVEN_AVAILABLE = True
+except ImportError:
+    RAVEN_AVAILABLE = False
+
 from dogslow.timer import Timer
 
 _sentinel = object()
         try:
             frame = sys._current_frames()[thread_id]
 
+            if getattr(settings, 'DOGSLOW_RAVEN', RAVEN_AVAILABLE):
+                client.capture('Message',
+                    message='Slow Request watchdog',
+                    stack=[record[0] for record
+                           in inspect.getouterframes(frame)],
+                    data={
+                        'sentry.interfaces.Http': {
+                            'method': request.META.get('REQUEST_METHOD'),
+                            'url': get_current_url(request.META,
+                                                   strip_querystring=True),
+                            'query_string': request.META.get('QUERY_STRING'),
+                            'headers': dict(get_headers(request.META)),
+                            'env': dict(get_environ(request.META)),
+                        },
+                    })
+
             req_string = '%s %s://%s%s' % (
                 request.META.get('REQUEST_METHOD'),
                 request.META.get('wsgi.url_scheme', 'http'),