I am logging messages in django using raven and getentry, but the record seems to delay code execution. For instance:
# ...view code tic = datetime.datetime.now() logging.warning('foo warning') toc = datetime.datetime.now() print "log time %s, %s, %s" % (tic, toc, (toc - tic).total_seconds())
gives the result:
log time 2013-09-25 12:03:56.541091, 2013-09-25 12:03:57.139420, 0.598329
those. this delays code execution for 600 ms in this case. Is this to be expected? I would have thought that the message would be sent async in a separate thread, so the main code would not linger. Also, the ping time for app.getsentry.com is 125 ms, so 600 ms still seem strangely large, even if the message is sent by synchronization. Is there some kind of configuration that I can change to speed things up?
settings file:
LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'handlers': { 'sentry': { 'level': 'INFO', 'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler', }, }, 'loggers': { '': { 'handlers': ['sentry'], 'level': 'INFO', 'propagate': True, }, } }
=== EDIT ===
Thanks to Philip Dupanovich for pointing out the streaming protocols. Unfortunately, they did not work for me in shooting due to the fact that the threads were copied during the loading of workers. I fixed it by adding the post_fork file to the gunicorn configuration file as follows:
import logging from raven.contrib.django.handlers import SentryHandler from raven.transport.threaded import ThreadedHTTPTransport def post_fork(server, worker): LOG = logging.getLogger() for handler in LOG.handlers: if isinstance(handler, SentryHandler): for url, transport in handler.client._registry._transports.items(): if isinstance(transport, ThreadedHTTPTransport): if hasattr(transport, '_worker'): server.log.info("deleting sentry thread worker attribute") delattr(transport, '_worker') else: server.log.info("sentry thread worker not present, nothing to do.")
Obv is a hack, and while it works for me, I have no idea if it will work anywhere else.