Datadog Provider for Apache Airflow

3.10.3 · active · verified Sat Apr 11

This provider package integrates Apache Airflow with Datadog, enabling users to send metrics, events, and query metrics from Datadog directly within their Airflow DAGs. It supports monitoring of DAGs, tasks, and other Airflow components through Datadog's platform. The current version is 3.10.3 and it follows the Apache Airflow provider release cadence, often aligning with Airflow core releases but also releasing independently for bug fixes and features.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use the `DatadogOperator` to send a custom metric to Datadog. It assumes that Datadog API and APP keys are configured either via an Airflow connection named `datadog_default` or directly through environment variables `DATADOG_API_KEY` and `DATADOG_APP_KEY`.

import os
from datetime import datetime

from airflow import DAG
from airflow.providers.datadog.operators.datadog import DatadogOperator

# Datadog API and APP keys are typically configured as an Airflow Connection
# with conn_id='datadog_default'. For demonstration, using environment vars.
# In a real Airflow environment, prefer Airflow Connections for credentials.

with DAG(
    dag_id='datadog_metrics_example',
    start_date=datetime(2023, 1, 1),
    schedule_interval=None,
    catchup=False,
    tags=['datadog', 'metrics'],
    params={
        'metric_value': 123.45
    }
) as dag:
    send_custom_metric_task = DatadogOperator(
        task_id='send_custom_metric',
        datadog_conn_id='datadog_default', # Ensure this connection is configured in Airflow UI
        metric_name='my.airflow.custom.metric',
        metric_type='gauge',
        points=[["{{ execution_date.int_timestamp }}", "{{ params.metric_value }}"]],
        tags=['env:dev', 'dag_id:{{ dag.dag_id }}', 'task_id:{{ ti.task_id }}'],
        # API/APP keys can be passed here, but Airflow Connections are preferred
        api_key=os.environ.get('DATADOG_API_KEY', ''),
        app_key=os.environ.get('DATADOG_APP_KEY', ''),
    )

    # Note: For this DAG to run successfully and send metrics to Datadog,
    # you must have a Datadog connection configured in Airflow UI (Admin -> Connections)
    # with Conn Id 'datadog_default' and provide your Datadog API and APP keys.
    # Alternatively, ensure DATADOG_API_KEY and DATADOG_APP_KEY environment
    # variables are set where the Airflow worker executes the task.

view raw JSON →