ferruzzi commented on code in PR #30873: URL: https://github.com/apache/airflow/pull/30873#discussion_r1178510321
########## airflow/metrics/otel_logger.py: ########## @@ -0,0 +1,234 @@ +# 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 warnings +from typing import Callable + +from opentelemetry import metrics +from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter +from opentelemetry.metrics import Instrument +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 + +# This is currently the only UDC used. If more are added, we should add a better system for this. Review Comment: Generally a counter is monotonic (can only go up) but OpenTelemetry has an UpDownCounter which, I'm sure you can guess, is non-monotonic; it can go up or down. The choice here is to either drop this metric and implement the rest as monotonic Counters, implement all counters as UpDownCounters, or add a bit of logic to do it intelligently. The catch is that the Collector which transmits these metrics to the upstream dashboard tools (Prometheus, Grafana, etc) assigns the type of `gauge` to any UDC instead of Counter. Adding this logic feels like the best solution so normal counters still get `typed` correctly and we don't lose an existing metric. OTel docs for [Counters](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#counter-creation) and [UDC](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#updowncounter) -- 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]
