Airflow has a native OpenTelemetry integration for traces and metrics, which involves creating
an exporter internally that sends data to the configured backend.
To configure Airflow to send data to Logfire, you'll need to:
Set the OTEL_EXPORTER_OTLP_HEADERS environment variable.
Configure the otel_* settings in the airflow.cfg file.
Warning
If your apache-airflow is older than 2.10.4, this section will not work for you.
In that case, go to the [Airflow with OpenTelemetry Collector] section.
[metrics]otel_on=Trueotel_host=logfire-api.pydantic.devotel_port=443otel_prefix=airflowotel_interval_milliseconds=30000# The interval between exports, defaults to 60000otel_ssl_active=True[traces]otel_on=Trueotel_host=logfire-api.pydantic.devotel_port=443otel_prefix=airflowotel_ssl_active=Trueotel_task_log_event=True
For more details, check airflow traces and metrics documentation.
The OpenTelemetry Collector is a vendor-agnostic agent that can collect traces and metrics from your applications and
send them to various backends.
In this case, we are interested in sending data to Logfire.
Note
Using a collector is an option when you are already sending data to a backend, but you want to migrate to Logfire.
Then you can configure the collector to send data to Logfire, as well as your current backend. This way you can
compare the data and ensure that everything is working as expected. Cool, right?
On your airflow.cfg file, add the following configuration:
airflow.cfg
[metrics]otel_on=Trueotel_host=localhostotel_port=4318otel_prefix=airflowotel_interval_milliseconds=30000# The interval between exports, defaults to 60000otel_ssl_active=False[traces]otel_on=Trueotel_host=localhostotel_port=4318otel_prefix=airflowotel_ssl_active=Falseotel_task_log_event=True