Skip to content

Add optional debug spans for the scheduler loop#69809

Open
xBis7 wants to merge 1 commit into
apache:mainfrom
xBis7:scheduler-debug-spans
Open

Add optional debug spans for the scheduler loop#69809
xBis7 wants to merge 1 commit into
apache:mainfrom
xBis7:scheduler-debug-spans

Conversation

@xBis7

@xBis7 xBis7 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

This patch is adding a trace for every iteration of the scheduler loop and debug spans around all the major steps and queries.

Context

There is a config option for exporting debug traces.

https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/config_templates/config.yml#L1504-L1513

We used to export random spans for multiple methods of the scheduler but these spans were never grouped together under a common trace and also didn't have any meaningful attributes. They were providing little to no benefit while they were actually adding more noise. Eventually, all such spans were removed and the config option was deprecated as unused but kept around in case we wanted to try a different approach in the future.

So far we only have traces for dag_runs but there are some operations across the project that are worth tracking with spans. The spans could help us pin-point the root cause of performance issues and come up with appropriate solutions.

There have been a lot of discussions around scheduler performance, task starvation, etc. with no solid way of consistently reproducing the issues or identifying the exact pain points. The spans added in this patch could be a good 1st step towards improving the scheduler.

In the future, we could also add debug spans for the dag_processor or the triggerer or operations in the task-sdk.

Current changes + examples

I've added a new function with a start_as_current_span call guarded by the debug traces flag so that we can enable and disable the new traces (disabled by default).

The parent span for each iteration always starts as a root span and it has an attribute airflow.scheduler.loop_iteration.idle which can help us distinguish the iterations that actually did some work. We can use it to filter the spans and find the interesting ones.

image

Then we can sort by the longest first and start examining them

image

Not all iteration traces look the same. In the above example, this is the longest

image image

2nd longest

image image

3rd longest

image image

And we are also exposing various internal values. I've only added attributes that are available at the moment of the span and avoided doing any calculations that will add more load to the system.

image image

Testing

Apart from manual testing, I've added unit tests for the new start_debug_span function and an integration test that checks for certain spans that we can expect to consistently appear in every iteration.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Claude-code Opus 4.8


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@boring-cyborg boring-cyborg Bot added the area:Scheduler including HA (high availability) scheduler label Jul 13, 2026
@xBis7 xBis7 force-pushed the scheduler-debug-spans branch 2 times, most recently from 4d0a7e0 to 8a90ffb Compare July 13, 2026 12:55
@xBis7 xBis7 force-pushed the scheduler-debug-spans branch from 8a90ffb to ec98125 Compare July 13, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Scheduler including HA (high availability) scheduler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant