使用ASP.NET Core库禁用Application Insights采样

Dav*_*New 12 asp.net-core-mvc azure-application-insights asp.net-core asp.net-core-1.0

我需要保留所有遥测,因为我们将其用于分析.

根据这篇文章,我可以运行以下Analytics查询来确定抽样率:

requests 
 | where timestamp > ago(1d)
 | summarize 100/avg(itemCount) by bin(timestamp, 1h) 
 | render areachart 
Run Code Online (Sandbox Code Playgroud)

结果显示一些严重抽样,特别是在白天只保留了约十分之一的项目:

采样

让我感到困惑的是,Azure Portal阻止采样设置为100%:

Azure门户洞察

也许这只反映了摄取采样?自适应采样仍可能在服务器上进行.

如何使用Application Insights的ASP.NET核心库完全禁用采样?(即Microsoft.ApplicationInsights.AspNetCore 1.0.2)

目前,这是我能找到的唯一配置,并且没有任何取样:

var appInsightsConfiguration = new ConfigurationBuilder()
    .AddApplicationInsightsSettings(
        developerMode: false,
        instrumentationKey: Configuration["ApplicationInsights:InstrumentationKey"])
    .Build();

services.AddApplicationInsightsTelemetry(appInsightsConfiguration);
Run Code Online (Sandbox Code Playgroud)

Asa*_*erg 8

您可以使用ApplicationInsightsServiceOptions类禁用采样.

一个用法示例:

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

services.AddApplicationInsightsTelemetry(Configuration, aiOptions);
Run Code Online (Sandbox Code Playgroud)

Application Insights ASP.NET Core Github文档页面中查看有关抽样的更多详细信息.

希望这可以帮助,

阿萨夫

  • 12 因素应用规则#3 规定:“在环境中存储配置”。改变环境的解决方案不能来自应用程序代码。我阅读了手册,看到人们评论使用“MaxTelemetryItemsPerSecond”,但似乎没有关于如何通过配置配置采样的具体示例。 (2认同)