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

rom pushed a commit to branch v2-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v2-10-test by this push:
     new 50546724a6 Support of host.name in OTEL metrics and usage of 
OTEL_RESOURCE_ATTRIBUTES in metrics (#42428) (#42604)
50546724a6 is described below

commit 50546724a6895eb9c8fb00081c1c39b9af16bedd
Author: Jarek Potiuk <[email protected]>
AuthorDate: Tue Oct 1 06:07:33 2024 -0700

    Support of host.name in OTEL metrics and usage of OTEL_RESOURCE_ATTRIBUTES 
in metrics (#42428) (#42604)
    
    * fixes: 42425, and 42424
    
    * fixed static type check failure
    
    (cherry picked from commit db06cb8e893addeef4d49479beb1f2387fa63993)
    
    Co-authored-by: Howard Yoo <[email protected]>
---
 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 4d6f1c725e..00f539754e 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.metrics.protocols import Timer
@@ -39,6 +39,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
@@ -398,7 +399,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