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

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.

@xBis7
xBis7 force-pushed the scheduler-debug-spans branch 3 times, most recently from 8a90ffb to ec98125 Compare July 13, 2026 20:23
@xBis7

xBis7 commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor Author

I've been running load tests using the debug spans from this PR. Based on the investigation so far, I'm planning to add some more spans to this patch. I'll push all the changes once I'm confident that there isn't any value in monitoring deeper levels of each iteration.

I'm going to convert this to a draft.

@xBis7
xBis7 marked this pull request as draft July 21, 2026 11:35
@xBis7
xBis7 force-pushed the scheduler-debug-spans branch from ec98125 to 4afffd3 Compare July 22, 2026 11:58
@xBis7
xBis7 force-pushed the scheduler-debug-spans branch 3 times, most recently from 9587ea7 to fd043e8 Compare August 3, 2026 16:14
@xBis7
xBis7 marked this pull request as ready for review August 3, 2026 16:14
@xBis7

xBis7 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

I've added some extra spans that provided valuable information during my testing and I've re-opened this PR.

@xBis7
xBis7 force-pushed the scheduler-debug-spans branch 2 times, most recently from b93a4d2 to c0caf88 Compare August 18, 2026 16:47

@Miretpl Miretpl left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my current knowledge, changes look mostly ok. Having traces in the scheduler and different components would make several things easier and possible, as we could base our decisions on actual data.

I'm not sure we can skip introducing the new task-sdk import in core.

Have you done any performance testing on what is the potential impact of these changes and debug mode enabling?

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

Probably we would want to have an opt-in option list-like scheduler, dag processor that would enable debug only for scheduler and dag processor components.

@xBis7

xBis7 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@Miretpl Thank you for taking a look at this PR!

Have you done any performance testing on what is the potential impact of these changes and debug mode enabling?

Yes, I have and and the difference is negligible.

I don't expect people to have the spans turned on all the time, but to enable them after a performance incident so that they can investigate.

Probably we would want to have an opt-in option list-like scheduler, dag processor that would enable debug only for scheduler and dag processor components.

Yes, a filter list is a good idea if we add spans for mulitple components.

@Miretpl

Miretpl commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

I don't expect people to have the spans turned on all the time, but to enable them after a performance incident so that they can investigate.

Same. It is always good to know that potential debug mode will not degrade performance to the level that the environment will not meet certain performance criteria, especially if that is a production environment.

@xBis7
xBis7 force-pushed the scheduler-debug-spans branch from c0caf88 to 1ae0900 Compare September 7, 2026 10:05
@xBis7
xBis7 force-pushed the scheduler-debug-spans branch from 1ae0900 to b36a98b Compare September 14, 2026 11:04
@xBis7
xBis7 force-pushed the scheduler-debug-spans branch 3 times, most recently from 9459d10 to 27c3612 Compare September 24, 2026 19:00
@ashb

ashb commented Sep 24, 2026

Copy link
Copy Markdown
Member

@dstandish Please can you weigh in on this one?

@manish1337 manish1337 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on the spans, a couple of thoughts on the flag plumbing

Comment thread airflow-core/src/airflow/settings.py Resolved
@xBis7

xBis7 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

@manish1337 Thank you for the review! I've addressed your comments. Please take a look and let me know what you think

@manish1337

Copy link
Copy Markdown
Contributor

Thanks! Agreed on settings.py, replied on the test thread.

@xBis7
xBis7 force-pushed the scheduler-debug-spans branch from 27c3612 to 0090783 Compare September 25, 2026 14:20
@xBis7
xBis7 force-pushed the scheduler-debug-spans branch 2 times, most recently from 0134c98 to 5be2774 Compare September 30, 2026 13:48
@xBis7
xBis7 force-pushed the scheduler-debug-spans branch 2 times, most recently from a849f24 to d28ad52 Compare October 8, 2026 11:59
@xBis7
xBis7 force-pushed the scheduler-debug-spans branch 4 times, most recently from 4ef2825 to 9ed78f0 Compare October 21, 2026 17:39
@xBis7
xBis7 force-pushed the scheduler-debug-spans branch from 9ed78f0 to a97099a Compare November 11, 2026 15:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants