Skip to content

Instantly share code, notes, and snippets.

@hynek
Last active July 8, 2019 15:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hynek/a1f3f92d57071ebc5b91 to your computer and use it in GitHub Desktop.
Save hynek/a1f3f92d57071ebc5b91 to your computer and use it in GitHub Desktop.
Please note that nowadays I prefer writing middleware.
class SentryProcessor(object):
def __init__(self, client):
self.client = client
def __call__(self, logger, method, event_dict):
event_dict["sentry"] = u"skipped"
if event_dict.pop("sentry_skip", False) is True or self.client is None:
return event_dict
exc_info = event_dict.pop("exc_info", None)
if exc_info:
if not isinstance(exc_info, tuple):
exc_info = sys.exc_info()
sid, = self.client.captureException(exc_info=exc_info,
extra=event_dict)
event_dict["sentry_id"] = sid
event_dict["sentry"] = u"sent"
return event_dict
class MetricsProcessor(object):
def __init__(self, meters, graphite_pusher):
class Stats(object):
pass
for m in meters:
ms = MeterStat(m)
setattr(Stats, m, ms)
self.stats = Stats()
scales.init(self.stats, "/")
self.METER_MAP = {name: getattr(self.stats, name) for name in meters}
self.pusher = graphite_pusher
if self.pusher:
self.pusher.allow("**")
self.pusher.start()
def __call__(self, logger, method, event_dict):
event = event_dict["event"]
m = self.METER_MAP.get(event)
if m is not None:
m.mark()
return event_dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment