@@ -384,6 +384,87 @@ def test_exporter_is_internal(self):
384384 "Exporter class should be prefixed with underscore to indicate it's private/internal" ,
385385 )
386386
387+ def test_export_uses_domain_override_when_env_var_set (self ):
388+ """Test that domain override is used when A365_OBSERVABILITY_DOMAIN_OVERRIDE is set."""
389+ # Arrange
390+ override_domain = "override.example.com"
391+ import os
392+
393+ os .environ ["A365_OBSERVABILITY_DOMAIN_OVERRIDE" ] = override_domain
394+
395+ try :
396+ spans = [self ._create_mock_span ("override_test_span" )]
397+
398+ # Mock the PowerPlatformApiDiscovery class (should not be called when override is set)
399+ with patch (
400+ "microsoft_agents_a365.observability.core.exporters.agent365_exporter.PowerPlatformApiDiscovery"
401+ ) as mock_discovery_class :
402+ # Mock the _post_with_retries method
403+ with patch .object (
404+ self .exporter , "_post_with_retries" , return_value = True
405+ ) as mock_post :
406+ # Act
407+ result = self .exporter .export (spans )
408+
409+ # Assert
410+ self .assertEqual (result , SpanExportResult .SUCCESS )
411+ mock_post .assert_called_once ()
412+
413+ # Verify the call arguments - should use override domain
414+ args , kwargs = mock_post .call_args
415+ url , body , headers = args
416+
417+ self .assertIn (override_domain , url )
418+ self .assertIn ("/maven/agent365/agents/test-agent-456/traces" , url )
419+
420+ # Verify PowerPlatformApiDiscovery was not instantiated
421+ mock_discovery_class .assert_not_called ()
422+
423+ finally :
424+ # Cleanup
425+ del os .environ ["A365_OBSERVABILITY_DOMAIN_OVERRIDE" ]
426+
427+ def test_export_uses_default_domain_when_no_override (self ):
428+ """Test that default domain resolution is used when no override is set."""
429+ # Arrange
430+ import os
431+
432+ # Ensure override is not set
433+ if "A365_OBSERVABILITY_DOMAIN_OVERRIDE" in os .environ :
434+ del os .environ ["A365_OBSERVABILITY_DOMAIN_OVERRIDE" ]
435+
436+ spans = [self ._create_mock_span ("default_domain_span" )]
437+
438+ # Mock the PowerPlatformApiDiscovery class
439+ with patch (
440+ "microsoft_agents_a365.observability.core.exporters.agent365_exporter.PowerPlatformApiDiscovery"
441+ ) as mock_discovery_class :
442+ mock_discovery = Mock ()
443+ mock_discovery .get_tenant_island_cluster_endpoint .return_value = "default-endpoint.com"
444+ mock_discovery_class .return_value = mock_discovery
445+
446+ # Mock the _post_with_retries method
447+ with patch .object (self .exporter , "_post_with_retries" , return_value = True ) as mock_post :
448+ # Act
449+ result = self .exporter .export (spans )
450+
451+ # Assert
452+ self .assertEqual (result , SpanExportResult .SUCCESS )
453+ mock_post .assert_called_once ()
454+
455+ # Verify the call arguments - should use default domain
456+ args , kwargs = mock_post .call_args
457+ url , body , headers = args
458+
459+ self .assertIn ("default-endpoint.com" , url )
460+ self .assertIn ("/maven/agent365/agents/test-agent-456/traces" , url )
461+
462+ # Verify PowerPlatformApiDiscovery was called
463+ mock_discovery_class .assert_called_once_with ("test" )
464+ mock_discovery .get_tenant_island_cluster_endpoint .assert_called_once_with (
465+ "test-tenant-123"
466+ )
467+
387468
388469if __name__ == "__main__" :
389470 unittest .main ()
0 commit comments