vandonr-amz commented on code in PR #31725:
URL: https://github.com/apache/airflow/pull/31725#discussion_r1222214760


##########
airflow/metrics/otel_logger.py:
##########
@@ -83,10 +95,45 @@ def name_is_otel_safe(prefix: str, name: str) -> bool:
     return bool(stat_name_otel_handler(prefix, name, 
max_length=OTEL_NAME_MAX_LENGTH))
 
 
+def _type_as_str(obj: Instrument) -> str:
+    """
+    Given an OpenTelemetry Instrument, returns the type of instrument as a 
string.
+
+    type() will return something like: <class 
'opentelemetry.sdk.metrics._internal.instrument._Counter'>
+    This extracts that down to just "Counter" (or "Gauge" or whatever) for 
cleaner logging purposes.

Review Comment:
   This kind of "technical explanation" is very nice to have, but I think it 
should be in a `#` comment and not in the docstring



##########
airflow/metrics/otel_logger.py:
##########
@@ -235,6 +301,57 @@ def del_counter(self, name: str, attributes: Attributes = 
None) -> None:
         if key in self.map.keys():
             del self.map[key]
 
+    def set_value(self, name: str, value: float, delta: bool, tags: 
Attributes):
+        """
+        Overrides the last reading for a Gauge with a new value.
+
+        :param name: The name of the gauge to record.
+        :param value: The new reading to record.
+        :param delta: If True, value is added to the previous reading, else it 
overrides.
+        :param tags: Gauge attributes which were used to generate a unique key 
to store the counter.
+        :returns: None
+        """
+        key: str = _generate_key_name(name, tags)
+        old_value = self.poke_gauge(name, tags)
+        # If delta is true, add the new value to the last reading otherwise 
overwrite it.
+        self.map[key] = Observation(value + (delta * old_value), tags)

Review Comment:
   oh wow because `True == 1` ? And the type checkers don't say anything ? 😱 



##########
airflow/metrics/otel_logger.py:
##########
@@ -83,10 +95,45 @@ def name_is_otel_safe(prefix: str, name: str) -> bool:
     return bool(stat_name_otel_handler(prefix, name, 
max_length=OTEL_NAME_MAX_LENGTH))
 
 
+def _type_as_str(obj: Instrument) -> str:
+    """
+    Given an OpenTelemetry Instrument, returns the type of instrument as a 
string.
+
+    type() will return something like: <class 
'opentelemetry.sdk.metrics._internal.instrument._Counter'>
+    This extracts that down to just "Counter" (or "Gauge" or whatever) for 
cleaner logging purposes.
+
+    :param obj: An OTel Instrument or subclass
+    :returns: The type() of the Instrument without all the nested class info
+    """
+    return str(type(obj)).split(".")[-1][1:-2]

Review Comment:
   that's a lot of twisting, wdyt of using `type(obj).__name__[1:]` ?



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