ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

EnableAdaptiveSampling with "excludedTypes" not taking effect

Open Jithesh-Menon opened this issue 2 years ago • 8 comments

List of NuGet packages and version that you are using: Microsoft.ApplicationInsights 2.20.0 Microsoft.ApplicationInsights.WorkerService 2.20.0 and Microsoft.Extensions.DependencyInjection 6.0.0 Microsoft.Extensions.DependencyInjection.Abstractions 6.0.0 Microsoft.Identity.Client.Desktop 4.41.0 System.Runtime.CompilerServices.Unsafe 6.0.0

Runtime version (e.g. net461, net48, netcoreapp2.1, netcoreapp3.1, etc. You can find this information from the *.csproj file): NetFramework4.7.2

Hosting environment (e.g. Azure Web App, App Service on Linux, Windows, Ubuntu, etc.): Windows

Describe the bug

Attempting to use the default setting of EnableAdaptiveSampling - true and setting exclude types has not had the desired effect. i.e, trying to exclude the "Dependency" from the app insights logging [and also tried with "Request"] still logs details into app insights for the cloud role instance (my machine) that the app is running on.

Referred the below links :- Configuring adaptive sampling for ASP.NET applications https://github.com/toddkitta/azure-content/blob/master/articles/application-insights/app-insights-sampling.md

Approach:- Configure adaptive sampling in code EnableDependencyTrackingTelemetryModule and EnableAdaptiveSampling settings set to true

 var telemetryConfig = serviceProvider.GetRequiredService<TelemetryConfiguration>();

  var builder = telemetryConfig.DefaultTelemetrySink.TelemetryProcessorChainBuilder;

  // Alternately, the following configures adaptive sampling with 5 items per second, and also excludes
  // DependencyTelemetry from being subject to sampling.
  builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5, excludedTypes: "Dependency");

  builder.Build();

But the above approach didn't reflect and does provide results for KQL query.

union requests,dependencies,pageViews,browserTimings,exceptions,traces
| where cloud_RoleInstance contains "MyMachine"
and timestamp >= todatetime('2022-04-04T12:19:00.775Z') 
and timestamp <= todatetime('2022-04-04T12:22:13.538Z')

Please check and advise.

Thank you.

Jithesh-Menon avatar Apr 04 '22 14:04 Jithesh-Menon

Please share a minimal repro application demonstrating the issue. its not clear how are you concluding "not taking effect". code sample, along with the actual queries used to validate if sampling is done would help us understand the question better.

cijothomas avatar Apr 08 '22 00:04 cijothomas

https://docs.microsoft.com/en-us/azure/azure-monitor/app/sampling#knowing-whether-sampling-is-in-operation

cijothomas avatar Apr 08 '22 00:04 cijothomas

Hi @cijothomas ,

In my query I have explained what I am trying to do with code sample and the query I used to see the results in app insights.

I was trying to reduce the traffic into app insights by excluding the "Dependency". I have also tried the same approach for "Request" as well. As I mentioned in my query, I am using a .Net Framework 4.7.2 application and trying to make the best out of app insights settings options.

Pasting the code approach I did from the query section for your convenience.

Approach:- Configure adaptive sampling in code EnableDependencyTrackingTelemetryModule and EnableAdaptiveSampling settings set to true

 var telemetryConfig = serviceProvider.GetRequiredService<TelemetryConfiguration>();

  var builder = telemetryConfig.DefaultTelemetrySink.TelemetryProcessorChainBuilder;

  // Alternately, the following configures adaptive sampling with 5 items per second, and also excludes
  // DependencyTelemetry from being subject to sampling.
  builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5, excludedTypes: "Dependency");

  builder.Build();

Irrespective of the sampling exclude types settings I provided Dependency/Request are still post details into app insights for the cloud role instance (my machine) that the app is running on.

Kindly advise.

Thank you

Jithesh-Menon avatar Apr 08 '22 09:04 Jithesh-Menon

app insights by excluding the "Dependency"

ExcludedTypes in UseAdaptiveSampling - means just the opposite. i.e Dependency items are NOT considered for sampling, means they are always sent. You want the opposite, based on your description.

cijothomas avatar Apr 08 '22 13:04 cijothomas

Thank you!

So, how could we ensure the Dependency is not considered for sampling while it is present in application insights logs.

Could you please advise?

Jithesh-Menon avatar Apr 08 '22 13:04 Jithesh-Menon

// Alternately, the following configures adaptive sampling with 5 items per second, and also excludes // DependencyTelemetry from being subject to sampling. builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5, excludedTypes: "Dependency");

cijothomas avatar Apr 08 '22 14:04 cijothomas

// Alternately, the following configures adaptive sampling with 5 items per second, and also excludes // DependencyTelemetry from being subject to sampling. builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5, excludedTypes: "Dependency");

This code will ensure Dependency is being excluded from Sampling. But how could we verify it got excluded..? Could you please provide a clarification on that..?

Jithesh-Menon avatar Apr 08 '22 14:04 Jithesh-Menon

// Alternately, the following configures adaptive sampling with 5 items per second, and also excludes // DependencyTelemetry from being subject to sampling. builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5, excludedTypes: "Dependency");

This code will ensure Dependency is being excluded from Sampling. But how could we verify it got excluded..? Could you please provide a clarification on that..?

https://docs.microsoft.com/en-us/azure/azure-monitor/app/sampling#knowing-whether-sampling-is-in-operation

cijothomas avatar Apr 22 '22 15:04 cijothomas

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Feb 17 '23 00:02 github-actions[bot]

i tried to exclude the following types in ApplicationInsights.config from sampling image

after more than 1 day i run the query to confirm, request type is still sampled. image

anyone know if there is anything wrong? thank you

tlsun0921 avatar Apr 27 '23 17:04 tlsun0921