diff --git a/backtracepython/report.py b/backtracepython/report.py index 28fc747..1c5a9ee 100644 --- a/backtracepython/report.py +++ b/backtracepython/report.py @@ -3,6 +3,7 @@ import threading import time import uuid +import traceback from backtracepython.attributes.attribute_manager import attribute_manager @@ -39,7 +40,8 @@ def __init__(self): } def set_exception(self, garbage, ex_value, ex_traceback): - self.report["classifiers"] = [ex_value.__class__.__name__] + exception_classifier = ex_value.__class__.__name__ + self.report["classifiers"] = [exception_classifier] self.report["attributes"]["error.message"] = str(ex_value) # reset faulting thread id and make sure the faulting thread is not listed twice @@ -63,6 +65,15 @@ def set_exception(self, garbage, ex_value, ex_traceback): self.faulting_thread_id = fault_thread_id self.report["mainThread"] = self.faulting_thread_id + self.set_annotation( + "Exception", + { + "type": exception_classifier, + "message": str(ex_value), + "traceback": traceback.format_tb(ex_traceback), + }, + ) + def capture_last_exception(self): self.set_exception(*sys.exc_info()) diff --git a/tests/test_report_attributes.py b/tests/test_report_attributes.py index e277c26..92aa632 100644 --- a/tests/test_report_attributes.py +++ b/tests/test_report_attributes.py @@ -85,3 +85,17 @@ def test_override_client_annotation(): new_report.set_annotation(annotation_name, override_report_annotation) report_annotation = new_report.get_annotations() assert report_annotation[annotation_name] == override_report_annotation + + +def test_set_exception_annotation(): + + def open_file(name): + open(name).read() + + try: + open_file("not existing file") + except: + report = BacktraceReport() + report.capture_last_exception() + annotations = report.get_annotations() + assert annotations["Exception"] is not None