"""DataDog utils.""" import time from lambdacommon import util def call_datadog_with_metric(metric, tags, api_key=None, app_key=None, logger=None, value=1): """Function to wrap the DataDog metric call. Args: metric (str): custom metric name to send to DataDog. tags (list): list of tags api_key (str): API key app_key (str): APP key logger (logger): logger instance value (int): metric value """ with util.datadog_connection( api_key=api_key, app_key=app_key ) as datadog_conn: now = time.time() try: send_response = datadog_conn.Metric.send([ { 'metric': metric, 'type': 'count', 'interval': 60, 'points': (now, value), 'tags': tags } ]) if logger: logger.info(f'Datadog metric sent - {send_response}') except Exception as e: if logger: logger.error(f'Datadog metric send failure. {e}')