Example #1
0
    def __init__(self,
                 project_id=None,
                 api_key=None,
                 host=None,
                 timeout=None,
                 **config):
        """Client constructor."""
        # properties
        self._api_url = None
        self._deploy_url = None
        self._context = None
        self.notifier = __notifier__

        if not project_id:
            project_id = os.getenv('AIRBRAKE_PROJECT_ID', '')
        self.project_id = str(project_id)
        if not api_key:
            api_key = os.getenv('AIRBRAKE_API_KEY', '')
        self.api_key = str(api_key)

        if not all((self.project_id, self.api_key)):
            raise ab_exc.AirbrakeNotConfigured(
                "Airbrake API Key (api_key) and Project ID "
                "(project_id) must be set. These values "
                "may be set using the environment variables "
                "AIRBRAKE_API_KEY and AIRBRAKE_PROJECT_ID or "
                "by passing in the arguments explicitly.")

        if not host:
            host = os.getenv('AIRBRAKE_HOST',
                             self.AIRBRAKE_HOST_DEFAULT.strip('/'))
        self.host = str(host)

        # Context values
        environment = config.get("environment",
                                 os.getenv('AIRBRAKE_ENVIRONMENT'))
        self.environment = str(environment)

        hostname = os.getenv('HOSTNAME') or socket.gethostname()
        self.hostname = str(hostname)

        self.root_directory = config.get("root_directory", os.getcwd())
        self.timeout = timeout or self.AIRBRAKE_TIMEOUT_DEFAULT

        self.local_revision = utils.get_local_git_revision()

        self.whitelist_keys = config.get("whitelist_keys", [])
        self.blacklist_keys = config.get("blacklist_keys", [])
        self.filter_chain = [self.filter_whitelist, self.filter_blacklist]

        self.send_uncaught_exc = config.get("send_uncaught_exc", True)
        if self.send_uncaught_exc:
            self.excepthook = sys.excepthook
            sys.excepthook = self.uncaught_handler

        self._exc_queue = utils.CheckableQueue()
Example #2
0
    def __init__(self,
                 project_id=None,
                 api_key=None,
                 environment=None,
                 base_url=None):
        """Client constructor."""
        # properties
        self._api_url = None
        self._context = None
        self.deploy_url = "http://api.airbrake.io/deploys.txt"
        self.notifier = __notifier__

        if not environment:
            environment = (os.getenv('AIRBRAKE_ENVIRONMENT')
                           or socket.gethostname())
        if not project_id:
            project_id = os.getenv('AIRBRAKE_PROJECT_ID', '')
        if not api_key:
            api_key = os.getenv('AIRBRAKE_API_KEY', '')
        if not base_url:
            base_url = os.getenv('AIRBRAKE_BASE_URL',
                                 'https://airbrake.io').strip('/')

        self.environment = str(environment)
        self.project_id = str(project_id)
        self.api_key = str(api_key)
        self.base_url = str(base_url)

        if not all((self.project_id, self.api_key)):
            raise ab_exc.AirbrakeNotConfigured(
                "Airbrake API Key (api_key) and Project ID "
                "(project_id) must be set. These values "
                "may be set using the environment variables "
                "AIRBRAKE_API_KEY and AIRBRAKE_PROJECT_ID or "
                "by passing in the arguments explicitly.")

        self._exc_queue = utils.CheckableQueue()