# 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:

    ```bash
    pip install "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.

```bash
# 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:

```ini
[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](#troubleshooting).                                                |
| `OTEL_SERVICE_NAME`, `OTEL_RESOURCE_ATTRIBUTES`     | Name the deployment. See [Name each deployment](#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:

```bash
# 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.

<figure class="shot">
  <img src="/screenshots/docs/airflow-01-services.webp" alt="The Services page grouped by namespace and environment. Below three other services, airflow-prod sits under production and airflow-staging under staging, each with its p50, p95 and p99 duration, error rate and throughput." loading="lazy" />
  <figcaption>Two Airflow deployments as two services, one per environment. The error rate is the share of DAG runs that failed.</figcaption>
</figure>

## 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.

<figure class="shot">
  <img src="/screenshots/docs/airflow-02-dag-runs.webp" alt="The Traces page filtered to the services airflow-prod and airflow-staging. Each row is a dag_run root span with its trace ID, service, span count, duration and status. Runs of billing_export are marked Error, runs of orders_etl OK." loading="lazy" />
  <figcaption>One trace per DAG run, filtered to the two Airflow services.</figcaption>
</figure>

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.

<figure class="shot">
  <img src="/screenshots/docs/airflow-03-failed-task.webp" alt="A trace of a failed billing_export DAG run. A banner reads 3 failed spans, likely origin worker.upload_to_sftp, Exception: ConnectionError. The timeline has 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 with a ConnectionError exception event, its message, and the span attributes airflow.dag_id and airflow.dag_run.run_id." loading="lazy" />
  <figcaption>A failed run. The <code>worker</code> span of the task that raised carries the exception and the DAG, task and run IDs.</figcaption>
</figure>

Exceptions recorded on `worker` spans also open issues on the [Errors](/docs/errors/overview) page, grouped by exception type. The failed `dag_run` and `task_run` spans carry an error status and no exception, so each of them opens an issue titled **Unknown error** as well.

### 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          | none                                     | Task instances that failed or succeeded, per deployment.                                             |
| `airflow.ti.finish`                                                                             | Sum          | `dag_id`, `task_id`, `state`, `run_type` | Finished task instances by final state. Filter `attr.state = "failed"` for failures per DAG or task. |
| `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](/docs/explore/metrics) page are the deployment, so every chart can be split or filtered by `service.name`.

<figure class="shot">
  <img src="/screenshots/docs/airflow-04-task-failures.webp" alt="The metric page for airflow.ti.finish with Aggregate set to increase, Where set to attr.state = failed and Group by set to attr.task_id. The chart has a spike every two minutes for the task upload_to_sftp, and a side panel lists the attributes dag_id, task_id, state and run_type." loading="lazy" />
  <figcaption>Failed task instances per task: <code>airflow.ti.finish</code> with <code>attr.state = "failed"</code>, grouped by <code>attr.task_id</code>.</figcaption>
</figure>

## Dashboard

On the [Metrics](/docs/explore/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.finish`, **Where** `attr.state = "failed"` | `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](/docs/dashboards/build-dashboards).

<figure class="shot">
  <img src="/screenshots/docs/airflow-06-dashboard.webp" alt="A dashboard named Airflow with six charts: failed task instances by DAG, task outcomes by state, p95 task duration by task, p95 DAG run duration, the scheduler heartbeat rate per deployment and running executor tasks." loading="lazy" />
  <figcaption>Six of the charts above on one board, built with <strong>Add to dashboard</strong> from each metric page.</figcaption>
</figure>

## Alerts

Three rules cover most of what goes wrong. Create them under **Alerts → Rules**. See [Alert rules](/docs/alerting/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.** Open `airflow.ti.finish` on the Metrics page, set **Aggregate** to `increase`, **Where** to `attr.state = "failed"` and **Group by** to `attr.dag_id`, then click **Create alert**. The rule opens in **Query builder** with that query. Alert when the value is above 0, or above the number of failures you accept per window. Set **Breaches to fire** to 1 and **Minimum samples** to 0, because one failed task is one data point. Each DAG gets its own incident. Add `service.name = "airflow-prod"` to **Where** to scope the rule to one deployment.

<figure class="shot">
  <img src="/screenshots/docs/airflow-07-alert-rule.webp" alt="The alert rule editor for a rule named Airflow task failures. The chart replays the increase of the query per attr.dag_id over the last hour against a threshold of 0 and reads Would have fired, with the breaching windows shaded. The summary at the bottom reads Warning when increase is above 0 over 5 min." loading="lazy" />
  <figcaption>The task failure rule replayed against the last hour. The shaded windows are where it would have fired.</figcaption>
</figure>

**Scheduler heartbeat.** Create one rule per deployment. Use **Query builder** on **Metrics** with `airflow.scheduler_heartbeat`, the `increase` aggregation, `service.name = "airflow-prod"` in **Where** and no group-by. 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. That switch is not available on a rule with a group-by, which is why this rule is per deployment. 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:

```text
$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](https://opentelemetry.io/docs/collector/) (the `contrib` distribution, which has the file log receiver) where the log files are, and tail them:

```yaml
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.

<figure class="shot">
  <img src="/screenshots/docs/airflow-05-task-logs.webp" alt="The Logs page filtered to the service airflow-prod and searched for the word failed. Rows at level ERROR alternate between Task failed with exception and SFTP upload of invoices failed, each with a dag_id attribute of billing_export, under a log volume chart." loading="lazy" />
  <figcaption>Task logs from the Collector for one deployment, searched for <code>failed</code>. The message a task logged sits next to Airflow's own failure line.</figcaption>
</figure>

## 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.finish`, `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](/docs/reference/ingest#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

- [Explore traces](/docs/explore/traces)
- [Metrics](/docs/explore/metrics)
- [Create alert rules](/docs/alerting/alert-rules)
- [Python instrumentation](/docs/guides/instrumentation-python) for the code your tasks run
