"""Config file.""" from logging import INFO import os import uuid from common.lambda_exceptions import ArtworkException from lambdacommon import util from lambdacommon.graphql.graphql import GraphQLConnector from owslogger import logger from secrets_manager.lambda_ext import LambdaSecretsManager import sentry_sdk util.init_sentry_for_lambda() def before_send(event, hint): """ Filter out expected transient exceptions from Sentry. ArtworkException "Artwork asset is not valid" is expected during polling when artwork validation is pending. Step Functions handles retry logic. """ if 'exc_info' in hint: exc_type, exc_value, tb = hint['exc_info'] # Ignore transient ArtworkException - expected polling condition if isinstance(exc_value, ArtworkException): message = str(exc_value) if message == 'Artwork asset is not valid': return None # Don't send to Sentry return event # Apply Sentry filter - must happen after init_sentry_for_lambda() if sentry_sdk.Hub.current.client: sentry_sdk.Hub.current.client.options['before_send'] = before_send DEV_ENVIRONMENT = 'dev' ENVIRONMENT = os.environ.get('Environment', DEV_ENVIRONMENT) LAMBDA_NAME = 'lambda-bulk-assets-ingester-poll-art-status' APPLICATION_NAME = 'bulk-assets-ingester' LOGGING_LEVEL = os.environ.get('LOGGING_LEVEL', INFO) LOGGER_DSN = os.environ.get('LOGGER_DSN') app_logger = util.setup_ows_logger( ENVIRONMENT, LAMBDA_NAME, LOGGING_LEVEL, APPLICATION_NAME, '1.0.0', ) secrets_manager_client = LambdaSecretsManager( environment=ENVIRONMENT, service_name=LAMBDA_NAME ) GRAPHQL_GATEWAY_URL = os.environ.get('GRAPHQL_GATEWAY_URL') OA_USER = os.environ.get('OA_USER') graphql_gateway = GraphQLConnector(GRAPHQL_GATEWAY_URL, APPLICATION_NAME) SNOWFLAKE_S3_BUCKET = os.environ.get( 'SNOWFLAKE_S3_BUCKET') SNOWFLAKE_S3_LOCATION = os.environ.get('SNOWFLAKE_S3_LOCATION') CATALOG_INGESTION_SOURCE_ID = str(os.environ.get( 'CATALOG_INGESTION_SOURCE_ID', 1001)) # DDEX_INGESTER_INTEGRATION: replaced lamda-ddex-common logger with ad-hoc # logger 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()})