Package: exception-reports
Exception ReportsGenerate an interactive stack trace that includes variable state at each level.FeaturesGet the variable state you need to understand what caused an exceptionNormal python tracebacks only show the stack up to where an exception was caught,
this library shows the entire traceback.Get full stack traces for logger.error calls (not just for exceptions)Exception reports can output to either the local filesystem or S3Shows beginning and end of large values (django's report only shows beginning)Decorator available for debugging or cases where you don't control logging.Installationpip install exception_reportsUsageBasic Setup (local filesystem)importloggingimportsysfromlogging.configimportdictConfigfromexception_reports.logsimportuncaught_exception_handler,DEFAULT_LOGGING_CONFIG# configure logging to use our filter and formatterdictConfig(DEFAULT_LOGGING_CONFIG)logger=logging.getLogger(__name__)# configure uncaught exceptions to be loggedsys.excepthook=uncaught_exception_handlerraiseException("YOLO!!!!")Change report output locationimportloggingimportsysfromlogging.configimportdictConfigfromexception_reports.logsimportuncaught_exception_handler,ExtraDataLogFormatter,AddExceptionReportFilterfromexception_reports.storagesimportLocalErrorStorageLOGGING_CONFIG={'version':1,'disable_existing_loggers':False,'formatters':{'standard':{'()':ExtraDataLogFormatter,'format':'%(asctime)s%(process)d[%(levelname)s]%(name)s.%(funcName)s:%(message)s;%(data_as_kv)s'},},'filters':{'add_exception_report':{'()':AddExceptionReportFilter,'storage_backend':LocalErrorStorage(output_path='/myproject/bug-reports/')},},'handlers':{'console':{'level':'DEBUG','filters':['add_exception_report'],'class':'logging.StreamHandler','formatter':'standard'},},'loggers':{'':{'handlers':['console'],'level':'INFO','propagate':True}}}# configure logging to use our filter and formatterdictConfig(LOGGING_CONFIG)logger=logging.getLogger(__name__)# configure uncaught exceptions to be loggedsys.excepthook=uncaught_exception_handlerraiseException("YOLO!!!!")Output reports to S3importloggingimportsysfromlogging.configimportdictConfigfromexception_reports.logsimportuncaught_exception_handler,ExtraDataLogFormatter,AddExceptionReportFilterfromexception_reports.storagesimportS3ErrorStorageLOGGING_CONFIG={'version':1,'disable_existing_loggers':False,'formatters':{'standard':{'()':ExtraDataLogFormatter,'format':'%(asctime)s%(process)d[%(levelname)s]%(name)s.%(funcName)s:%(message)s;%(data_as_kv)s'},},'filters':{'add_exception_report':{'()':AddExceptionReportFilter,'storage_backend':S3ErrorStorage(access_key='MY_ACCESS_KEY',secret_key='MY_SECRET_KEY',bucket='MY_BUCKET',prefix='bugs'),},},'handlers':{'console':{'level':'DEBUG','filters':['add_exception_report'],'class':'logging.StreamHandler','formatter':'standard'},},'loggers':{'':{'handlers':['console'],'level':'INFO','propagate':True}}}# configure logging to use our filter and formatterdictConfig(LOGGING_CONFIG)logger=logging.getLogger(__name__)# configure uncaught exceptions to be loggedsys.excepthook=uncaught_exception_handlerraiseException("YOLO!!!!")DecoratorsUseful to do some quick debugging, only get reports for specific exceptions, or when you don't control the
logging config.  Can be used to provide debugging information in UDFs in PySpark.fromexception_reports.decoratorsimportexception_reportfromexception_reports.storagesimportS3ErrorStorage# defaults to local file storage@exception_report()deffoobar(text):raiseException("bad things!!")# s3 storagestorage_backend=S3ErrorStorage(access_key='access_key',secret_key='secret_key',bucket='my_bucket',prefix='all-exceptions/')@exception_report(storage_backend=storage_backend)deffoobar(text):raiseException("bad things!!")# custom decoratordefmy_exception_report(f):storage_backend=S3ErrorStorage(access_key='access_key',secret_key='secret_key',bucket='my_bucket',prefix='all-exceptions/')returnexception_report(storage_backend=storage_backend)(f)@my_exception_reportdeffoobar(text):raiseException("bad things!!")Updating package on pypimake deployChangelog2.0.0feature: support python 3.8 through 3.11build: update to latest version of dependenciesci: switch to github actionsstyle: fix lintsfix: support newer jinja2 (autoescape no longer an extension)1.1.0Bugfix. tinys3 was abandoned. switching to boto3Dev: Added black autoformatter.Dev: Added makefile withtest,lint, andautoformatcommandsDev: Autoformatted code, fixed lint issues1.0.0Feature: Default to not showing less usefull "full stacktrace"Feature: Add platform data to reportFeature: Allow specification of a data_processor function that can alter the exception dataFeature: Safer filenames (no colon characters)Bugfix: Handle all builtin exception types when attaching a message to an exception objectRefactor: Combine repetitive code into create_exception_reportRefactor: Simplify logging APIRefactor: Split ExceptionReporter into component functions.0.4.0Ensure the JSON version of exception data has the same data as the html versionAdd decorator support for outputting json versionsbugfix: Handle exceptions throw fromExceptiondirectly0.3.1If an error happens while loading the source context it's now gracefully handled instead of stopping the report from being generated0.3.0Can now handle exceptions that require special init args.  Uses a modified class instead of creating a new exception instance. Thanks to @munro for noticing
the issue and finding the right solution.