Skip to content

Commit 9aa2903

Browse files
authored
fix: respect OTEL_EXPORTER_OTLP_ENDPOINT when setting trace/log/metrics endpoints (#732)
*Description of changes:* - Restore the `OTEL_EXPORTER_OTLP_ENDPOINT` guard that was dropped in #729 - When the base `OTEL_EXPORTER_OTLP_ENDPOINT` is set (e.g. to a local collector), skip defaulting `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` and `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` to the direct-to-AWS URLs so the OTel SDK honors the base URL
1 parent 1cf5ad1 commit 9aa2903

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_distro.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def _check_otel_version_compatibility():
9494
_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED as OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED,
9595
)
9696
from opentelemetry.sdk.environment_variables import (
97+
OTEL_EXPORTER_OTLP_ENDPOINT,
9798
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
9899
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
99100
OTEL_EXPORTER_OTLP_PROTOCOL,
@@ -206,16 +207,19 @@ def _configure(self, **kwargs):
206207
os.environ.setdefault("OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT", "true")
207208

208209
region = get_aws_region()
209-
if region:
210-
os.environ.setdefault(
211-
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, f"https://xray.{region}.amazonaws.com/v1/traces"
212-
)
213-
os.environ.setdefault(OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, f"https://logs.{region}.amazonaws.com/v1/logs")
214-
else:
215-
_logger.warning(
216-
"AWS region could not be determined. OTLP endpoints will not be automatically configured. "
217-
"Please set AWS_REGION environment variable or configure OTLP endpoints manually."
218-
)
210+
if not os.environ.get(OTEL_EXPORTER_OTLP_ENDPOINT):
211+
if region:
212+
os.environ.setdefault(
213+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, f"https://xray.{region}.amazonaws.com/v1/traces"
214+
)
215+
os.environ.setdefault(
216+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, f"https://logs.{region}.amazonaws.com/v1/logs"
217+
)
218+
else:
219+
_logger.warning(
220+
"AWS region could not be determined. OTLP endpoints will not be automatically configured. "
221+
"Please set AWS_REGION environment variable or configure OTLP endpoints manually."
222+
)
219223

220224
os.environ.setdefault(
221225
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS,

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelemetry_distro.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,11 @@ def test_agent_observability_respects_custom_disabled_instrumentations(self):
492492
disabled = os.environ.get(OTEL_PYTHON_DISABLED_INSTRUMENTATIONS, "")
493493
self.assertTrue(disabled.startswith("custom_lib"))
494494

495-
def test_base_otlp_endpoint_does_not_prevent_specific_endpoints(self):
495+
def test_base_otlp_endpoint_prevents_specific_endpoints(self):
496496
os.environ[OTEL_EXPORTER_OTLP_ENDPOINT] = "http://my-collector:4318"
497497
self._configure_with_agent_observability()
498-
self.assertIn(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, os.environ)
499-
self.assertIn(OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, os.environ)
498+
self.assertNotIn(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, os.environ)
499+
self.assertNotIn(OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, os.environ)
500500

501501
@staticmethod
502502
def _make_ep(name, dist_name=None):

0 commit comments

Comments
 (0)