问题描述

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:

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 stringhttps://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

【Azure 应用程序见解】 Application Insights 对App Service的支持问题的更多相关文章

  1. 【应用程序见解 Application Insights】Application Insights 使用 Application Maps 构建请求链路视图

    Applicaotn  Insigths 使用 Application Maps 构建请求链路视图 构建系统时,请求的逻辑操作大多数情况下都需要在不同的服务,或接口中完成整个请求链路.一个请求可以经历 ...

  2. 【应用程序见解 Application Insights】使用Azure Monitor Application Insights Agent获取Azure VM中监控数据及IIS请求指标等信息

    问题情形 为了使用Application Insights也可以监控Azure VM中的相关性能数据,如CPU, Memory,IIS Reuqest等信息,可以在VM中开始一个一个扩展插件: Azu ...

  3. 【应用程序见解 Application Insights】在Application Insights中通过自定义查询结果定义指标并显示在Dashboard中

    问题情形 通过Application Insights收集到指标数据后,如Request,Trace,Exception.但是默认的Insights图表不能满足业务的需求,需要自定义相应的类SQL语句 ...

  4. 【Azure 应用程序见解】Application Insights Java Agent 3.1.0的使用实验,通过修改单个URL的采样率来减少请求及依赖项的数据采集

    问题描述 近日好消息,如果是一个Java Spring Cloud的项目,想使用Azure Applicaiton Insights来收集日志及一些应用程序见解.但是有不愿意集成SDK来修改代码或者配 ...

  5. 【Azure Application Insights】在Azure Function中启用Application Insights后,如何配置不输出某些日志到AI 的Trace中

    问题描述 基于.NET Core的Function App如果配置了Application Insights之后,每有一个函数被执行,则在Application Insights中的Logs中的tra ...

  6. 【Azure 应用服务】PHP应用部署在App Service for Linux环境中,上传文件大于1MB时,遇见了413 Request Entity Too Large 错误的解决方法

    问题描述 在PHP项目部署在App Service后,上传文件如果大于1MB就会遇见 413 Request Entity Too Large 的问题. 问题解决 目前这个问题,首先需要分析应用所在的 ...

  7. 小程序框架之逻辑层App Service

    小程序开发框架的逻辑层使用 JavaScript 引擎为小程序提供开发者 JavaScript 代码的运行环境以及微信小程序的特有功能. 逻辑层将数据进行处理后发送给视图层,同时接受视图层的事件反馈. ...

  8. 【Azure 应用服务】一个 App Service 同时部署运行两个及多个 Java 应用程序(Jar包)

    问题描述 如何在一个AppService下同时部署运行多个Java 应用程序呢? 问题解答 因为App Service的默认根目录为 wwwroot.如果需要运行多个Java 应用程序,需要在 www ...

  9. 【Azure 应用服务】App Service 开启了私有终结点(Private Endpoint)模式后,如何来实现公网Git部署呢?

    问题描述 因为中国区的App Service对外(公网访问)需要进行ICP备案,所以很多情况下,Web应用部署到App Service后,都是通过Application Gateway(应用程序网关) ...

随机推荐

  1. MDK5生成BIn文件的方法

    配置MDK5 生成bin文件的 第一步:方法打开option for Target 第二步:选择 user 第三步:找到After Build/Rebuild 第四步:勾选run,点击文件选择小图标选 ...

  2. Nmap & ncat

    Nmap & ncat https://github.com/udacity/course-ud303 https://nmap.org/dist/nmap-7.30-setup.exe Yo ...

  3. HTML5 download 执行条件

    HTML5 download 执行条件 同一个域名下的资源 http only 绝对路径/相对路径 都可以 demo https://cdn.xgqfrms.xyz/ https://cdn.xgqf ...

  4. React & redux-saga & effects & Generator function & React Hooks

    React & redux-saga & effects & Generator function & React Hooks demos https://github ...

  5. DOM事件对象用法

    分为三个阶段:事件捕获阶段.目标阶段.事件冒泡阶段. 事件捕获老版本浏览器(IE<=8)不支持,但是事件冒泡可以放心使用. 事件处理程序 一共四类写法,基本都见过,看下写法就知道怎么回事儿了. ...

  6. NGK——更好的数据与网络

    对于NGK而言,帐本是不可或缺的,所以NGK有独立的共识层,共识层有单独的参与的共识节点.而其余计算都丢给其他的计算资源计算,共识层汇总一个正确的结果即可. 进行大量计算过程的资源是另一种节点,在NG ...

  7. 直播预告 | 全面的审计分析和权限管控——CloudQuery年终发布!

    2020年9月,CloudQuery 发布. 针对开发.运维人员面临的如何高效便捷访问.操作管理数据的问题,我们设计并研发了云原生安全数据操作平台,CloudQuery 就此诞生! 2020年结束之际 ...

  8. Angular的工作原理

    来源:https://www.cnblogs.com/moriah/p/6096998.html <!doctype html> <html ng-app> <head& ...

  9. 上天的源码要不要——GitHub 热点速览 v.21.08

    作者:HelloGitHub-小鱼干 前几天,"机智号" 所用的飞行软件框架 F´ 被 NASA 开源了,想看 F´ 这个嵌入式的代码不妨考虑下 Sourcetrail 这个神器, ...

  10. 微信支付/支付宝支付/银联支付,对比加总结(Java服务端)

    今天来讲讲支付. 工作到现在,接入过好几个项目的支付,其中涉及到了微信支付.支付宝支付.银联支付. 三种支付的对接感受其实整体上大同小异.都遵循同一个流程: 1).商户APP向商户服务器请求生成订单 ...