potiuk commented on code in PR #37989:
URL: https://github.com/apache/airflow/pull/37989#discussion_r1557402237


##########
airflow/providers/opentelemetry/hooks/otel.py:
##########
@@ -0,0 +1,421 @@
+# 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 inspect
+import logging
+import os
+import random
+from typing import TYPE_CHECKING, Any
+
+from opentelemetry import metrics, trace
+from opentelemetry.exporter.otlp.proto.http.metric_exporter import 
OTLPMetricExporter
+from opentelemetry.exporter.otlp.proto.http.trace_exporter import 
OTLPSpanExporter
+from opentelemetry.sdk.metrics import MeterProvider
+from opentelemetry.sdk.metrics._internal.export import 
PeriodicExportingMetricReader
+from opentelemetry.sdk.resources import HOST_NAME, SERVICE_NAME, Resource
+from opentelemetry.sdk.trace import TracerProvider
+from opentelemetry.sdk.trace.export import SimpleSpanProcessor
+from opentelemetry.sdk.trace.id_generator import IdGenerator
+from opentelemetry.trace import NonRecordingSpan, TraceFlags
+
+from airflow.configuration import conf
+from airflow.exceptions import AirflowException
+from airflow.hooks.base import BaseHook
+from airflow.metrics.otel_logger import SafeOtelLogger
+from airflow.providers.opentelemetry.models import (
+    EMPTY_SPAN,
+    EMPTY_TIMER,
+)
+from airflow.providers.opentelemetry.util import (
+    gen_span_id,
+    gen_trace_id,
+)
+from airflow.utils.log.logging_mixin import LoggingMixin
+from airflow.utils.net import get_hostname
+
+if TYPE_CHECKING:
+    from opentelemetry.trace import Span, Tracer
+    from opentelemetry.util.types import Attributes
+
+    from airflow.metrics.protocols import DeltaType, TimerProtocol
+    from airflow.models import TaskInstance
+    from airflow.providers.opentelemetry.models import EmptySpan
+
+log = logging.getLogger(__name__)
+
+
+def is_otel_traces_enabled() -> bool:
+    """Check whether either core otel traces is enabled."""
+    return conf.has_option("traces", "otel_on") and conf.getboolean("traces", 
"otel_on") is True
+
+
+def is_otel_metrics_enabled() -> bool:
+    """Check whether either core otel metrics is enabled."""
+    return conf.has_option("metrics", "otel_on") and 
conf.getboolean("metrics", "otel_on") is True
+
+
+def is_listener_enabled() -> bool:
+    """Check whether otel listener is disabled."""
+    return (
+        is_otel_traces_enabled() is not True
+        and os.getenv("OTEL_LISTENER_DISABLED", "false").lower() == "false"

Review Comment:
   I think this should be a provider-specific configuration in provider.yaml 
rather than environment variable in [opentelemetry] section



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