如何使用Application Insights禁用Azure Function的采样

nwo49xxi  于 2023-05-23  发布在  其他
关注(0)|答案(1)|浏览(263)

我想禁用使用应用程序洞察的Azure函数的采样。我已经遵循了这些文档,但采样仍然启用。
Sampling in Application Insights
如何为Azure Functions配置监视
在Application Insights中,我使用以下查询来确定采样率:

  1. dependencies
  2. | where timestamp > ago(1d)
  3. | summarize RetainedPercentage = 100/avg(itemCount) by bin(timestamp, 1h)
  4. | order by timestamp desc

下面是我的host.json文件:

  1. {
  2. "version": "2.0",
  3. "logging": {
  4. "applicationInsights": {
  5. "LogLevel": {
  6. "default": "Information"
  7. },
  8. "samplingSettings": {
  9. "isEnabled": false
  10. }
  11. }
  12. }
  13. }

我也试过在代码中禁用采样:

  1. var aiOptions = new ApplicationInsightsServiceOptions
  2. {
  3. EnableAdaptiveSampling = false,
  4. InstrumentationKey = configuration.GetValue<string>("Telemetry:AppInsightsInstrumentationKey")
  5. };
  6. services.AddApplicationInsightsTelemetry(aiOptions);
8i9zcol2

8i9zcol21#

如MSDOC中所述,默认情况下将为Azure函数启用自适应采样。

将设置***isEnabled***更改为***false***,如下图所示:

您也可以通过在ConfigureServices方法中使用以下代码来禁用采样:

  1. public class Startup : FunctionsStartup
  2. {
  3. public override void Configure(IFunctionsHostBuilder builder)
  4. {
  5. var aiOptions = new ApplicationInsightsServiceOptions();
  6. aiOptions.EnableAdaptiveSampling = false;
  7. builder.Services.AddApplicationInsightsTelemetry(aiOptions);
  8. }
  9. }

运行以下查询以检查采样是否已禁用。RetainedPercentage应显示100%,如下所示:

  1. union requests,dependencies,pageViews,browserTimings,exceptions,traces
  2. | where timestamp > ago(1d)
  3. | summarize RetainedPercentage = 100/avg(itemCount) by bin(timestamp, 1h), itemType

响应:

如果有助于解决问题,请检查以下故障排除步骤:
1.更新host.json文件中的采样设置后,重新启动Azure Function。
1.还要验证您的代码并检查是否在Application Insights SDK配置中启用了采样。

展开查看全部

相关问题