【问题标题】:Azure WebJobs - How to disable adaptive sampling for application insights?Azure WebJobs - 如何为应用程序洞察禁用自适应采样?
【发布时间】:2022-01-06 12:18:23
【问题描述】:

我在为各种类型的应用配置 AppInsights 采样时遇到了 this MSDN article。

但是我找不到为 azure webjobs 配置它的方法。

在为 WebJob 配置 appinsights 时,它看起来像这样 (MSDN):

static async Task Main()
{
    var builder = new HostBuilder();
    builder.UseEnvironment(EnvironmentName.Development);
    builder.ConfigureWebJobs(b =>
            {
                b.AddAzureStorageCoreServices();
                b.AddAzureStorage();
            });
    builder.ConfigureLogging((context, b) =>
            {
                b.AddConsole();

                // If the key exists in settings, use it to enable Application Insights.
                string instrumentationKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
                if (!string.IsNullOrEmpty(instrumentationKey))
                {
                    b.AddApplicationInsightsWebJobs(o => o.InstrumentationKey = instrumentationKey);
                }
            });
    var host = builder.Build();
    using (host)
    {
        await host.RunAsync();
    }
}

相关代码为:

b.AddApplicationInsightsWebJobs(o => o.InstrumentationKey = instrumentationKey);

选项本身如下:

是否可以禁用自适应采样?

非常感谢任何帮助。谢谢!

【问题讨论】:

    标签: azure azure-application-insights azure-webjobs


    【解决方案1】:

    是否可以禁用自适应采样?

    您可以通过进入 ApplicationInsights.config 文件,并删除或注释 AdaptiveSamplingTelemetryProcessor 节点。

    <TelemetryProcessors>
    
    <!-- Disable adaptive sampling:
      <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
        <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
      </Add>
    -->
    

    【讨论】:

    • 这不适用于 .Net Core,因为没有 .config 文件了。
    【解决方案2】:

    最简单的方法是将SamplingSettings属性设置为null:

    .ConfigureLogging((loggingContext, builder) =>
    {
        builder.AddConsole();
        builder.AddApplicationInsightsWebJobs(o =>
        {
            o.SamplingSettings = null;
        });
    })
    

    这可以防止将AdaptiveSamplingTelemetryProcessor 添加到遥测处理器列表中。

    您可以通过查看TelemetryClient.TelemetryConfiguration.TelemetryProcessors 属性来检查自适应采样是否处于活动状态,以查看它是否包含AdaptiveSamplingTelemetryProcessor 类型的条目。

    【讨论】:

      猜你喜欢
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      • 2021-11-22
      • 1970-01-01
      • 2022-08-08
      • 1970-01-01
      • 2023-04-08
      • 2015-11-10
      相关资源
      最近更新 更多