Skip to content

Instantly share code, notes, and snippets.

@samkaufman
Created November 19, 2012 02:40
Show Gist options
  • Select an option

  • Save samkaufman/4108681 to your computer and use it in GitHub Desktop.

Select an option

Save samkaufman/4108681 to your computer and use it in GitHub Desktop.
Hack to record web.py exceptions for New Relic Agent
# Record handler exceptions for New Relic
def _new_internalerror(orig_internalerror):
def inner():
e = orig_internalerror()
if isinstance(e, web.webapi._InternalError):
e.orig_exc_info = sys.exc_info()
return e
return inner
def catch_and_report_exceptions(handler):
try:
return handler()
except Exception, e:
if hasattr(e, 'orig_exc_info'):
newrelic.agent.record_exception(*e.orig_exc_info)
e.orig_exc_info = None # not today, leaks.
raise
app.internalerror = _new_internalerror(app.internalerror)
app.add_processor(catch_and_report_exceptions)
@gabrii
Copy link

gabrii commented Feb 15, 2015

Wow!! Amazing, thanks for the gist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment