From d819ab2309e78e996367f2841e7b651606f1137f Mon Sep 17 00:00:00 2001 From: Steve Liu Date: Thu, 23 Apr 2026 12:32:58 -0700 Subject: [PATCH] fix: respect OTEL_EXPORTER_OTLP_ENDPOINT when setting trace/log endpoints When OTEL_EXPORTER_OTLP_ENDPOINT is set, skip defaulting the specific trace and log endpoint vars so the base URL is honored by the OTel SDK. This was a regression from #729 which dropped the guard. --- .../distro/aws_opentelemetry_distro.py | 24 +++++++++++-------- .../distro/test_aws_opentelemetry_distro.py | 6 ++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_distro.py b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_distro.py index 516e265fd..df0f69ab1 100644 --- a/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_distro.py +++ b/aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_distro.py @@ -94,6 +94,7 @@ def _check_otel_version_compatibility(): _OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED as OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, ) from opentelemetry.sdk.environment_variables import ( + OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION, OTEL_EXPORTER_OTLP_PROTOCOL, @@ -206,16 +207,19 @@ def _configure(self, **kwargs): os.environ.setdefault("OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT", "true") region = get_aws_region() - if region: - os.environ.setdefault( - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, f"https://xray.{region}.amazonaws.com/v1/traces" - ) - os.environ.setdefault(OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, f"https://logs.{region}.amazonaws.com/v1/logs") - else: - _logger.warning( - "AWS region could not be determined. OTLP endpoints will not be automatically configured. " - "Please set AWS_REGION environment variable or configure OTLP endpoints manually." - ) + if not os.environ.get(OTEL_EXPORTER_OTLP_ENDPOINT): + if region: + os.environ.setdefault( + OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, f"https://xray.{region}.amazonaws.com/v1/traces" + ) + os.environ.setdefault( + OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, f"https://logs.{region}.amazonaws.com/v1/logs" + ) + else: + _logger.warning( + "AWS region could not be determined. OTLP endpoints will not be automatically configured. " + "Please set AWS_REGION environment variable or configure OTLP endpoints manually." + ) os.environ.setdefault( OTEL_PYTHON_DISABLED_INSTRUMENTATIONS, diff --git a/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py index f1e929d7c..845ec16b8 100644 --- a/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py +++ b/aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py @@ -492,11 +492,11 @@ def test_agent_observability_respects_custom_disabled_instrumentations(self): disabled = os.environ.get(OTEL_PYTHON_DISABLED_INSTRUMENTATIONS, "") self.assertTrue(disabled.startswith("custom_lib")) - def test_base_otlp_endpoint_does_not_prevent_specific_endpoints(self): + def test_base_otlp_endpoint_prevents_specific_endpoints(self): os.environ[OTEL_EXPORTER_OTLP_ENDPOINT] = "http://my-collector:4318" self._configure_with_agent_observability() - self.assertIn(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, os.environ) - self.assertIn(OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, os.environ) + self.assertNotIn(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, os.environ) + self.assertNotIn(OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, os.environ) @staticmethod def _make_ep(name, dist_name=None):