Skip to content

Flush in-memory OTel metrics at process shutdown#61808

Merged
potiuk merged 2 commits intoapache:mainfrom
xBis7:missing-metrics
Feb 13, 2026
Merged

Flush in-memory OTel metrics at process shutdown#61808
potiuk merged 2 commits intoapache:mainfrom
xBis7:missing-metrics

Conversation

@xBis7
Copy link
Copy Markdown
Contributor

@xBis7 xBis7 commented Feb 12, 2026

Issue

When using OpenTelemetry as the stat logger, all metrics are stored in-memory and exported to the collector in batches at fixed intervals.

Subprocesses like the task_runner, can be very short-lived and the result is that the process exits before it exports any metrics.

Solution

The solution is to register a hook that performs a force_flush() at shutdown.

All process forks so far are resetting their state just like here

https://github.com/apache/airflow/blob/main/task-sdk/src/airflow/sdk/execution_time/supervisor.py#L355

I tested it and the changes in the stats.py aren't used but any future forks that don't reset their parent's state, are going to result in missing metrics and it's going to be hard figuring out why. I think it's a good safe-guard to keep.

Tests

I tested the changes manually, added an integration test and a unit test.


Was generative AI tooling used to co-author this PR?
  • No

  • 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 or {issue_number}.significant.rst, in airflow-core/newsfragments.

Copy link
Copy Markdown
Contributor

@Nataneljpwd Nataneljpwd left a comment

Choose a reason for hiding this comment

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

Looks great!

@xBis7
Copy link
Copy Markdown
Contributor Author

xBis7 commented Feb 12, 2026

@Nataneljpwd Thanks for the review!

@jason810496 jason810496 self-requested a review February 13, 2026 11:02
@potiuk potiuk added this to the Airflow 3.1.8 milestone Feb 13, 2026
@potiuk potiuk merged commit a9df122 into apache:main Feb 13, 2026
71 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

Backport failed to create: v3-1-test. View the failure log Run details

Status Branch Result
v3-1-test Commit Link

You can attempt to backport this manually by running:

cherry_picker a9df122 v3-1-test

This should apply the commit to the v3-1-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

@xBis7
Copy link
Copy Markdown
Contributor Author

xBis7 commented Feb 13, 2026

@potiuk Thank you for the review and the merge!

@xBis7 xBis7 deleted the missing-metrics branch February 13, 2026 13:53
@potiuk
Copy link
Copy Markdown
Member

potiuk commented Feb 13, 2026

@potiuk Thank you for the review and the merge!

Would you try to backport it (see the instructions above - needs some conflict resolution) @xBis7

@xBis7
Copy link
Copy Markdown
Contributor Author

xBis7 commented Feb 13, 2026

@potiuk I resolved the conflicts. Now, if I understand correctly, I have to create a PR against the v3-1-test branch. Is that correct?

https://github.com/xBis7/airflow/tree/backport-a9df122-v3-1-test

Ratasa143 pushed a commit to Ratasa143/airflow that referenced this pull request Feb 15, 2026
* flush in-memory otel metrics at process shutdown

* fix module for test
potiuk pushed a commit that referenced this pull request Feb 17, 2026
…#61869)

* manually backport and resolve conflicts

* fix mypy-airflow-core error

* make package unit.core importable for the test subprocess
choo121600 pushed a commit to choo121600/airflow that referenced this pull request Feb 22, 2026
* flush in-memory otel metrics at process shutdown

* fix module for test
Subham-KRLX pushed a commit to Subham-KRLX/airflow that referenced this pull request Mar 4, 2026
* flush in-memory otel metrics at process shutdown

* fix module for test
vatsrahul1001 pushed a commit that referenced this pull request Mar 4, 2026
…#61869)

* manually backport and resolve conflicts

* fix mypy-airflow-core error

* make package unit.core importable for the test subprocess
dominikhei pushed a commit to dominikhei/airflow that referenced this pull request Mar 11, 2026
* flush in-memory otel metrics at process shutdown

* fix module for test
Ankurdeewan pushed a commit to Ankurdeewan/airflow that referenced this pull request Mar 15, 2026
* flush in-memory otel metrics at process shutdown

* fix module for test
radhwene pushed a commit to radhwene/airflow that referenced this pull request Mar 21, 2026
* flush in-memory otel metrics at process shutdown

* fix module for test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing Metrics After Migrating from StatsD to OpenTelemetry

3 participants