import logging.config from fansifter_common.logging.utils import update_logging_config import config from app.exceptions import ImproperlyConfigured _ready = False def setup() -> None: global _ready if _ready: return None logging.config.dictConfig( update_logging_config( config.LOGGING_CONFIG, environment=config.ENVIRONMENT, service_name=config.SERVICE_NAME, service_version=config.SERVICE_NAME, logger_name=config.LAMBDA_NAME, log_format=config.LOG_FORMAT, # type: ignore[arg-type] debug=config.LOGGING_DEBUG, ) ) if config.ENVIRONMENT in ["qa", "prod"]: # Setup Sentry if config.SENTRY_DSN: import sentry_sdk from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration from sentry_sdk.integrations.httpx import HttpxIntegration sentry_sdk.init( dsn=config.SENTRY_DSN, environment=config.ENVIRONMENT, integrations=[ AwsLambdaIntegration(), HttpxIntegration(), ], ) else: raise ImproperlyConfigured( f"Sentry is not configured in {config.ENVIRONMENT}." ) _ready = True setup()