@@ -201,6 +201,42 @@ def test_configure_uses_existing_tracer_provider(self, mock_get_provider, mock_i
201201 self .assertIn ("_EnrichingBatchSpanProcessor" , processor_types )
202202 self .assertIn ("SpanProcessor" , processor_types )
203203
204+ class TestOTLPExporterConfiguration (unittest .TestCase ):
205+ """Test suite for OTLP exporter configuration based on environment variables."""
206+
207+ @patch ("microsoft_agents_a365.observability.core.config.OTLPSpanExporter" )
208+ @patch ("microsoft_agents_a365.observability.core.config.is_agent365_exporter_enabled" , return_value = False )
209+ @patch ("microsoft_agents_a365.observability.core.config.TelemetryManager._instance" , None )
210+ @patch .dict ("os.environ" , {"OTEL_EXPORTER_OTLP_ENDPOINT" : "http://localhost:4318" }, clear = True )
211+ def test_otlp_exporter_initialized_when_env_var_set (
212+ self , mock_is_enabled , mock_otlp_exporter
213+ ):
214+ """Test that OTLPSpanExporter is initialized when OTEL_EXPORTER_OTLP_ENDPOINT is set."""
215+
216+ result = configure (
217+ service_name = "test-service" ,
218+ service_namespace = "test-namespace" ,
219+ )
220+
221+ self .assertTrue (result , "configure() should return True" )
222+ mock_otlp_exporter .assert_called_once ()
223+
224+ @patch ("microsoft_agents_a365.observability.core.config.OTLPSpanExporter" )
225+ @patch ("microsoft_agents_a365.observability.core.config.is_agent365_exporter_enabled" , return_value = False )
226+ @patch ("microsoft_agents_a365.observability.core.config.TelemetryManager._instance" , None )
227+ @patch .dict ("os.environ" , {}, clear = True )
228+ def test_otlp_exporter_not_initialized_when_env_var_not_set (
229+ self , mock_is_enabled , mock_otlp_exporter
230+ ):
231+ """Test that OTLPSpanExporter is NOT initialized when OTEL_EXPORTER_OTLP_ENDPOINT is not set."""
232+
233+ result = configure (
234+ service_name = "test-service" ,
235+ service_namespace = "test-namespace" ,
236+ )
237+
238+ self .assertTrue (result , "configure() should return True" )
239+ mock_otlp_exporter .assert_not_called ()
204240
205241if __name__ == "__main__" :
206242 unittest .main ()
0 commit comments