Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public void UnableToFindModuleToConfigure(string moduleType, string appDomainNam
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -164,6 +165,7 @@ public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCo
#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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,18 @@ public void Configure(TelemetryConfiguration configuration)
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)
{
Expand Down Expand Up @@ -121,20 +119,25 @@ public void Configure(TelemetryConfiguration configuration)
}

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,24 @@ public static void RegistersTelemetryConfigurationFactoryMethodThatPopulatesItWi
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()
Expand Down