diff --git a/python/humbug/report.py b/python/humbug/report.py index 48feca3..06e57c9 100644 --- a/python/humbug/report.py +++ b/python/humbug/report.py @@ -6,7 +6,7 @@ import concurrent.futures from dataclasses import dataclass, field from enum import Enum - +import inspect import logging import os import pkg_resources @@ -140,7 +140,7 @@ def publish(self, report: Report, wait: bool = False) -> None: timeout=self.timeout_seconds, ) self.report_futures.append(report_future) - except: + except Exception: pass def custom_report( @@ -379,7 +379,10 @@ def record_factory(*args, **kwargs): self.is_loggerhook_set = True def setup_excepthook( - self, tags: Optional[List[str]] = None, publish: bool = True + self, + tags: Optional[List[str]] = None, + publish: bool = True, + modules_whitelist: Optional[List[str]] = None, ) -> None: """ Adds error_report with python Exceptions. @@ -392,9 +395,22 @@ def setup_excepthook( original_excepthook = sys.excepthook def _hook(exception_type, exception_instance, traceback): - self.error_report(error=exception_instance, tags=tags, publish=publish) original_excepthook(exception_type, exception_instance, traceback) + module = inspect.getmodule(exception_type) + report_error = False + if modules_whitelist is None: + report_error = True + elif module is not None and modules_whitelist is not None: + for whitelisted_module in modules_whitelist: + if module.__name__.startswith(whitelisted_module): + report_error = True + + if report_error: + self.error_report( + error=exception_instance, tags=tags, publish=publish + ) + sys.excepthook = _hook self.is_excepthook_set = True @@ -484,5 +500,5 @@ def publish(self, report: Report, wait: bool = False) -> None: timeout=self.timeout_seconds, ) self.report_futures.append(report_future) - except: + except Exception: pass diff --git a/python/setup.py b/python/setup.py index 8698a21..a6bd514 100644 --- a/python/setup.py +++ b/python/setup.py @@ -6,7 +6,7 @@ setup( name="humbug", - version="0.2.1", + version="0.2.2", packages=find_packages(), install_requires=["requests"], extras_require={