This is an automated email from the ASF dual-hosted git repository.
amoghdesai pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new d2780f41f41 Expose Stats in sdk API and handle core backcompat (#61810)
d2780f41f41 is described below
commit d2780f41f41476db2e6d3c1e59f55dfef14c6082
Author: Amogh Desai <[email protected]>
AuthorDate: Fri Feb 13 11:47:09 2026 +0530
Expose Stats in sdk API and handle core backcompat (#61810)
---
airflow-core/.pre-commit-config.yaml | 1 +
airflow-core/src/airflow/observability/stats.py | 22 ++++++++++++++++++
airflow-core/src/airflow/stats.py | 31 +++++++++++++++++++++++++
contributing-docs/05_pull_requests.rst | 12 ++--------
task-sdk/src/airflow/sdk/observability/stats.py | 24 +++++++++++++++++++
5 files changed, 80 insertions(+), 10 deletions(-)
diff --git a/airflow-core/.pre-commit-config.yaml
b/airflow-core/.pre-commit-config.yaml
index f1bb1de4425..c3b869761a2 100644
--- a/airflow-core/.pre-commit-config.yaml
+++ b/airflow-core/.pre-commit-config.yaml
@@ -362,6 +362,7 @@ repos:
^src/airflow/models/taskmixin\.py$|
^src/airflow/models/taskreschedule\.py$|
^src/airflow/models/trigger\.py$|
+ ^src/airflow/stats\.py$|
^src/airflow/models/variable\.py$|
^src/airflow/models/xcom\.py$|
^src/airflow/models/xcom_arg\.py$|
diff --git a/airflow-core/src/airflow/observability/stats.py
b/airflow-core/src/airflow/observability/stats.py
new file mode 100644
index 00000000000..6caf6d93b1f
--- /dev/null
+++ b/airflow-core/src/airflow/observability/stats.py
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Re-exports from airflow._shared.observability.metrics.stats for
compatibility."""
+
+from __future__ import annotations
+
+from airflow._shared.observability.metrics.stats import Stats as Stats
diff --git a/airflow-core/src/airflow/stats.py
b/airflow-core/src/airflow/stats.py
new file mode 100644
index 00000000000..950728fcbbd
--- /dev/null
+++ b/airflow-core/src/airflow/stats.py
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Deprecated module - Stats moved to airflow.observability.stats but we have
to retain compat."""
+
+from __future__ import annotations
+
+import warnings
+
+from airflow.sdk.observability.stats import Stats as Stats
+from airflow.utils.deprecation_tools import DeprecatedImportWarning
+
+warnings.warn(
+ "Importing from 'airflow.stats' is deprecated. Please use
'airflow.sdk.observability.stats' instead.",
+ DeprecatedImportWarning,
+ stacklevel=2,
+)
diff --git a/contributing-docs/05_pull_requests.rst
b/contributing-docs/05_pull_requests.rst
index 8ce5a8d47d9..9cd06059ffc 100644
--- a/contributing-docs/05_pull_requests.rst
+++ b/contributing-docs/05_pull_requests.rst
@@ -308,11 +308,7 @@ will be timed and submitted automatically:
.. code-block:: python
- # If importing from airflow-core
- from airflow._shared.observability.metrics.stats import Stats
-
- # Else if importing from task-sdk
- from airflow.sdk._shared.observability.metrics.stats import Stats
+ from airflow.sdk.observability.stats import Stats
...
@@ -323,11 +319,7 @@ or to time but not send a metric:
.. code-block:: python
- # If importing from airflow-core
- from airflow._shared.observability.metrics.stats import Stats
-
- # Else if importing from task-sdk
- from airflow.sdk._shared.observability.metrics.stats import Stats
+ from airflow.sdk.observability.stats import Stats
...
diff --git a/task-sdk/src/airflow/sdk/observability/stats.py
b/task-sdk/src/airflow/sdk/observability/stats.py
new file mode 100644
index 00000000000..40452fbcaaa
--- /dev/null
+++ b/task-sdk/src/airflow/sdk/observability/stats.py
@@ -0,0 +1,24 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Stats module - re-exports from
airflow.sdk._shared.observability.metrics.stats."""
+
+from __future__ import annotations
+
+from airflow.sdk._shared.observability.metrics.stats import Stats,
normalize_name_for_stats
+
+__all__ = ["Stats", "normalize_name_for_stats"]