Disable Application Insights sampling with the ASP.NET Core libraries

asp.net-core, asp.net-core-1.0, asp.net-core-mvc, azure-application-insights

Solution

You can disable sampling by using the ApplicationInsightsServiceOptions class.

A usage example:

var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
aiOptions.EnableAdaptiveSampling = false;

services.AddApplicationInsightsTelemetry(Configuration, aiOptions);

See more details about sampling in the Application Insights ASP.NET Core Github documentation page.

Hope this helps,

Asaf

Problem

I need to retain all telemetry since we use this for analytics. According to this article I can run the following Analytics query to determine the rate of sampling: ``` requests | where timestamp > ago(1d) | summarize 100/avg(itemCount) by bin(timestamp, 1h) | render areachart ``` The results indicate some heavily sampling, especially during the day where only around 1 in 10 items are retained: What confuses me is that the Azure Portal insdicates that sampling is set to 100%: Perhaps this only reflects Ingestion sampling? Adaptive sampling could still be occurring on the server. How do I disable sampling completely using the ASP.NET Core libraries for Application Insights? (i.e. Microsoft.ApplicationInsights.AspNetCore 1.0.2) Currently, this is these are the only configuration I can find and there isn't anything on sampling: ``` var appInsightsConfiguration = new ConfigurationBuilder() .AddApplicationInsightsSettings( developerMode: false, instrumentationKey: Configuration["ApplicationInsights:InstrumentationKey"]) .Build(); services.AddApplicationInsightsTelemetry(appInsightsConfiguration); ```

Original source