我用下面的代码在ASP.NET Core3.1应用程序中使用应用程序洞察。
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
ApplicationInsightsServiceOptions aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.DeveloperMode = true;
services.AddApplicationInsightsTelemetry(aiOptions);
}如你所见,我已经启用了开发者模式,以确保立即推送遥测数据(而不是等待2-5分钟)。然而,它似乎不起作用。
有没有关于如何让它工作的想法?
发布于 2020-07-12 23:30:28
DeveloperMode只是意味着SDK channel不会在内存中缓冲遥测项。常规行为是遥测在内存中缓冲,每30秒一次,或者当buffer有500个项目时,它们被推送到后端。开发人员模式只会导致发送每个项目时不进行缓冲。
遥测将在Azure门户中可见,通常在3-10分钟内(取决于后端/索引等延迟,不受SDK控制)。开启开发者模式,仅关闭SDK级缓冲,最大增益为30秒。遥测仍然需要几分钟才能显示在门户中。
(开发者模式背后的意图是在本地即时显示数据。也就是说,Visual Studio本身在调试时显示遥测。对于该开发人员不需要显式启用。附加调试器会自动启用开发人员模式)
发布于 2020-07-12 19:56:29
在你开启开发者模式之前,它能正常工作吗?
在将应用程序洞察注册到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);https://stackoverflow.com/questions/62856487
复制相似问题