1. Tobias McNulty
  2. dogslow

Commits

Tobias McNulty  committed 6e5b7db Draft

attempt to write a log message when dogslow fails to take a snapshot of requests that took longer than the specified number of seconds

  • Participants
  • Parent commits 3de7da5
  • Branches default

Comments (0)

Files changed (2)

File dogslow/__init__.py

View file
 
 from dogslow.timer import Timer
 
+logger = logging.getLogger(__name__)
+
 _sentinel = object()
 def safehasattr(obj, name):
     return getattr(obj, name, _sentinel) is not _sentinel
                            extra={'request': request})
 
         except Exception:
-            logging.exception('Request watchdog failed')
+            logger.exception('Request watchdog failed')
 
     def _is_exempt(self, request):
         """Returns True if this request's URL resolves to a url pattern whose
                 request,
                 thread.get_ident(),
                 dt.datetime.utcnow())
+            request.dogslow_starttime = dt.datetime.utcnow()
 
     def _cancel(self, request):
         try:
             if safehasattr(request, 'dogslow'):
+                request_time = dt.datetime.utcnow() - request.dogslow_starttime
+                request_secs = request_time.total_seconds()
+                if not request.dogslow.is_finished() and\
+                   request_secs > self.interval:
+                    diff = request_secs - self.interval
+                    logger.warning('Request took %s seconds (%s longer than '
+                                   'the limit of %s) but dogslow failed to '
+                                   'take a snapshot of the running request.'
+                                   '' % (request_secs, diff, self.interval))
                 self.timer.cancel(request.dogslow)
                 del request.dogslow
         except:
-            logging.exception('Failed to cancel request watchdog')
+            logger.exception('Failed to cancel request watchdog')
 
     def process_response(self, request, response):
         self._cancel(request)

File dogslow/timer.py

View file
 import threading
 import time
 
+logger = logging.getLogger(__name__)
+
 class TimerTask(object):
 
     def __init__(self, callable_, *args, **kwargs):
         try:
             self._callable()
         except:
-            logging.exception('TimerTask failed')
+            logger.exception('TimerTask failed')
         finally:
             self._finished = True