【问题标题】:.NET Core 2.1 - Setting Azure Insights sampling configuration results in NPE.NET Core 2.1 - 在 NPE 中设置 Azure Insights 采样配置结果
【发布时间】:2019-05-02 09:52:45
【问题描述】:

我有一个 Azure Function App,我尝试为其配置 Azure Insights Sampling(根据 https://docs.microsoft.com/en-us/azure/azure-monitor/app/sampling),但这会导致以下错误:

发生主机错误 [5/2/19 9:42:42 AM] Microsoft.ApplicationInsights.AspNetCore:对象引用未设置为对象的实例。 值不能为空。 参数名称:提供者

我已包含以下代码:

public class StartUp : IWebJobsStartup
{
    public void Configure(IWebJobsBuilder builder)
    {
        Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
        aiOptions.EnableAdaptiveSampling = false;
        builder.Services.AddApplicationInsightsTelemetry(aiOptions);
    }
}

应在何处/如何/由谁设置“提供者”?

我已经尝试添加

        aiOptions.InstrumentationKey = "[MyKey]";

也一样,但这会导致同样的错误

【问题讨论】:

  • NPE? NullReferenceException?

标签: c# azure dependency-injection azure-application-insights


【解决方案1】:

azure函数采样,可以在host.json中设置,参考这个article:

v2 功能:

{
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "maxTelemetryItemsPerSecond" : 20
      }
    }
  }
}

v1 功能:

{
  "applicationInsights": {
    "sampling": {
      "isEnabled": true,
      "maxTelemetryItemsPerSecond" : 5
    }
  }
}

【讨论】:

  • @Karel,如果答案有效,请帮助将其标记为答案。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-16
  • 2019-02-20
  • 1970-01-01
  • 2018-12-16
  • 2019-04-26
  • 1970-01-01
  • 2020-04-10
相关资源
最近更新 更多