Skip to content

Commit db06cb8

Browse files
authored
Support of host.name in OTEL metrics and usage of OTEL_RESOURCE_ATTRIBUTES in metrics (apache#42428)
* fixes: 42425, and 42424 * fixed static type check failure
1 parent 9b29394 commit db06cb8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

airflow/metrics/otel_logger.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from opentelemetry.metrics import Observation
2929
from opentelemetry.sdk.metrics import MeterProvider
3030
from opentelemetry.sdk.metrics._internal.export import ConsoleMetricExporter, PeriodicExportingMetricReader
31-
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
31+
from opentelemetry.sdk.resources import HOST_NAME, SERVICE_NAME, Resource
3232

3333
from airflow.configuration import conf
3434
from airflow.exceptions import AirflowProviderDeprecationWarning
@@ -40,6 +40,7 @@
4040
get_validator,
4141
stat_name_otel_handler,
4242
)
43+
from airflow.utils.net import get_hostname
4344

4445
if TYPE_CHECKING:
4546
from opentelemetry.metrics import Instrument
@@ -410,7 +411,7 @@ def get_otel_logger(cls) -> SafeOtelLogger:
410411
debug = conf.getboolean("metrics", "otel_debugging_on")
411412
service_name = conf.get("metrics", "otel_service")
412413

413-
resource = Resource(attributes={SERVICE_NAME: service_name})
414+
resource = Resource.create(attributes={HOST_NAME: get_hostname(), SERVICE_NAME: service_name})
414415

415416
protocol = "https" if ssl_active else "http"
416417
endpoint = f"{protocol}://{host}:{port}/v1/metrics"

0 commit comments

Comments
 (0)