"""Logger and exception handling setup.""" import uuid import sentry_sdk from lambdacommon.util import setup_ows_logger from owslogger import logger from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration import config from config import ENVIRONMENT, LOGGER_DSN, LOGGER_LEVEL, SCRIPT_NAME if config.SENTRY_DSN: sentry_sdk.init( dsn=config.SENTRY_DSN, integrations=[AwsLambdaIntegration()] ) app_logger = setup_ows_logger( ENVIRONMENT, SCRIPT_NAME, LOGGER_LEVEL, SCRIPT_NAME, '1.0.0', dsn=LOGGER_DSN ) def get_current_logger(correlation_id=None): """Get logger with a correlation_id attached. Args: correlation_id: correlation_id that will be sent along with log record Returns: logger.OwsLoggingAdapter: instance of OwsLoggingAdapter with correlation_id attached. """ return logger.OwsLoggingAdapter( app_logger, {'correlation_id': correlation_id or uuid.uuid4()})