【Azure 应用程序见解】 Application Insights 对App Service的支持问题

简介: 【Azure 应用程序见解】 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:

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

 

相关文章
|
4月前
|
存储 安全 Linux
【Azure App Service】在App Service中查看CA证书
在 Azure App Service 中,使用自签名或私有 CA 证书的远程服务可能会导致 SSL 握手失败。解决方法包括使用受信任 CA 签发的证书,或通过 App Service Environment 加载自定义根证书,实现安全连接。
126 3
|
3月前
|
移动开发 小程序 Android开发
基于 uni-app 开发的废品回收类多端应用功能与界面说明
本文将对一款基于 uni-app 开发的废品回收类多端应用,从多端支持范围、核心功能模块及部分界面展示进行客观说明,相关资源信息也将一并呈现。
169 0
|
2月前
|
Java 应用服务中间件 API
【App Service】部署War包到Azure云上遇404错误
Java应用部署至Azure App Service for Windows后报404,本地运行正常。经排查,日志提示类文件版本不兼容:应用由Java 17(class file version 61.0)编译,但环境仅支持到Java 11(55.0)。错误根源为Java版本不匹配。调整App Service的Java版本至17后问题解决,成功访问接口。
168 1
|
2月前
|
存储 Linux 网络安全
【Azure App Service】Root CA on App Service
Azure App Service for Windows应用连接外部SSL服务时,需确保其证书由受信任的根CA颁发。多租户环境下无法修改根证书,但ASE(单租户)可加载自定义CA证书。若遇证书信任问题,可更换为公共CA证书或将应用部署于ASE并导入私有CA证书。通过Kudu的PowerShell(Windows)或SSH(Linux)可查看当前受信任的根证书列表。
107 14
|
3月前
|
API 网络架构 容器
【Azure Container App】查看当前 Container App Environment 中的 CPU 使用情况的API
在扩展 Azure Container Apps 副本时,因 Container App Environment 的 CPU 核心数已达上限(500 cores),导致扩展失败。本文介绍如何使用 `az rest` 命令调用 Azure China Cloud 管理 API,查询当前环境的 CPU 使用情况,并提供具体操作步骤及示例。
150 16
|
3月前
|
数据安全/隐私保护
【Azure Function App】PowerShell Function 执行 Get-AzAccessToken 的返回值类型问题:System.String 与 System.Security.SecureString
将PowerShell Function部署到Azure Function App后,Get-AzAccessToken返回值类型在不同环境中有差异。正常为SecureString类型,但部分情况下为System.String类型,导致后续处理出错。解决方法是在profile.ps1中设置环境变量$env:AZUREPS_OUTPUT_PLAINTEXT_AZACCESSTOKEN=false,以禁用明文输出。
132 1
|
3月前
|
网络协议 Java Linux
【App Service】在Azure环境中如何查看App Service实例当前的网络连接情况呢?
在 Azure App Service(Windows 和 Linux)中部署应用时,分析网络连接状态是排查异常、验证端口监听及确认后端连接的关键。本文介绍如何在 Linux 环境中使用 `netstat` 命令查看特定端口(如 443、3306、6380)的连接情况,并解析输出结果。同时说明在 Windows App Service 中 `netstat` 被禁用的情况下,如何通过门户抓包等替代方法进行网络诊断。内容涵盖命令示例、操作步骤及附录说明,帮助开发者快速掌握云环境中的网络分析技巧。
125 11
|
消息中间件
多个不同的app应用间应该如何进行消息推送呢?
现在很多公司做app应用都会用到推送,推送这个不多说了,怎么做网上一堆,用的比较多的还数极光推送(Jpush)以及百度推送,目前我们使用Jpush,文档方面质量是差了点。。这个先不吐槽,主要现在的app应用很多公司不是做单个,而是多个,比如打车软件有司机端和用户端,运输类应用会有司机端、车主端、货主...
1019 0
|
2月前
|
缓存 移动开发 JavaScript
如何优化UniApp开发的App的启动速度?
如何优化UniApp开发的App的启动速度?
572 139
|
2月前
|
移动开发 JavaScript weex
UniApp开发的App在启动速度方面有哪些优势和劣势?
UniApp开发的App在启动速度方面有哪些优势和劣势?
356 137