Application-Insights-对App-Service的支持问题-仅自己可见
问题描述
Web App 发布后, Application Insights 收集不到数据了
在应用服务(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却还没有被支持。
一:使用基于代理(agent-based)模式修改.Net Core的版本和Application Agent版本。如:
ApplicationInsightsAgent_EXTENSIONVERSION=~2 同时 升级至.NET Core 3.1 ApplicationInsightsAgent_EXTENSIONVERSION=2.8.37 同时 继续使用.NET Core 2.2
二:使用基于代码模式的Application Insighs:
升级至.NET 5 并更新项目依赖:https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core
2.1 安装Application Insights SDK,建议一直使用最新的稳定版 Application Insights SDK NuGet package for ASP.NET Core。打开项目中的.csproj文件,以如下示例为参考添加Package引用。
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" />
</ItemGroup>
2.2 在项目的Startup类中的 ConfigureServices()方法中,添加 services.AddApplicationInsightsTelemetry()。启动Application Insights
// 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();
}
2.3 设置Application Insights的 instrumentation Connection String。 这里有多种方式来设置Connection String, Connection String的值由Azure Application门户提供
a) 使用系统级环境变量
在系统中添加环境变量参数:APPLICATIONINSIGHTS_CONNECTION_STRING。
b) 在代码设置,使用TelemetryConfiguration对象或ApplicationInsightsServiceOptions
// 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();
}
或者
public void ConfigureServices(IServiceCollection services)
{
var options = new ApplicationInsightsServiceOptions { ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000;" };
services.AddApplicationInsightsTelemetry(options: options);
}
c) 使用配置文件(官方推荐方式)
XML
<?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)
{
"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-string
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
相关文章
- 硅谷互联网公司的开发流程
开发流程包括这么几个阶段: OKR 的设立; 主项目及其子项目的确立; 每个子项目的生命周期; 主项目的生命周期; 收尾、维护、复盘。 第一点,OKR 的设立 所有项目的起始,都应该从 Ro
- RESTful-表述性状态转移风格
REST英文全拼:Representational State Transfer 面向资源编程 资源指的就是一类数据 产品表->就是产品资源 最重要的是如何表示一个资源 地址即
- 稳定性思考
产品功能线 0-1: 当系统从无到有的时候,首要考虑的是研发效率,功能快速迭代,满足快速增长的业务需求 1-10 系统已经搭建起来,此时考虑的是系统的稳定性。 可用性:1.隔离:区分出核心和非核心功能
- Supervisor守护队列发邮件
安装 CentOS: yum -y install supervisor Debien/Ubuntu适用:apt-get install supervisor 配置 修改主配置文件:vim /et
- 安装libsodium,让服务器支持chacha20等加密方式
用chacha20加密方式需要安装libsodium 注意:libsodium从1.0.15开始就废弃了aes-128-ctr yum install wget m2crypto git libsod
随机推荐
- 硅谷互联网公司的开发流程
开发流程包括这么几个阶段: OKR 的设立; 主项目及其子项目的确立; 每个子项目的生命周期; 主项目的生命周期; 收尾、维护、复盘。 第一点,OKR 的设立 所有项目的起始,都应该从 Ro
- RESTful-表述性状态转移风格
REST英文全拼:Representational State Transfer 面向资源编程 资源指的就是一类数据 产品表->就是产品资源 最重要的是如何表示一个资源 地址即
- 稳定性思考
产品功能线 0-1: 当系统从无到有的时候,首要考虑的是研发效率,功能快速迭代,满足快速增长的业务需求 1-10 系统已经搭建起来,此时考虑的是系统的稳定性。 可用性:1.隔离:区分出核心和非核心功能
- Supervisor守护队列发邮件
安装 CentOS: yum -y install supervisor Debien/Ubuntu适用:apt-get install supervisor 配置 修改主配置文件:vim /et
- 安装libsodium,让服务器支持chacha20等加密方式
用chacha20加密方式需要安装libsodium 注意:libsodium从1.0.15开始就废弃了aes-128-ctr yum install wget m2crypto git libsod