Skip to content

Commit 8d94cb5

Browse files
committed
fix unsampled span export to fall back to OTEL_EXPORTER_OTLP_ENDPOINT
1 parent e3e14cf commit 8d94cb5

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,19 @@ def _export_unsampled_span_for_agent_observability(trace_provider: TracerProvide
330330
if not is_agent_observability_enabled():
331331
return
332332

333-
traces_endpoint = os.environ.get(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT)
334-
if traces_endpoint and _is_aws_otlp_endpoint(traces_endpoint, XRAY_SERVICE):
333+
traces_endpoint = os.environ.get(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) or os.environ.get(
334+
"OTEL_EXPORTER_OTLP_ENDPOINT"
335+
)
336+
if not traces_endpoint:
337+
return
338+
339+
if _is_aws_otlp_endpoint(traces_endpoint, XRAY_SERVICE):
335340
endpoint, region = _extract_endpoint_and_region_from_otlp_endpoint(traces_endpoint)
336341
span_exporter = _create_aws_otlp_exporter(endpoint=endpoint, service=XRAY_SERVICE, region=region)
342+
else:
343+
span_exporter = OTLPSpanExporter(endpoint=traces_endpoint)
337344

338-
trace_provider.add_span_processor(BatchUnsampledSpanProcessor(span_exporter=span_exporter))
345+
trace_provider.add_span_processor(BatchUnsampledSpanProcessor(span_exporter=span_exporter))
339346

340347

341348
def _is_defer_to_workers_enabled():

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,18 @@ def test_export_unsampled_span_for_agent_observability(self):
11021102
os.environ.pop("AGENT_OBSERVABILITY_ENABLED", None)
11031103
os.environ.pop("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", None)
11041104

1105+
mock_tracer_provider.reset_mock()
1106+
1107+
os.environ["AGENT_OBSERVABILITY_ENABLED"] = "true"
1108+
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "http://localhost:4318"
1109+
_export_unsampled_span_for_agent_observability(mock_tracer_provider, Resource.get_empty())
1110+
self.assertEqual(mock_tracer_provider.add_span_processor.call_count, 1)
1111+
processor = mock_tracer_provider.add_span_processor.call_args_list[0].args[0]
1112+
self.assertIsInstance(processor, BatchUnsampledSpanProcessor)
1113+
1114+
os.environ.pop("AGENT_OBSERVABILITY_ENABLED", None)
1115+
os.environ.pop("OTEL_EXPORTER_OTLP_ENDPOINT", None)
1116+
11051117
# pylint: disable=no-self-use
11061118
def test_export_unsampled_span_for_agent_observability_uses_aws_exporter(self):
11071119
"""Test that OTLPAwsSpanExporter is used for AWS endpoints"""

0 commit comments

Comments
 (0)