ferruzzi commented on code in PR #30873:
URL: https://github.com/apache/airflow/pull/30873#discussion_r1179502610


##########
airflow/metrics/otel_logger.py:
##########
@@ -0,0 +1,242 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import logging
+import random
+import warnings
+from typing import Callable
+
+from opentelemetry import metrics
+from opentelemetry.exporter.otlp.proto.http.metric_exporter import 
OTLPMetricExporter
+from opentelemetry.sdk.metrics import MeterProvider
+from opentelemetry.sdk.metrics._internal.export import ConsoleMetricExporter, 
PeriodicExportingMetricReader
+from opentelemetry.sdk.resources import SERVICE_NAME, Resource
+from opentelemetry.util.types import Attributes
+
+from airflow.configuration import conf
+from airflow.metrics.protocols import DeltaType, Timer, TimerProtocol
+from airflow.metrics.validators import AllowListValidator, validate_stat
+from airflow.utils.helpers import prune_dict
+
+log = logging.getLogger(__name__)
+
+
+# This is currently the only UDC used.  If more are added, we should add a 
better system for this.
+UP_DOWN_COUNTERS = {"airflow.dag_processing.processes"}
+OTEL_NAME_MAX_LENGTH = 63
+METRIC_NAME_PREFIX = "airflow."
+
+
+def _is_up_down_counter(name):
+    return name in UP_DOWN_COUNTERS
+
+
+class SafeOtelLogger:
+    """Otel Logger"""
+
+    def __init__(self, otel_provider, prefix: str = "airflow", 
allow_list_validator=AllowListValidator()):
+        self.otel: Callable = otel_provider
+        self.prefix: str = prefix
+        self.metrics_validator = allow_list_validator
+        self.meter = otel_provider.get_meter(__name__)
+        self.metrics_map = MetricsMap(self.meter)
+
+    @validate_stat
+    def incr(
+        self, stat: str, count: int = 1, rate: float = 1, tags: Attributes = 
None, *, back_compat_name: str
+    ):
+        """
+        Increment stat by count.
+
+        :param stat: The name of the stat to increment.
+        :param count: A positive integer to add to the current value of stat.
+        :param rate: Value between 0 and 1 representing the "percentage" of
+            the time to emit the metric where 1 = 100%.

Review Comment:
   Howard replied below 
   
   > Why not add ‘sampling rate’ instead of just ‘percentage?’ I think it might 
be more concise if we could describe it as “value between 0 and 1 that 
represents the sampled rate at which the metric is going to be emitted.”
   
   I like that.  I'll make the change.



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