Created
November 19, 2012 02:40
-
-
Save samkaufman/4108681 to your computer and use it in GitHub Desktop.
Hack to record web.py exceptions for New Relic Agent
This file contains hidden or 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
| # 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow!! Amazing, thanks for the gist!