jedcunningham commented on code in PR #31859:
URL: https://github.com/apache/airflow/pull/31859#discussion_r1228942632


##########
airflow/metrics/otel_logger.py:
##########
@@ -131,6 +131,29 @@ def _skip_due_to_rate(rate: float) -> bool:
     return rate < 1 and random.random() > rate
 
 
+class _OtelTimer(Timer):
+    """
+    An implementation of Stats.Timer() which records the result in the OTel 
Metrics Map.
+    OpenTelemetry does not have a native timer, we will store the values as a 
Gauge.
+
+    :param name: The name of the timer.
+    :param tags: Tags to append to the timer.
+    """
+
+    def __init__(self, otel_logger, name, tags):

Review Comment:
   Can we add some typing here?



##########
airflow/metrics/otel_logger.py:
##########
@@ -233,27 +255,32 @@ def gauge(
         if self.metrics_validator.test(stat):
             self.metrics_map.set_gauge_value(full_name(prefix=self.prefix, 
name=stat), value, delta, tags)
 
-    @validate_stat
     def timing(
         self,
         stat: str,
         dt: DeltaType,
         *,
         tags: Attributes = None,
     ) -> None:
-        warnings.warn(f"Create timer {stat}: OpenTelemetry Timers are not yet 
implemented.")
+        """
+        OpenTelemetry does not have a native timer, we will store
+        them as a Gauge whose value represents the seconds elapsed.
+        """
+        if self.metrics_validator.test(stat) and 
name_is_otel_safe(self.prefix, stat):
+            if isinstance(dt, datetime.timedelta):
+                dt = dt.total_seconds()
+            self.metrics_map.set_gauge_value(full_name(prefix=self.prefix, 
name=stat), float(dt), False, tags)
         return None

Review Comment:
   ```suggestion
   ```
   
   We can get rid of this too.



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