sortega commented on code in PR #68568:
URL: https://github.com/apache/airflow/pull/68568#discussion_r3436151629
##########
airflow-core/src/airflow/models/taskinstance.py:
##########
@@ -732,9 +734,29 @@ def __hash__(self):
@property
def stats_tags(self) -> dict[str, str]:
"""Returns task instance tags."""
- return prune_dict(
- {"dag_id": self.dag_id, "task_id": self.task_id, "team_name":
getattr(self, "_team_name", None)}
+ from sqlalchemy import inspect as sa_inspect
+
+ tags: dict[str, str] = {}
+ if conf.getboolean("metrics", "dag_tags_in_metrics", fallback=False):
+ try:
+ dr = self.dag_run # lazy="joined" — always in memory when TI
is loaded
+ if dr is not None and "dag_model" not in
sa_inspect(dr).unloaded:
+ dm = dr.dag_model
+ if dm is not None and "tags" not in
sa_inspect(dm).unloaded and dm.tags:
+ tags.update(build_dag_metric_tags(tag.name for tag in
dm.tags))
+ except SQLAlchemyError:
+ pass
+ # Built-in keys always win on collision.
+ tags.update(
+ prune_dict(
+ {
+ "dag_id": self.dag_id,
+ "task_id": self.task_id,
+ "team_name": getattr(self, "_team_name", None),
+ }
+ )
Review Comment:
It will increase cardinality but it's not noise, it's useful. You might want
to look at TI metrics excluding backfills
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]