Merge pull request #645 from Microsoft/cithomas/fixqpconfig
Make QuickPulse configurable by adding it to DI like all other modules
This commit is contained in:
Коммит
7fd14bd4ef
|
@ -12,6 +12,7 @@
|
|||
- [Added ability to remove any default Telemetry Module.](https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/633)
|
||||
- [TelemetryChannel is configured via DI, making it easier to override channel](https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/641)
|
||||
- [Fixed a bug which caused QuickPulse and Sampling to be enabled only if ServerTelemetryChannel was used](https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/642)
|
||||
- [QuickPulseTelemetryModule is constructed via DI, make it possible for users to configure it.] (https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/639)
|
||||
|
||||
## Version 2.2.1
|
||||
- Updated Web/Base SDK version dependency to 2.5.1 which addresses a bug.
|
||||
|
|
|
@ -140,6 +140,12 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.
|
|||
this.WriteEvent(11, moduleType, this.ApplicationName);
|
||||
}
|
||||
|
||||
[Event(12, Message = "Unable to find QuickPulseTelemetryModule in service collection. LiveMetrics feature will not be available. Please add QuickPulseTelemetryModule to services collection in the ConfigureServices method of your application Startup class.", Level = EventLevel.Error, Keywords = Keywords.Diagnostics)]
|
||||
public void UnableToFindQuickPulseModuleInDI(string appDomainName = "Incorrect")
|
||||
{
|
||||
this.WriteEvent(12, this.ApplicationName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Keywords for the AspNetEventSource.
|
||||
/// </summary>
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.DependencyCollector;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse;
|
||||
using Microsoft.ApplicationInsights.WindowsServer;
|
||||
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
@ -164,6 +165,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
#endif
|
||||
services.AddSingleton<ITelemetryModule, AppServicesHeartbeatTelemetryModule>();
|
||||
services.AddSingleton<ITelemetryModule, AzureInstanceMetadataTelemetryModule>();
|
||||
services.AddSingleton<ITelemetryModule, QuickPulseTelemetryModule>();
|
||||
services.AddSingleton<TelemetryConfiguration>(provider => provider.GetService<IOptions<TelemetryConfiguration>>().Value);
|
||||
|
||||
services.AddSingleton<ICorrelationIdLookupHelper>(provider => new CorrelationIdLookupHelper(() => provider.GetService<IOptions<TelemetryConfiguration>>().Value));
|
||||
|
|
|
@ -75,20 +75,18 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
foreach (ITelemetryProcessorFactory processorFactory in this.telemetryProcessorFactories)
|
||||
{
|
||||
configuration.TelemetryProcessorChainBuilder.Use(processorFactory.Create);
|
||||
}
|
||||
configuration.TelemetryProcessorChainBuilder.Build();
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to default channel (InMemoryChannel) created by base sdk if no channel is found in DI
|
||||
configuration.TelemetryChannel = this.telemetryChannel ?? configuration.TelemetryChannel;
|
||||
(configuration.TelemetryChannel as ITelemetryModule)?.Initialize(configuration);
|
||||
|
||||
this.AddQuickPulse(configuration);
|
||||
this.AddSampling(configuration);
|
||||
this.DisableHeartBeatIfConfigured();
|
||||
|
||||
(configuration.TelemetryChannel as ITelemetryModule)?.Initialize(configuration);
|
||||
|
||||
configuration.TelemetryProcessorChainBuilder.Build();
|
||||
|
||||
// Fallback to default channel (InMemoryChannel) created by base sdk if no channel is found in DI
|
||||
configuration.TelemetryChannel = this.telemetryChannel ?? configuration.TelemetryChannel;
|
||||
|
||||
configuration.TelemetryProcessorChainBuilder.Build();
|
||||
|
||||
if (this.applicationInsightsServiceOptions.DeveloperMode != null)
|
||||
{
|
||||
|
@ -121,20 +119,25 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
}
|
||||
|
||||
private void AddQuickPulse(TelemetryConfiguration configuration)
|
||||
{
|
||||
{
|
||||
if (this.applicationInsightsServiceOptions.EnableQuickPulseMetricStream)
|
||||
{
|
||||
var quickPulseModule = new QuickPulseTelemetryModule();
|
||||
quickPulseModule.Initialize(configuration);
|
||||
|
||||
QuickPulseTelemetryProcessor processor = null;
|
||||
configuration.TelemetryProcessorChainBuilder.Use((next) =>
|
||||
{
|
||||
QuickPulseTelemetryModule quickPulseModule = this.modules.FirstOrDefault(((module) => module.GetType() == typeof(QuickPulseTelemetryModule))) as QuickPulseTelemetryModule;
|
||||
if (quickPulseModule != null)
|
||||
{
|
||||
QuickPulseTelemetryProcessor processor = null;
|
||||
configuration.TelemetryProcessorChainBuilder.Use((next) =>
|
||||
{
|
||||
processor = new QuickPulseTelemetryProcessor(next);
|
||||
quickPulseModule.RegisterTelemetryProcessor(processor);
|
||||
return processor;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
processor = new QuickPulseTelemetryProcessor(next);
|
||||
quickPulseModule.RegisterTelemetryProcessor(processor);
|
||||
return processor;
|
||||
});
|
||||
}
|
||||
AspNetCoreEventSource.Instance.UnableToFindQuickPulseModuleInDI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSampling(TelemetryConfiguration configuration)
|
||||
|
|
|
@ -348,15 +348,24 @@ namespace Microsoft.Extensions.DependencyInjection.Test
|
|||
Assert.NotNull(modules);
|
||||
|
||||
#if NET46
|
||||
Assert.Equal(4, modules.Count());
|
||||
Assert.Equal(5, modules.Count());
|
||||
var perfCounterModule = services.FirstOrDefault<ServiceDescriptor>(t => t.ImplementationType == typeof(PerformanceCollectorModule));
|
||||
Assert.NotNull(perfCounterModule);
|
||||
#else
|
||||
Assert.Equal(3, modules.Count());
|
||||
Assert.Equal(4, modules.Count());
|
||||
#endif
|
||||
|
||||
var dependencyModuleDescriptor = services.FirstOrDefault<ServiceDescriptor>(t => t.ImplementationType == typeof(DependencyTrackingTelemetryModule));
|
||||
Assert.NotNull(dependencyModuleDescriptor);
|
||||
Assert.NotNull(dependencyModuleDescriptor);
|
||||
|
||||
var appServiceHeartBeatModuleDescriptor = services.FirstOrDefault<ServiceDescriptor>(t => t.ImplementationType == typeof(AppServicesHeartbeatTelemetryModule));
|
||||
Assert.NotNull(appServiceHeartBeatModuleDescriptor);
|
||||
|
||||
var azureMetadataHeartBeatModuleDescriptor = services.FirstOrDefault<ServiceDescriptor>(t => t.ImplementationType == typeof(AzureInstanceMetadataTelemetryModule));
|
||||
Assert.NotNull(azureMetadataHeartBeatModuleDescriptor);
|
||||
|
||||
var quickPulseModuleDescriptor = services.FirstOrDefault<ServiceDescriptor>(t => t.ImplementationType == typeof(QuickPulseTelemetryModule));
|
||||
Assert.NotNull(quickPulseModuleDescriptor);
|
||||
}
|
||||
[Fact]
|
||||
public static void RegistersTelemetryConfigurationFactoryMethodThatPopulatesDependencyCollectorWithDefaultValues()
|
||||
|
|
Загрузка…
Ссылка в новой задаче