Azure应用洞察-在高流量情况下不记录所有请求

问题描述

“ Azure Application Insights”似乎没有在高流量环境中记录所有请求。

例如,当我们测试在10,000个请求中部署在“ Azure Service Fabric”上的.Net Core2.1 Web API应用程序,持续30分钟时,可以从“ Azure Application Insights”检索所有请求的详细信息通过使用日期时间戳作为过滤器的KQL,没问题。

当我们在30分钟内将负载增加到100,000个请求时,只有大约5-10%的请求记录在“ Azure Application Insights”上。

为什么“ Azure Application Insights”错过了在每秒处理约60个请求的高流量环境下的提取/记录?

是否需要任何其他配置? (或)仅一行代码不足以吸收由Azure Service Fabric服务提供服务的请求的详细信息?请澄清

使用了SDK

SDK used

在Azure Service Fabric上用于提取代码

  return new WebHostBuilder().Usehttpsys()
                                .ConfigureServices(
                                    services => services
                                        .AddSingleton<StatelessServiceContext>(serviceContext)
                                        .AddSingleton<ServiceFabricAppContext>(new ServiceFabricAppContext(){
                                                NodeName = serviceContext.NodeContext.NodeName,ServiceHostIP=serviceContext.NodeContext.IPAddressOrFQDN,ServiceHostPort=FabricRuntime.GetActivationContext().GetEndpoints()[0].Port
                                        } )
                                            .AddSingleton<ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext))) // Azure Service Fabric Telemetry Initializer
                                .UseContentRoot(Directory.GetCurrentDirectory())
                                   .UseApplicationInsights()
                                .UseStartup<Startup>()
                                .UseEnvironment(environment)
                                .UseServiceFabricIntegration(listener,ServiceFabricIntegrationoptions.None)
                                .UseUrls(url)
                                .Build();

带有项目数的示例查询

enter image description here

未从Azure门户启用采样

enter image description here

解决方法

您可以从代码中禁用自适应采样。请注意,我在下面使用.UseApplicationInsights()。而不是使用不推荐使用的.AddApplicationInsightsTelemetry(下面将其删除)。

  return new WebHostBuilder().UseHttpSys()
                                .ConfigureServices(
                                    services => services
                                        .AddSingleton<StatelessServiceContext>(serviceContext)
                                        .AddSingleton<ServiceFabricAppContext>(new ServiceFabricAppContext(){
                                                NodeName = serviceContext.NodeContext.NodeName,ServiceHostIP=serviceContext.NodeContext.IPAddressOrFQDN,ServiceHostPort=FabricRuntime.GetActivationContext().GetEndpoints()[0].Port
                                        } )
                                       .AddSingleton<ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext)) // Azure Service Fabric Telemetry Initializer
                                       .AddApplicationInsightsTelemetry(o => 
                                            {
                                                o.EnableAdaptiveSampling = false; // disabling adaptive sampling
                                            }))
                                .UseContentRoot(Directory.GetCurrentDirectory())
                                .UseStartup<Startup>()
                                .UseEnvironment(environment)
                                .UseServiceFabricIntegration(listener,ServiceFabricIntegrationOptions.None)
                                .UseUrls(url)
                                .Build();

注意:我必须添加nuget Microsoft.ApplicationInsights.AspNetCore

注意:如果流量很大,禁用采样可能会导致节流和过多的网络流量。因此,您可能希望查看固定速率采样而不是自适应采样。请参阅Sampling in Application Insights