我有一个 Azure Function App,我尝试为其配置 Azure Insights 采样(按照 https://learn.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]";
也是如此,但这会导致相同的错误
最佳答案
对于azure函数采样,可以在host.json中设置,引用这个article :
v2 功能:
{
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"maxTelemetryItemsPerSecond" : 20
}
}
}
}
v1 功能:
{
"applicationInsights": {
"sampling": {
"isEnabled": true,
"maxTelemetryItemsPerSecond" : 5
}
}
}
关于c# - .NET Core 2.1 - 在 NPE 中设置 Azure Insights 采样配置结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55949841/