Web App 发布后, Application Insights 收集不到数据了web
在应用服务(App Service)中收集应用的监控数据(如Request,Exception,Trace等)时经过Agent(Application Insight Site Extension)来实现的。因更新迭代的关系,有些版本再也不,或尚未被支持。如Agent(Application Insight Site Extension 2.8.38)支持.NET Core 2.1 and 3.1, 而 .Net Core 2.2再也不被继续支持,而.Net 5却尚未被支持。json
<ItemGroup> <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" /> </ItemGroup>
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // The following line enables Application Insights telemetry collection. services.AddApplicationInsightsTelemetry(); // This code adds other services for your application. services.AddMvc(); }
a) 使用系统级环境变量app
在系统中添加环境变量参数:APPLICATIONINSIGHTS_CONNECTION_STRING。
ide
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var configuration = new TelemetryConfiguration { ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000;" }; // The following line enables Application Insights telemetry collection. services.AddApplicationInsightsTelemetry(configuration); // This code adds other services for your application. services.AddMvc(); }
或者visual-studio
public void ConfigureServices(IServiceCollection services) { var options = new ApplicationInsightsServiceOptions { ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000;" }; services.AddApplicationInsightsTelemetry(options: options); }
c) 使用配置文件(官方推荐方式)this
XMLurl
<?xml version="1.0" encoding="utf-8"?> <ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings"> <ConnectionString>InstrumentationKey=00000000-0000-0000-0000-000000000000</ConnectionString> </ApplicationInsights>
JSON(config.json)spa
{ "ApplicationInsights": { "ConnectionString" : "InstrumentationKey=00000000-0000-0000-0000-000000000000;" } }
How to set a connection string: https://docs.microsoft.com/en-us/azure/azure-monitor/app/sdk-connection-string?tabs=net#how-to-set-a-connection-string3d
Enable Application Insights server-side telemetry (no Visual Studio): https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core#enable-application-insights-server-side-telemetry-no-visual-studio代理
Enable agent-based monitoring:https://docs.microsoft.com/en-us/azure/azure-monitor/app/azure-web-apps?tabs=netcore#enable-agent-based-monitoring
Microsoft.ApplicationInsights.AspNetCore package: https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore