xBis7 commented on code in PR #74046:
URL: https://github.com/apache/airflow/pull/74046#discussion_r4336630031
##########
task-sdk/src/airflow/sdk/observability/metrics/otel_logger.py:
##########
@@ -16,16 +16,38 @@
# under the License.
from __future__ import annotations
+import os
from typing import TYPE_CHECKING
+from opentelemetry.sdk.resources import SERVICE_INSTANCE_ID
+
from airflow.sdk._shared.observability.metrics import otel_logger
+from airflow.sdk._shared.observability.otel_env_config import
load_metrics_env_config
from airflow.sdk.configuration import conf
if TYPE_CHECKING:
from airflow.sdk._shared.observability.metrics.otel_logger import
SafeOtelLogger
-def get_otel_logger() -> SafeOtelLogger:
+def get_otel_logger(short_lived: bool = False) -> SafeOtelLogger:
+ service_instance_id = None
+ temporality_preference_env =
"OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE"
+
+ if short_lived:
+ # The temporality env variable defaults to `CUMULATIVE` if unset.
+ # If the process is `short_lived`, then set the default fallback to
`DELTA`.
+ os.environ.setdefault(temporality_preference_env, "DELTA")
+
+ # Check the value of the env variable because the user could have
defined it as `CUMULATIVE`.
+ # LOWMEMORY also exports counters and histograms as deltas.
+ if (
+ os.environ[temporality_preference_env].strip().upper() in
("DELTA", "LOWMEMORY")
+ and SERVICE_INSTANCE_ID not in
load_metrics_env_config().resource_attributes
Review Comment:
@dstandish See here, if the service instance id isn't provided by the user,
then we set a fixed value.
--
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]