From e83258aef49ade73011c0940eb241c6559ae38a2 Mon Sep 17 00:00:00 2001 From: JhontSouth Date: Wed, 11 Sep 2024 09:54:18 -0500 Subject: [PATCH] disable adaptive sampling --- .../Extensions/ServiceCollectionExtensions.cs | 1 + .../ServiceCollectionExtensions.cs | 30 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive.Runtime/Extensions/ServiceCollectionExtensions.cs b/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive.Runtime/Extensions/ServiceCollectionExtensions.cs index b0ec9fab9b..34446c5420 100644 --- a/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive.Runtime/Extensions/ServiceCollectionExtensions.cs +++ b/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive.Runtime/Extensions/ServiceCollectionExtensions.cs @@ -209,6 +209,7 @@ internal static void AddBotRuntimeTelemetry(this IServiceCollection services, IC } else { + telemetrySettings.Options.EnableAdaptiveSampling = false; services.AddApplicationInsightsTelemetry(telemetrySettings.Options); services.TryAddSingleton(); diff --git a/libraries/integration/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core/ServiceCollectionExtensions.cs b/libraries/integration/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core/ServiceCollectionExtensions.cs index 0c208542df..4e68b8ac68 100644 --- a/libraries/integration/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core/ServiceCollectionExtensions.cs +++ b/libraries/integration/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core/ServiceCollectionExtensions.cs @@ -57,7 +57,14 @@ public static IServiceCollection AddBotApplicationInsights(this IServiceCollecti IBotTelemetryClient telemetryClient = null; if (appInsightService != null) { - services.AddApplicationInsightsTelemetry(appInsightService.InstrumentationKey); + // Create Application Insights options and disable adaptive sampling + var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions + { + EnableAdaptiveSampling = false, + InstrumentationKey = appInsightService.InstrumentationKey + }; + + services.AddApplicationInsightsTelemetry(aiOptions); telemetryClient = new BotTelemetryClient(new TelemetryClient()); } else @@ -88,9 +95,19 @@ public static IServiceCollection AddBotApplicationInsights(this IServiceCollecti CreateBotTelemetry(services); IBotTelemetryClient telemetryClient = null; + if (!string.IsNullOrWhiteSpace(instrumentationKey)) { - services.AddApplicationInsightsTelemetry(instrumentationKey); + // Create Application Insights options and disable adaptive sampling + var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions + { + EnableAdaptiveSampling = false, + InstrumentationKey = instrumentationKey + }; + + // Add Application Insights telemetry with custom options + services.AddApplicationInsightsTelemetry(aiOptions); + telemetryClient = new BotTelemetryClient(new TelemetryClient()); } else @@ -122,7 +139,14 @@ public static IServiceCollection AddBotApplicationInsights(this IServiceCollecti // Start Application Insights if (instrumentationKey != null) { - services.AddApplicationInsightsTelemetry(instrumentationKey); + // Create Application Insights options and disable adaptive sampling + var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions + { + EnableAdaptiveSampling = false, + InstrumentationKey = instrumentationKey + }; + + services.AddApplicationInsightsTelemetry(aiOptions); } // Register the BotTelemetryClient