Created
March 5, 2014 12:19
-
-
Save bobuss/9366148 to your computer and use it in GitHub Desktop.
Send locals to your sentry server while an exception occurs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import | |
import pprint | |
from raven.handlers.logging import SentryHandler | |
class VerboseSentryHandler(SentryHandler, object): | |
""" | |
Subclass the SentryHandler in order to add the locals to the record | |
Inspired by The Verbose exception Formatter | |
From Bitly blog : http://word.bitly.com/post/69080588278/logging-locals | |
""" | |
def _emit(self, record, **kwargs): | |
tb = record.exc_info[2] # This is the outermost frame of the traceback. | |
while tb.tb_next: | |
tb = tb.tb_next # Zoom to the innermost frame. | |
record.extra = { | |
'data': {k: pprint.pformat(v) for k, v in tb.tb_frame.f_locals.iteritems()}} | |
super(VerboseSentryHandler, self)._emit(record, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment