Your IP : 18.219.47.115


Current Path : /opt/hc_python/lib64/python3.12/site-packages/
Upload File :
Current File : //opt/hc_python/lib64/python3.12/site-packages/NCSentry.py

#!/opt/hc_python/bin/python3
import os
import warnings
import importlib.metadata as metadata
import sentry_sdk

from packaging.version import Version




class NCSentry:
    """
    Simple Wrapper

        sentry = NCSentry()

    After successfully inited class we can use Sentry debug system:

    Report to Sentry:
        SentryClient.capture_message("test")
        SentryClient.capture_exception(Exception("MyAwesomeString"))
    """

    __conflict_under_version = "0.19.2"

    def __init__(self, config_dir=None):
        self.sentry_args = {}
        if config_dir:
            dir_path = config_dir
        else:
            dir_path = os.path.dirname(os.path.realpath(__file__))

        self.conf_path = os.path.join(dir_path, ".sentry.conf")

        self.construct_args()

        with open(self.conf_path) as fh:
            self.dsn = fh.read().strip()
            self.client = sentry_sdk.init(self.dsn, **self.sentry_args)
            self.capture_message = sentry_sdk.capture_message
            self.capture_exception = sentry_sdk.capture_exception

    def construct_args(self):
        try:
            dist_version_str = metadata.version("sentry-sdk")

            installed_version = Version(dist_version_str)
            conflict_version = Version(self.__conflict_under_version)

            if installed_version >= conflict_version:
                self.sentry_args["traces_sample_rate"] = 0

        except Exception as err:
            warnings.warn(f"Can't set up sentry default args properly: {err}")

?>