Skip to content

Commit

Permalink
Support of host.name in OTEL metrics and usage of OTEL_RESOURCE_ATTRI…
Browse files Browse the repository at this point in the history
…BUTES in metrics (apache#42428)

* fixes: 42425, and 42424

* fixed static type check failure
  • Loading branch information
howardyoo authored Oct 1, 2024
1 parent 9b29394 commit db06cb8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions airflow/metrics/otel_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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
Expand All @@ -40,6 +40,7 @@
get_validator,
stat_name_otel_handler,
)
from airflow.utils.net import get_hostname

if TYPE_CHECKING:
from opentelemetry.metrics import Instrument
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit db06cb8

Please sign in to comment.