This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new db06cb8e89 Support of host.name in OTEL metrics and usage of 
OTEL_RESOURCE_ATTRIBUTES in metrics (#42428)
db06cb8e89 is described below

commit db06cb8e893addeef4d49479beb1f2387fa63993
Author: Howard Yoo <[email protected]>
AuthorDate: Tue Oct 1 02:04:06 2024 -0500

    Support of host.name in OTEL metrics and usage of OTEL_RESOURCE_ATTRIBUTES 
in metrics (#42428)
    
    * fixes: 42425, and 42424
    
    * fixed static type check failure
---
 airflow/metrics/otel_logger.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/airflow/metrics/otel_logger.py b/airflow/metrics/otel_logger.py
index 14080eb2d8..6d7d6e8fff 100644
--- a/airflow/metrics/otel_logger.py
+++ b/airflow/metrics/otel_logger.py
@@ -28,7 +28,7 @@ from opentelemetry.exporter.otlp.proto.http.metric_exporter 
import OTLPMetricExp
 from opentelemetry.metrics import Observation
 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.sdk.resources import HOST_NAME, SERVICE_NAME, Resource
 
 from airflow.configuration import conf
 from airflow.exceptions import AirflowProviderDeprecationWarning
@@ -40,6 +40,7 @@ from airflow.metrics.validators import (
     get_validator,
     stat_name_otel_handler,
 )
+from airflow.utils.net import get_hostname
 
 if TYPE_CHECKING:
     from opentelemetry.metrics import Instrument
@@ -410,7 +411,7 @@ def get_otel_logger(cls) -> SafeOtelLogger:
     debug = conf.getboolean("metrics", "otel_debugging_on")
     service_name = conf.get("metrics", "otel_service")
 
-    resource = Resource(attributes={SERVICE_NAME: service_name})
+    resource = Resource.create(attributes={HOST_NAME: get_hostname(), 
SERVICE_NAME: service_name})
 
     protocol = "https" if ssl_active else "http"
     endpoint = f"{protocol}://{host}:{port}/v1/metrics"

Reply via email to