diff --git a/CHANGELOG.md b/CHANGELOG.md index 43407ff8dd..eecfd09217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Update AppInsights JS snippet used in the code to [latest version](https://github.com/microsoft/ApplicationInsights-JS) - [ServerTelemetryChannel does not fall back to any default directory if user explicitly configures StorageFolder, and have trouble read/write to it](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2002) - [Fixed a bug which caused ApplicationInsights.config file being read for populating TelemetryConfiguration in .NET Core projects](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1795) +- [Remove System.RunTime EventCounters by default](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2009) ## Version 2.15.0-beta2 - [Read all properties of ApplicationInsightsServiceOptions from IConfiguration](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1882) diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs index 58088449f7..a085df0c55 100644 --- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs +++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs @@ -133,10 +133,6 @@ public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCo AddCommonTelemetryModules(services); AddTelemetryChannel(services); -#if NETSTANDARD2_0 - ConfigureEventCounterModuleWithSystemCounters(services); -#endif - services.TryAddSingleton, DefaultApplicationInsightsServiceConfigureOptions>(); diff --git a/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs index 363a5075e7..4790a4e9d3 100644 --- a/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs +++ b/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs @@ -95,8 +95,6 @@ public static IServiceCollection AddApplicationInsightsTelemetryWorkerService(th AddCommonTelemetryModules(services); AddTelemetryChannel(services); - ConfigureEventCounterModuleWithSystemCounters(services); - services .TryAddSingleton, DefaultApplicationInsightsServiceConfigureOptions>(); diff --git a/NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs b/NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs index aa7f64be82..bbc35f99ec 100644 --- a/NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs +++ b/NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs @@ -230,7 +230,7 @@ public static IConfigurationBuilder AddApplicationInsightsSettings( /// /// Read configuration from appSettings.json, appsettings.{env.EnvironmentName}.json, - /// IConfiguation used in an application and EnvironmentVariables. + /// IConfiguation used in an application and EnvironmentVariables. /// Bind configuration to ApplicationInsightsServiceOptions. /// Values can also be read from environment variables to support azure web sites configuration. /// @@ -286,7 +286,7 @@ internal static void AddTelemetryConfiguration( } /// - /// The AddSingleton method will not check if a class has already been added as an ImplementationType. + /// The AddSingleton method will not check if a class has already been added as an ImplementationType. /// This extension method is to encapsulate those checks. /// /// @@ -402,61 +402,6 @@ private static void AddAndConfigureDependencyTracking(IServiceCollection service }); } -#if NETSTANDARD2_0 - private static void AddEventCounterIfNotExist(EventCounterCollectionModule eventCounterModule, string eventSource, string eventCounterName) - { - if (!eventCounterModule.Counters.Any(req => req.EventSourceName.Equals(eventSource, StringComparison.Ordinal) && req.EventCounterName.Equals(eventCounterName, StringComparison.Ordinal))) - { - eventCounterModule.Counters.Add(new EventCounterCollectionRequest(eventSource, eventCounterName)); - } - } - - private static void ConfigureEventCounterModuleWithSystemCounters(IServiceCollection services) - { - services.ConfigureTelemetryModule((eventCounterModule, options) => - { - if (options.EnableEventCounterCollectionModule) - { - // Ref this code for actual names. https://github.com/dotnet/coreclr/blob/dbc5b56c48ce30635ee8192c9814c7de998043d5/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSource.cs - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "cpu-usage"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "working-set"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "gc-heap-size"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "gen-0-gc-count"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "gen-1-gc-count"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "gen-2-gc-count"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "time-in-gc"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "gen-0-size"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "gen-1-size"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "gen-2-size"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "loh-size"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "alloc-rate"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "assembly-count"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "exception-count"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "threadpool-thread-count"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "monitor-lock-contention-count"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "threadpool-queue-length"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "threadpool-completed-items-count"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForSystemRuntime, "active-timer-count"); - } - }); - } - - private static void ConfigureEventCounterModuleWithAspNetCounters(IServiceCollection services) - { - services.ConfigureTelemetryModule((eventCounterModule, options) => - { - if (options.EnableEventCounterCollectionModule) - { - // Ref this code for actual names. https://github.com/aspnet/AspNetCore/blob/f3f9a1cdbcd06b298035b523732b9f45b1408461/src/Hosting/Hosting/src/Internal/HostingEventSource.cs - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForAspNetCoreHosting, "requests-per-second"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForAspNetCoreHosting, "total-requests"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForAspNetCoreHosting, "current-requests"); - AddEventCounterIfNotExist(eventCounterModule, EventSourceNameForAspNetCoreHosting, "failed-requests"); - } - }); - } -#endif - [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "services parameter is used in only NetStandard 2.0 build.")] private static void AddApplicationInsightsLoggerProvider(IServiceCollection services) { diff --git a/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests/AddApplicationInsightsTelemetryTests.cs b/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests/AddApplicationInsightsTelemetryTests.cs index bba445b35b..de08c53c91 100644 --- a/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests/AddApplicationInsightsTelemetryTests.cs +++ b/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests/AddApplicationInsightsTelemetryTests.cs @@ -657,14 +657,9 @@ public static void RegistersTelemetryConfigurationFactoryMethodThatPopulatesEven var telemetryConfiguration = serviceProvider.GetTelemetryConfiguration(); var eventCounterModule = modules.OfType().Single(); - //VALIDATE - Assert.Equal(19, eventCounterModule.Counters.Count); - - // sanity check with a sample counter. - var cpuCounterRequest = eventCounterModule.Counters.FirstOrDefault( - eventCounterCollectionRequest => eventCounterCollectionRequest.EventSourceName == "System.Runtime" - && eventCounterCollectionRequest.EventCounterName == "cpu-usage"); - Assert.NotNull(cpuCounterRequest); + // VALIDATE + // By default, no counters are collected. + Assert.Equal(0, eventCounterModule.Counters.Count); } #endif diff --git a/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/ExtensionsTest.cs b/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/ExtensionsTest.cs index 06803bb606..6c8c134010 100644 --- a/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/ExtensionsTest.cs +++ b/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/ExtensionsTest.cs @@ -393,29 +393,19 @@ public void VerifyAddAIWorkerServiceSetsUpDefaultConfigurationAndModules() [Fact] public static void RegistersTelemetryConfigurationFactoryMethodThatPopulatesEventCounterCollectorWithDefaultListOfCounters() { - //ARRANGE + // ARRANGE var services = new ServiceCollection(); services.AddApplicationInsightsTelemetryWorkerService(); - //ACT + // ACT IServiceProvider serviceProvider = services.BuildServiceProvider(); var modules = serviceProvider.GetServices(); var telemetryConfiguration = serviceProvider.GetRequiredService(); var eventCounterModule = modules.OfType().Single(); - //VALIDATE - Assert.Equal(19, eventCounterModule.Counters.Count); - - // sanity check with a sample counter. - var cpuCounterRequest = eventCounterModule.Counters.FirstOrDefault( - eventCounterCollectionRequest => eventCounterCollectionRequest.EventSourceName == "System.Runtime" - && eventCounterCollectionRequest.EventCounterName == "cpu-usage"); - Assert.NotNull(cpuCounterRequest); - - // sanity check - no asp.net counters should be added - var aspnetCounterRequest = eventCounterModule.Counters.FirstOrDefault( - eventCounterCollectionRequest => eventCounterCollectionRequest.EventSourceName == "Microsoft.AspNetCore.Hosting"); - Assert.Null(aspnetCounterRequest); + // VALIDATE + // By default, no counters are collected. + Assert.Equal(0, eventCounterModule.Counters.Count); } [Fact]