Commits

Erik van Zijst committed d4d7e96

Updated README to reflect the new configuration parameters and refactored the IGNORE_URLS logic.

Comments (0)

Files changed (2)

     DOGSLOW_EMAIL_TO = 'errors@atlassian.com'
     DOGSLOW_EMAIL_FROM = 'no-reply@atlassian.com'
 
+    # Also log to this logger (defaults to none):
+    DOGSLOW_LOGGER = 'syslog_logger'
+
+    # Tuple of url pattern names that should not be monitored:
+    # (defaults to none -- everything monitored)
+    DOGSLOW_IGNORE_URLS = ('some_view', 'other_view')
+
 
 Usage
 -----

dogslow/__init__.py

 
 from dogslow.timer import Timer
 
-IGNORE_URLS = ignore_urls = getattr(settings, 'DOGSLOW_IGNORE_URLS', ())
-
 class SafePrettyPrinter(pprint.PrettyPrinter, object):
     def format(self, obj, context, maxlevels, level):
         try:
         try:
             frame = sys._current_frames()[thread_id]
             
-            match = resolve(request.META.get('PATH_INFO'))
-            if match.url_name in IGNORE_URLS:
-                return
-            
             req_string = '%s %s://%s%s' % (
                 request.META.get('REQUEST_METHOD'),
                 request.META.get('wsgi.url_scheme', 'http'),
                                   (getattr(settings, 'DOGSLOW_EMAIL_TO'),))
                 em.send(fail_silently=True)
 
+            # and a custom logger:
             if hasattr(settings, 'DOGSLOW_LOGGER'):
                 logger = logging.getLogger(getattr(settings, 'DOGSLOW_LOGGER'))
-                logger.warn('Slow Request Watchdog: %s, %%s - %%s' % resolve(request.META.get('PATH_INFO')).url_name, str(req_string), output)
+                logger.warn('Slow Request Watchdog: %s, %%s - %%s' %
+                            resolve(request.META.get('PATH_INFO')).url_name,
+                            str(req_string), output)
 
         except Exception:
             logging.exception('Request watchdog failed')
 
 
+    def _is_exempt(self, request):
+        """Returns True if this request's URL resolves to a url pattern whose
+        name is listed in settings.DOGSLOW_IGNORE_URLS.
+        """
+        match = resolve(request.META.get('PATH_INFO'))
+        return match and (match.url_name in
+                       getattr(settings, 'DOGSLOW_IGNORE_URLS', ()))
+
     def process_request(self, request):
-        request.dogslow = self.timer.run_later(
-            WatchdogMiddleware.peek,
-            self.interval,
-            request,
-            thread.get_ident(),
-            dt.datetime.utcnow())
+        if not self._is_exempt(request):
+            request.dogslow = self.timer.run_later(
+                WatchdogMiddleware.peek,
+                self.interval,
+                request,
+                thread.get_ident(),
+                dt.datetime.utcnow())
 
     def _cancel(self, request):
         try: