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 3 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
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 expected module {0} in service collection.", Level = EventLevel.Warning, Keywords = Keywords.Diagnostics)]
public void UnableToFindExpectedModule(string moduleType, string appDomainName = "Incorrect")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this message more specific. So customer will know that without this QuickPulse wouldn't work. Generic message doesn't help.

Also promote it to Error so support of customer screwed up config and not able to see live metrics would be easier

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
this.WriteEvent(12, moduleType, 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.UnableToFindExpectedModule(nameof(QuickPulseTelemetryModule));
}
}
}

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