Skip to content
Maple Docs
Open app

Monitor Apache Airflow 3

Send Apache Airflow 3 metrics, DAG run traces and task logs to Maple with Airflow's built-in OpenTelemetry export, and keep several Airflow deployments apart.

Airflow 3 exports metrics and traces over OpenTelemetry without a plugin. This guide points that export at Maple, names each Airflow deployment so several of them stay separate, and ships task logs with an OpenTelemetry Collector. It was tested with Airflow 3.4.0 on Python 3.12.

Prerequisites

  • Airflow 3.2 or later. From 3.2 the exporters read the standard OTEL_* environment variables, which is where the ingest key goes.

  • The otel extra, which installs the OpenTelemetry SDK and the OTLP exporters:

    pip install "apache-airflow[otel]==3.4.0" \
      --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-3.4.0/constraints-3.12.txt"
    uv add "apache-airflow[otel]==3.4.0" \
      --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-3.4.0/constraints-3.12.txt"
  • An ingest key from Settings → Ingestion in Maple. Use the private key (maple_sk_…).

Enable metrics and traces

Two Airflow options turn the export on. Everything else is a standard OpenTelemetry variable. Set all of them on every Airflow component: scheduler, DAG processor, triggerer, API server and workers.

# Airflow: turn the two exporters on
export AIRFLOW__METRICS__OTEL_ON="True"
export AIRFLOW__TRACES__OTEL_ON="True"
export AIRFLOW__METRICS__LEGACY_NAMES_ON="False"

# Where to send, and how to authenticate
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.maple.dev" # EU: https://ingest.eu.maple.dev
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
export OTEL_TRACES_EXPORTER="otlp_proto_http"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer%20YOUR_INGEST_KEY"
export OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE="delta"

# Which deployment this is
export OTEL_SERVICE_NAME="airflow-prod"
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=production"

The three Airflow options can live in airflow.cfg instead:

[metrics]
otel_on = True
legacy_names_on = False

[traces]
otel_on = True

What each setting does:

Setting Why
[metrics] otel_on, [traces] otel_on Turn each exporter on. They are independent, and both default to False.
[metrics] legacy_names_on Defaults to True, which also sends every metric under its old name with the DAG and task in the name, such as airflow.ti.finish.orders_etl.load_warehouse.success. See the note below.
OTEL_EXPORTER_OTLP_ENDPOINT The base URL. The exporters add /v1/traces and /v1/metrics.
OTEL_EXPORTER_OTLP_PROTOCOL Selects the HTTP metric exporter.
OTEL_TRACES_EXPORTER Selects the HTTP span exporter. Airflow picks the span exporter from this variable alone, and its default is gRPC even when the protocol variable says http/protobuf.
OTEL_EXPORTER_OTLP_HEADERS The ingest key. The space after Bearer is written %20.
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE Makes counters report the increase since the last export. Without it, task counters chart as zero. See Troubleshooting.
OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES Name the deployment. See Name each deployment.

In the test setup, two DAGs with six tasks produced 116 metric names with legacy names on and 60 with them off. The new names carry the same information as dag_id, task_id and state attributes, which is what you filter and group by in Maple.

[metrics] otel_prefix sets the first segment of every metric name. It defaults to airflow, and the names in this guide assume that.

Settings Airflow has deprecated

Older guides configure the endpoint in airflow.cfg. Airflow 3.2 deprecated those options in favor of the standard variables above:

Deprecated option, in [metrics] and [traces] Use instead
otel_host, otel_port, otel_ssl_active OTEL_EXPORTER_OTLP_ENDPOINT
otel_service OTEL_SERVICE_NAME
otel_interval_milliseconds (metrics only) OTEL_METRIC_EXPORT_INTERVAL
otel_debugging_on OTEL_METRICS_EXPORTER=console for a test

They still work in 3.4.0 and log a deprecation warning. They have no option for request headers, so the ingest key goes in OTEL_EXPORTER_OTLP_HEADERS either way. When an OTEL_EXPORTER_OTLP_ENDPOINT is set, Airflow ignores the host and port options.

Name each deployment

Maple keeps data apart by service.name and deployment.environment.name. Give every Airflow deployment its own service name, and set the environment it runs in:

# Production
export OTEL_SERVICE_NAME="airflow-prod"
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=production"

# Staging
export OTEL_SERVICE_NAME="airflow-staging"
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=staging"

Without OTEL_SERVICE_NAME, every deployment reports as airflow and their data mixes. For several deployments in one environment, such as one per team or region, keep the environment and vary the service name: airflow-prod-eu, airflow-prod-data-platform.

All components of one deployment share the service name. The scheduler, DAG processor and workers are not separate services in Maple.

The Services page with two rows, airflow-prod and airflow-staging, each with its span count, errors, error rate, p50, p95 and log count, and an Environment filter listing production and staging.
Two Airflow deployments as two services, filterable by environment. The error rate is the share of DAG runs that failed.

What shows up in Maple

Traces

Each DAG run is one trace. Its root span is sent when the run finishes.

Span What it is Attributes
dag_run.<dag_id> The root span, from the start of the run to its end. airflow.dag_id, airflow.dag_run.run_id, airflow.dag_run.run_type, airflow.dag_run.logical_date, .queued_at, .start_date, .end_date
task_run.<task_id> One task instance, from scheduling to its final state. airflow.dag_id, airflow.task_id, airflow.dag_run.run_id, airflow.task_instance.id, airflow.task_instance.state, airflow.task_instance.try_number, .map_index
worker.<task_id> The task’s code running on a worker, as a child of its task_run. airflow.dag_id, airflow.task_id, airflow.dag_run.run_id, airflow.task_instance.try_number, .map_index, and an exception event when the task raises

The gap between the start of a task_run span and its worker span is the time the task waited to be scheduled, queued and started.

A failed run has status Error on the root span, on the failed task_run and on its worker span. Because the root span is what Maple’s service pages read, the error rate of an Airflow service is its share of failed DAG runs.

The Traces page listing DAG runs from two Airflow deployments. Each row is a dag_run span with its service, duration, span count and status. Runs of billing_export are marked Error, runs of orders_etl OK. Filters on the left list the environments, services and root spans.
One trace per DAG run, from both deployments.

To find runs in Explore → Traces:

  • One deployment: pick it under Service, or pick an Environment.
  • One DAG: pick dag_run.<dag_id> under Root span.
  • Failed runs: tick Has error.
  • One run: click Advanced filter and enter attr.airflow.dag_run.run_id = "<run_id>" with the run ID from the Airflow UI.
A trace of a failed billing_export DAG run with five spans on a timeline: the dag_run root, task_run and worker spans for fetch_invoices, and task_run and worker spans for upload_to_sftp in red. The worker.upload_to_sftp span is open in a side panel showing the status Error, a ConnectionError exception event with its message, and the span attributes airflow.dag_id, airflow.task_id and airflow.dag_run.run_id.
A failed run. The worker span of the task that raised carries the exception and the DAG, task and run IDs.

Exceptions recorded on worker spans also open issues on the Errors page, grouped by exception type.

Metrics

Metric names start with airflow.. These are the ones to chart or alert on first. All of them were received from the test deployment.

Metric Type Attributes What it tells you
airflow.ti_failures, airflow.ti_successes Sum dag_id, task_id Task instances that failed or succeeded.
airflow.ti.finish Sum dag_id, task_id, state Finished task instances by final state.
airflow.task.duration Exp Hist, ms dag_id, task_id How long tasks run.
airflow.task.queued_duration, airflow.task.scheduled_duration Exp Hist, ms dag_id, task_id How long tasks wait before they run.
airflow.dagrun.duration.success, airflow.dagrun.duration.failed Exp Hist, ms dag_id How long DAG runs take.
airflow.dagrun.schedule_delay Exp Hist, ms dag_id Delay between the scheduled start of a run and its actual start.
airflow.scheduler_heartbeat, airflow.dag_processor_heartbeat, airflow.triggerer_heartbeat Sum none Each component counts its heartbeats. A flat line is a dead component.
airflow.scheduler.scheduler_loop_duration Exp Hist, ms none Time for one scheduler loop.
airflow.executor.open_slots, .queued_tasks, .running_tasks Gauge none Executor capacity and backlog.
airflow.pool.open_slots, .running_slots, .queued_slots, .starving_tasks Gauge none Pool capacity and tasks that cannot get a slot.
airflow.dag_processing.import_errors Gauge none DAG files that failed to parse.
airflow.dag_processing.total_parse_time, airflow.dagbag_size Gauge none Parse time for the DAG folder, and how many DAGs it holds.

The Service column and filter on the Metrics page are the deployment, so every chart can be split or filtered by service.name.

The metric page for airflow.ti_failures, a Sum. A line chart of the rate per second by service peaks every two minutes, each time the failing DAG runs, with airflow-prod and airflow-staging in the legend and a breakdown table of the two services below.
airflow.ti_failures per deployment. Both test deployments fail the same task on the same schedule, so their lines overlap. Group by attr.dag_id or attr.task_id to see which task is failing.

Dashboard

On the Metrics page, open a metric, set the query and click Add to dashboard. A starting set for one board:

Chart Metric Aggregate Group by
Task failures airflow.ti_failures increase attr.dag_id
Task outcomes airflow.ti.finish increase attr.state
Slowest tasks airflow.task.duration p95 attr.task_id
Queue wait airflow.task.queued_duration p95 attr.dag_id
DAG run duration airflow.dagrun.duration.success p95 attr.dag_id
Schedule delay airflow.dagrun.schedule_delay p95 attr.dag_id
Scheduler heartbeat airflow.scheduler_heartbeat rate service.name
Scheduler loop airflow.scheduler.scheduler_loop_duration p95 service.name
Executor backlog airflow.executor.queued_tasks max service.name
DAG import errors airflow.dag_processing.import_errors max service.name

For one board per deployment, add service.name = "airflow-prod" to Where on each chart. For one board across deployments, group by service.name. See Build dashboards.

Alerts

Three rules cover most of what goes wrong. Create them under Alerts → Rules. See Alert rules for every field.

Failed DAG runs. Start from the High error rate template and pick the Airflow service. The built-in error rate reads root spans, which for Airflow are DAG runs. Lower Minimum samples from 50 to a number your deployment reaches in one window, or a quiet deployment never fires.

Task failures. Use Query builder on Metrics with airflow.ti_failures, the increase aggregation and a group-by on attr.dag_id. Alert when the value is above 0, or above the number of failures you accept per window. Each DAG gets its own incident. Add service.name to Where to scope the rule to one deployment.

Scheduler heartbeat. Use Query builder on Metrics with airflow.scheduler_heartbeat, the increase aggregation and a group-by on service.name. Alert when the value is below 1 over a 5 minute window, set Minimum samples to 0 and turn on Alert when there is no data. A stopped scheduler sends nothing, so the empty window has to count as a breach. The same rule on airflow.dag_processor_heartbeat and airflow.triggerer_heartbeat covers the other components.

Logs

Airflow’s OpenTelemetry export covers metrics and traces only. Task logs stay in files, one JSON object per line:

$AIRFLOW_HOME/logs/dag_id=<dag_id>/run_id=<run_id>/task_id=<task_id>/attempt=<n>.log

To send them to Maple, run an OpenTelemetry Collector (the contrib distribution, which has the file log receiver) where the log files are, and tail them:

receivers:
    file_log:
        include:
            - /opt/airflow/logs/dag_id=*/run_id=*/task_id=*/attempt=*.log
        start_at: beginning
        operators:
            - type: json_parser
              timestamp:
                  parse_from: attributes.timestamp
                  layout_type: gotime
                  layout: "2006-01-02T15:04:05.999999Z"
              severity:
                  parse_from: attributes.level
            - type: move
              from: attributes.event
              to: body
            - type: remove
              field: attributes.timestamp
            - type: remove
              field: attributes.level

processors:
    resource:
        attributes:
            - key: service.name
              value: airflow-prod
              action: upsert
            - key: deployment.environment.name
              value: production
              action: upsert

exporters:
    otlp_http:
        endpoint: https://ingest.maple.dev
        headers:
            Authorization: Bearer ${env:MAPLE_INGEST_KEY}

service:
    pipelines:
        logs:
            receivers: [file_log]
            processors: [resource]
            exporters: [otlp_http]

Notes on the config:

  • Use the same service.name and environment as the Airflow deployment. The logs then sit under the same service as its traces and metrics.
  • Older Collector releases use the previous names: filelog and otlphttp. This config was tested with Collector 0.166.0.
  • Replace /opt/airflow/logs with $AIRFLOW_HOME/logs, or with [logging] base_log_folder if you changed it. Workers on separate machines each need a Collector, or a shared log volume.
  • EU organizations use https://ingest.eu.maple.dev as the endpoint.

Each log line arrives with its level, the message as the body, and dag_id, task_id, run_id and try_number as attributes. Airflow does not write trace IDs into task logs, so a log line is not linked to its span. To go from a failed run to its logs, open Explore → Logs, pick the service and set the time range to the run. The run_id on each line matches airflow.dag_run.run_id on the spans.

The Logs page filtered to severity error and the service airflow-prod. Rows alternate between Task failed with exception and SFTP upload of invoices failed: connection refused, each with a dag_id attribute of billing_export.
Task logs from the Collector, filtered to errors in one deployment. The message a task logged sits next to Airflow's own failure line.

Verify

  1. Restart the Airflow components so they read the new settings, and let a DAG run finish.
  2. Open Services in Maple. The deployment appears under the name in OTEL_SERVICE_NAME once its first DAG run ends.
  3. Open Explore → Traces. The run is a dag_run.<dag_id> trace with a task_run and a worker span per task.
  4. Open Explore → Metrics and search airflow.. Metrics are exported every 60 seconds.

A component with metrics on logs [OTLPMetricExporter] Connecting to OpenTelemetry Collector at https://ingest.maple.dev when it starts. If that line is missing from a component’s log, it did not read [metrics] otel_on.

Troubleshooting

  • Metrics arrive, traces do not. OTEL_TRACES_EXPORTER is not set, so Airflow uses the gRPC span exporter while metrics go over HTTP. The log shows Failed to export traces with StatusCode.UNAVAILABLE. Set OTEL_TRACES_EXPORTER=otlp_proto_http.
  • airflow.ti_failures and other task counters chart as zero. Each task runs in its own short process, which reports a counter once with the value 1 and exits. As a cumulative counter that never increases, so its rate is 0. Set OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta on every component, workers included.
  • Hundreds of metric names, with DAG and task IDs in them. [metrics] legacy_names_on is still True. Set it to False.
  • A deployment shows up as airflow. OTEL_SERVICE_NAME is not set on that component, so its data mixes with every other deployment that lacks the variable.
  • Some spans or metrics are missing for a deployment. The variables are set on the scheduler but not on the workers, or the other way round. dag_run and task_run spans come from the scheduler and API server, worker spans and task counters from the process that runs the task.
  • A running DAG is not in the trace list yet. The root dag_run span is sent when the run reaches its final state.
  • 401 responses. The key is wrong, was copied from the other region, or the header is malformed. In OTEL_EXPORTER_OTLP_HEADERS it is written Authorization=Bearer%20YOUR_INGEST_KEY. See Ingest API status codes.
  • airflow standalone cannot find airflow. Standalone starts its components by running airflow from PATH. Activate the virtual environment, or put its bin directory on PATH, before you start it.
  • The Collector reads no log files. The include pattern must match the layout under your log folder, and the Collector’s user must be able to read it.

Next steps