ramitkataria commented on code in PR #57215:
URL: https://github.com/apache/airflow/pull/57215#discussion_r2467527178


##########
airflow-core/src/airflow/models/callback.py:
##########
@@ -131,26 +136,42 @@ class Callback(Base):
     trigger_id: Mapped[int] = mapped_column(Integer, ForeignKey("trigger.id"), 
nullable=True)
     trigger = relationship("Trigger", back_populates="callback", uselist=False)
 
-    def __init__(self, priority_weight: int = 1):
+    def __init__(self, priority_weight: int = 1, prefix: str = "", **kwargs):
         self.state = CallbackState.PENDING
         self.priority_weight = priority_weight
+        self.data = kwargs  # kwargs can be used to include additional info in 
metric tags
+        if prefix:
+            self.data["prefix"] = prefix
 
     def queue(self):
         self.state = CallbackState.QUEUED
 
+    def get_metric_info(self, status: str, result: Any) -> dict:
+        tags = {"result": result, **self.data}
+        tags.pop("prefix", None)
+
+        if "kwargs" in tags:
+            # Remove the context (if exists) to keep the tags simple
+            tags["kwargs"] = {k: v for k, v in tags["kwargs"].items() if k != 
"context"}
+
+        prefix = self.data.get("prefix", "")
+        name = f"{prefix}.callback_{status}" if prefix else 
f"callback_{status}"

Review Comment:
   The way it is right now, I've assumed that you would always want a `.` when 
a prefix is included so I've made it so that you don't need to include the `.` 
in the prefix parameter. If no prefix is included, the `.` is also not included 
(in the `else` case). However, I'm not too opinionated about this and would be 
happy to change if you prefer that the caller include the `.`



-- 
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]

Reply via email to