sortega commented on code in PR #68568:
URL: https://github.com/apache/airflow/pull/68568#discussion_r3436035032
##########
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:
There is a subtlety related to the _team attribute. I suppose teams cannot
differ between dagrun and ti but that would break the expectation (and unit
test) about using _team in this class.
The other differences are that this has `task_id` but the other doesn't and
`dag_run.stats_tags` having `run_type`, which I don't think it would hurt to
have here.
--
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]