diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLoggerOptions.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLoggerOptions.cs index 778025afd..0793ba900 100644 --- a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLoggerOptions.cs +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/ApplicationInsightsLoggerOptions.cs @@ -99,6 +99,21 @@ public TimeSpan QuickPulseInitializationDelay { /// public bool EnableDependencyTracking { get; set; } = true; + /// + /// Gets or sets the endpoint address for the telemetry channel + /// + public string EndpointAddress { get; set; } + + /// + /// Gets or sets the Profile Query Endpoint for the Application Id Provider + /// + public string ProfileQueryEndpoint { get; set; } + + /// + /// Gets or sets the Quick Pulse Service Endpoint for the Quick Pulse Telemetry Module + /// + public string QuickPulseServiceEndpoint { get; set; } + /// /// Gets or sets HTTP request collection options. /// @@ -163,7 +178,10 @@ public string Format() { nameof(HttpAutoCollectionOptions), httpOptions }, { nameof(LiveMetricsInitializationDelay), LiveMetricsInitializationDelay }, { nameof(EnableLiveMetrics), EnableLiveMetrics }, - { nameof(EnableDependencyTracking), EnableDependencyTracking } + { nameof(EnableDependencyTracking), EnableDependencyTracking }, + { nameof(EndpointAddress), EndpointAddress }, + { nameof(ProfileQueryEndpoint), ProfileQueryEndpoint }, + { nameof(QuickPulseServiceEndpoint), QuickPulseServiceEndpoint } }; return options.ToString(Formatting.Indented); diff --git a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Extensions/ApplicationInsightsServiceCollectionExtensions.cs b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Extensions/ApplicationInsightsServiceCollectionExtensions.cs index ce532c6b7..3638fcf60 100644 --- a/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Extensions/ApplicationInsightsServiceCollectionExtensions.cs +++ b/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Extensions/ApplicationInsightsServiceCollectionExtensions.cs @@ -57,7 +57,19 @@ public static IServiceCollection AddApplicationInsights(this IServiceCollection services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); + + services.AddSingleton(provider => + { + ApplicationInsightsLoggerOptions options = provider.GetService>().Value; + if (!string.IsNullOrEmpty(options.QuickPulseServiceEndpoint)) + { + return new QuickPulseTelemetryModule + { + QuickPulseServiceEndpoint = options.QuickPulseServiceEndpoint + }; + } + return new QuickPulseTelemetryModule(); + }); services.AddSingleton(provider => { @@ -85,7 +97,18 @@ public static IServiceCollection AddApplicationInsights(this IServiceCollection return NullTelemetryModule.Instance; }); - services.AddSingleton(); + services.AddSingleton(provider => + { + ApplicationInsightsLoggerOptions options = provider.GetService>().Value; + if (!string.IsNullOrEmpty(options.ProfileQueryEndpoint)) + { + return new ApplicationInsightsApplicationIdProvider + { + ProfileQueryEndpoint = options.ProfileQueryEndpoint + }; + } + return new ApplicationInsightsApplicationIdProvider(); + }); services.AddSingleton(provider => { @@ -134,7 +157,19 @@ public static IServiceCollection AddApplicationInsights(this IServiceCollection services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(provider => + { + ApplicationInsightsLoggerOptions options = provider.GetService>().Value; + if (!string.IsNullOrEmpty(options.EndpointAddress)) + { + return new ServerTelemetryChannel + { + EndpointAddress = options.EndpointAddress + }; + } + return new ServerTelemetryChannel(); + }); + services.AddSingleton(provider => { ApplicationInsightsLoggerOptions options = provider.GetService>().Value; diff --git a/test/Microsoft.Azure.WebJobs.Host.EndToEndTests/ApplicationInsights/ApplicationInsightsEndToEndTests.cs b/test/Microsoft.Azure.WebJobs.Host.EndToEndTests/ApplicationInsights/ApplicationInsightsEndToEndTests.cs index 8f524b9c1..9a6d1fabe 100644 --- a/test/Microsoft.Azure.WebJobs.Host.EndToEndTests/ApplicationInsights/ApplicationInsightsEndToEndTests.cs +++ b/test/Microsoft.Azure.WebJobs.Host.EndToEndTests/ApplicationInsights/ApplicationInsightsEndToEndTests.cs @@ -98,7 +98,7 @@ private IHost ConfigureHost(LogLevel minLevel = LogLevel.Information, HttpAutoCo }) .ConfigureServices(services => { - ServiceDescriptor quickPulse = services.Single(s => s.ImplementationType == typeof(QuickPulseTelemetryModule)); + ServiceDescriptor quickPulse = services.Single(s => s.ServiceType.Name == nameof(QuickPulseTelemetryModule)); services.Remove(quickPulse); services.AddSingleton(s => new QuickPulseTelemetryModule() { diff --git a/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/ApplicationInsightsConfigurationTests.cs b/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/ApplicationInsightsConfigurationTests.cs index 1618d944c..59cf162fb 100644 --- a/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/ApplicationInsightsConfigurationTests.cs +++ b/test/Microsoft.Azure.WebJobs.Host.UnitTests/Loggers/ApplicationInsightsConfigurationTests.cs @@ -500,6 +500,37 @@ public void DependencyInjectionConfiguration_ConfiguresActiveOnlyOnce() } } + [Fact] + public void DependencyInjectionConfiguration_ConfiguresEndpoints() + { + var endpointAddress = "http://endpoint.address.com/"; + var quickPulseServiceEndpoint = "http://quickpulse.serviceendpoint.com/"; + var profileQueryEndpoint = "http://profile.queryendpoint.com/"; + using (var host = new HostBuilder() + .ConfigureLogging(b => + { + b.AddApplicationInsightsWebJobs(o => + { + o.EndpointAddress = endpointAddress; + o.QuickPulseServiceEndpoint = quickPulseServiceEndpoint; + o.ProfileQueryEndpoint = profileQueryEndpoint; + }); + }) + .Build()) + { + var config = host.Services.GetService(); + + Assert.Equal(endpointAddress, config.TelemetryChannel.EndpointAddress); + + Assert.IsType(config.ApplicationIdProvider); + Assert.Equal(profileQueryEndpoint, ((ApplicationInsightsApplicationIdProvider)config.ApplicationIdProvider).ProfileQueryEndpoint); + + var modules = host.Services.GetServices().ToList(); + var quickPulseTelemetryModule = modules.OfType().Single(); + Assert.Equal(quickPulseServiceEndpoint, quickPulseTelemetryModule.QuickPulseServiceEndpoint); + } + } + [Fact] public void CreateFilterOptions_MinLevel() {