Application Insights 开发者模式在 ASP.NET Core 3.1 中不工作
Application Insights Developer Mode not working in ASP.NET Core 3.1
我在 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 分钟)。但是,它似乎没有用。
关于如何让它发挥作用有什么想法吗?
在您启用开发者模式之前它是否有效?
当您像这样将应用程序洞察力注册到 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);
DeveloperMode 仅表示 SDK 通道不会在内存中缓冲遥测项目。常规行为是遥测在内存中缓冲,每 30 秒一次或当缓冲区有 500 个项目时,它们被推送到后端。开发者模式只会导致每个项目在没有缓冲的情况下发送。
遥测通常会在 3-10 分钟内显示在 Azure 门户中(取决于 backend/indexing/etc。延迟,不受 SDK 控制)。通过启用开发者模式,只有 SDK 级缓冲被禁用,导致最大“增益”为 30 秒。遥测仍需要几分钟才能显示在门户中。
(开发人员模式背后的目的是在本地立即显示数据。即 Visual Studio 本身在调试时显示遥测。为此,不需要显式启用开发人员。附加调试器会自动启用开发人员模式)
我在 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 分钟)。但是,它似乎没有用。
关于如何让它发挥作用有什么想法吗?
在您启用开发者模式之前它是否有效?
当您像这样将应用程序洞察力注册到 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);
DeveloperMode 仅表示 SDK 通道不会在内存中缓冲遥测项目。常规行为是遥测在内存中缓冲,每 30 秒一次或当缓冲区有 500 个项目时,它们被推送到后端。开发者模式只会导致每个项目在没有缓冲的情况下发送。
遥测通常会在 3-10 分钟内显示在 Azure 门户中(取决于 backend/indexing/etc。延迟,不受 SDK 控制)。通过启用开发者模式,只有 SDK 级缓冲被禁用,导致最大“增益”为 30 秒。遥测仍需要几分钟才能显示在门户中。
(开发人员模式背后的目的是在本地立即显示数据。即 Visual Studio 本身在调试时显示遥测。为此,不需要显式启用开发人员。附加调试器会自动启用开发人员模式)