nickstenning commented on code in PR #62436:
URL: https://github.com/apache/airflow/pull/62436#discussion_r2852925750
##########
shared/observability/src/airflow_shared/observability/metrics/otel_logger.py:
##########
@@ -386,6 +387,81 @@ def atexit_register_metrics_flush():
atexit.register(flush_otel_metrics)
+def get_otel_data_exporter(
+ *,
+ otel_env_config: OtelEnvConfig,
+ host: str | None = None,
+ port: int | None = None,
+ ssl_active: bool = False,
+) -> SpanExporter | MetricExporter:
+ protocol = "https" if ssl_active else "http"
+
+ # According to the OpenTelemetry Spec, specific config options like
'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT'
+ # take precedence over generic ones like 'OTEL_EXPORTER_OTLP_ENDPOINT'.
+ env_exporter_protocol = (
+ otel_env_config.type_specific_exporter_protocol or
otel_env_config.exporter_protocol
+ )
+ env_endpoint = otel_env_config.type_specific_endpoint or
otel_env_config.base_endpoint
+
+ # If the protocol env var isn't set, then it will be None,
+ # and it will default to an http/protobuf exporter.
+ if env_endpoint and env_exporter_protocol == "grpc":
+ from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import
OTLPMetricExporter
+ from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import
OTLPSpanExporter
+ else:
+ from opentelemetry.exporter.otlp.proto.http.metric_exporter import
OTLPMetricExporter
+ from opentelemetry.exporter.otlp.proto.http.trace_exporter import
OTLPSpanExporter
+
+ if env_endpoint:
+ if host is not None and port is not None:
+ log.warning(
+ "Both the standard OpenTelemetry environment variables and "
+ "the Airflow OpenTelemetry configs have been provided. "
+ "Using the OpenTelemetry environment variables. "
+ "The Airflow configs have been deprecated and will be removed
in the future."
+ )
+
+ endpoint_str = env_endpoint
+ # The SDK will pick up all the values from the environment.
+ if otel_env_config.data_type == OtelDataType.TRACES:
+ exporter = OTLPSpanExporter()
+ else:
+ exporter = OTLPMetricExporter()
+ else:
+ if host is None or port is None:
+ # Since the configs have been deprecated, host and port could be
None.
+ # Log a warning to steer the user towards configuring the
environment variables
+ # and deliberately let it fail here without providing fallbacks.
+ log.warning(
+ "OpenTelemetry %s have been enabled but the endpoint settings
haven't been configured. "
+ "The Airflow configs have been deprecated and will be removed
in the future. "
+ "Configure the standard OpenTelemetry environment variables
instead. "
+ "For more info, check the docs.",
+ otel_env_config.data_type.value,
+ )
+ else:
+ log.warning(
+ "The Airflow OpenTelemetry configs have been deprecated and
will be removed in the future. "
+ "OpenTelemetry is advised to be configured using the standard
environment variables. "
Review Comment:
```suggestion
"Configure the standard OpenTelemetry environment variables
instead. "
```
--
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]