def init(config: Optional[pyramid.config.Configurator] = None) -> None: global ORIG if _utils.env_or_config(config, 'C2C_TRACK_REDIS', 'c2c.track_redis', True, _utils.config_bool): try: import redis.client ORIG = redis.client.StrictRedis.execute_command redis.client.StrictRedis.execute_command = _execute_command_patch LOG.info("Enabled the redis tracking") except Exception: # pragma: nocover LOG.warning("Cannot enable redis tracking", exc_info=True)
def init_daemon(config: Optional[pyramid.config.Configurator] = None) -> None: """ Initialize the debug broadcast listeners. Used mostly for headless processes that depend on a master providing a normal REST API and broadcasting those requests. """ if _utils.env_or_config(config, ENV_KEY, CONFIG_KEY, type_=_utils.config_bool): from . import _listeners _listeners.init()
def init(config: Optional[pyramid.config.Configurator] = None) -> None: global _client_setup sentry_url = _utils.env_or_config(config, 'SENTRY_URL', 'c2c.sentry.url') if sentry_url is not None and not _client_setup: client_info: MutableMapping[str, Any] = { key[14:].lower(): value for key, value in os.environ.items() if key.startswith('SENTRY_CLIENT_') } git_hash = _utils.env_or_config(config, 'GIT_HASH', 'c2c.git_hash') if git_hash is not None and not ('release' in client_info and client_info['release'] != 'latest'): client_info['release'] = git_hash client_info['ignore_errors'] = client_info.pop('ignore_exceptions', 'SystemExit').split(",") tags = { key[11:].lower(): value for key, value in os.environ.items() if key.startswith('SENTRY_TAG_') } sentry_logging = LoggingIntegration(level=logging.DEBUG, event_level=_utils.env_or_config( config, 'SENTRY_LEVEL', 'c2c.sentry_level', 'ERROR').upper()) sentry_sdk.init(dsn=sentry_url, integrations=[sentry_logging], before_send=_create_before_send_filter(tags), **client_info) _client_setup = True excludes = _utils.env_or_config(config, "SENTRY_EXCLUDES", "c2c.sentry.excludes", "sentry_sdk").split(",") for exclude in excludes: ignore_logger(exclude) LOG.info("Configured sentry reporting with client=%s and tags=%s", repr(client_info), repr(tags))
def init(config: pyramid.config.Configurator) -> None: global ID_HEADERS, DEFAULT_TIMEOUT ID_HEADERS = [ 'X-Request-ID', 'X-Correlation-ID', 'Request-ID', 'X-Varnish', 'X-Amzn-Trace-Id' ] extra_header = _utils.env_or_config(config, 'C2C_REQUEST_ID_HEADER', 'c2c.request_id_header') if extra_header is not None: ID_HEADERS.insert(0, extra_header) DEFAULT_TIMEOUT = _utils.env_or_config(config, 'C2C_REQUESTS_DEFAULT_TIMEOUT', 'c2c.requests_default_timeout', type_=float) config.add_request_method(_gen_request_id, 'c2c_request_id', reify=True) _patch_requests() if _utils.env_or_config(config, 'C2C_SQL_REQUEST_ID', 'c2c.sql_request_id', False): from . import _sql _sql.init()
def __init__(self, config: pyramid.config.Configurator) -> None: config.add_route("c2c_health_check", _utils.get_base_path(config) + r"/health_check", request_method="GET") config.add_view(self._view, route_name="c2c_health_check", renderer="fast_json", http_cache=0) self._checks: List[Tuple[str, Callable[[pyramid.request.Request], Any], int]] = [] redis_url = _utils.env_or_config(config, broadcast.REDIS_ENV_KEY, broadcast.REDIS_CONFIG_KEY) if redis_url is not None: self.add_redis_check(redis_url, level=2) if version.get_version() is not None: self.add_version_check(level=2)
def init(config: pyramid.config.Configurator) -> None: if _utils.env_or_config(config, 'C2C_DISABLE_EXCEPTION_HANDLING', 'c2c.disable_exception_handling', '0') == '0': for exception in (HTTPSuccessful, HTTPRedirection): config.add_view(view=_passthrough, context=exception, http_cache=0) common_options = {'renderer': 'json', 'http_cache': 0} config.add_view(view=_http_error, context=HTTPError, **common_options) for exception in (sqlalchemy.exc.IntegrityError, sqlalchemy.exc.DataError): config.add_view(view=_integrity_error, context=exception, **common_options) # We don't want to cry wolf if the user interrupted the uplad of the body for exception in (ConnectionResetError, DisconnectionError): config.add_view(view=_client_interrupted_error, context=exception, **common_options) config.add_view(view=_other_error, context=Exception, **common_options) LOG.info('Installed the error catching views')
def is_enabled(config: pyramid.config.Configurator, env_name: Optional[str] = None, config_name: Optional[str] = None) -> bool: return config_bool(env_or_config(config, env_name, config_name)) and \ env_or_config(config, SECRET_ENV, SECRET_PROP, '') != ''