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
otelextra, 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.. 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.
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., .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., .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.
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.with the run ID from the Airflow UI.airflow. dag_ run. run_ id = "< run_ id>"
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. |
Exp Hist, ms | dag_id, task_id |
How long tasks wait before they run. |
airflow., 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., airflow.triggerer_heartbeat |
Sum | none | Each component counts its heartbeats. A flat line is a dead component. |
airflow. |
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. |
Gauge | none | DAG files that failed to parse. |
airflow., 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.
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. |
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. |
p95 |
service.name |
| Executor backlog | airflow.executor.queued_tasks |
max |
service.name |
| DAG import errors | airflow. |
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. 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.nameand 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:
filelogandotlphttp. This config was tested with Collector 0.166.0. - Replace
/opt/airflow/logswith$AIRFLOW_HOME/logs, or with[logging] base_log_folderif you changed it. Workers on separate machines each need a Collector, or a shared log volume. - EU organizations use
https://ingest.eu.maple.devas 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.
Verify
- Restart the Airflow components so they read the new settings, and let a DAG run finish.
- Open Services in Maple. The deployment appears under the name in
OTEL_SERVICE_NAMEonce its first DAG run ends. - Open Explore → Traces. The run is a
dag_run.<dag_id>trace with atask_runand aworkerspan per task. - 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_EXPORTERis not set, so Airflow uses the gRPC span exporter while metrics go over HTTP. The log showsFailed to export traceswithStatusCode.UNAVAILABLE. SetOTEL_.TRACES_ EXPORTER=otlp_ proto_ http airflow.ti_failuresand 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. SetOTEL_on every component, workers included.EXPORTER_ OTLP_ METRICS_ TEMPORALITY_ PREFERENCE=delta - Hundreds of metric names, with DAG and task IDs in them.
[metrics] legacy_names_onis stillTrue. Set it toFalse. - A deployment shows up as
airflow.OTEL_SERVICE_NAMEis 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_runandtask_runspans come from the scheduler and API server,workerspans and task counters from the process that runs the task. - A running DAG is not in the trace list yet. The root
dag_runspan is sent when the run reaches its final state. 401responses. The key is wrong, was copied from the other region, or the header is malformed. InOTEL_EXPORTER_OTLP_HEADERSit is writtenAuthorization=Bearer%20YOUR_. See Ingest API status codes.INGEST_ KEY airflow standalonecannot findairflow. Standalone starts its components by runningairflowfromPATH. Activate the virtual environment, or put itsbindirectory onPATH, before you start it.- The Collector reads no log files. The
includepattern must match the layout under your log folder, and the Collector’s user must be able to read it.
Next steps
- Explore traces
- Metrics
- Create alert rules
- Python instrumentation for the code your tasks run