我正在通过以下代码在ASP.NET Core 3.1应用程序中使用Application Insights。
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
ApplicationInsightsServiceOptions aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.DeveloperMode = true;
services.AddApplicationInsightsTelemetry(aiOptions);
}
如您所见,我已启用“开发人员”模式以确保立即推送遥测数据(而不是等待2-5分钟)。但是,它似乎不起作用。
关于如何使其工作的任何想法?
答案 0 :(得分:3)
DeveloperMode仅表示SDK通道不会在内存中缓冲遥测项目。常规行为是遥测被缓存在内存中,并且每30秒一次或当缓冲区有500个项目时,它们将被推送到后端。开发人员模式只是使每个项目都发送而无需缓冲。
遥测通常会在3-10分钟内在Azure门户中显示(取决于后端/索引/等延迟,不受SDK控制)。通过启用开发人员模式,仅SDK级别的缓冲被禁用,从而导致最大“增益”为30秒。遥测仍然需要几分钟才能显示在门户网站上。
(开发人员模式背后的意图是在本地即时显示数据。即Visual Studio本身在调试时显示遥测。不需要显式启用该开发人员。附加调试器会自动启用开发人员模式)
答案 1 :(得分:0)
在启用开发者模式之前它可以工作吗?
像这样将应用程序见解注册到DI容器中
services.AddApplicationInsightsTelemetry()
它会自动假定您在appsettings.json文件中具有带有检测键的json对象
"ApplicationInsights": {
"InstrumentationKey": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
与将其部署为Azure Web应用程序相同,它会自动为您创建一个配置变量。
我建议您将检测密钥显式传递到ApplicationInsightsServiceOptions中,以确保其正确加载。
ApplicationInsightsServiceOptions aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.InstrumentationKey("xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
aiOptions.DeveloperMode = true;
services.AddApplicationInsightsTelemetry(aiOptions);