You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 8 ASP.NET Core应用Azure Application Insights无请求数据问题

解决Azure App Service发布后Application Insights请求数据丢失问题

现象总结

  • 发布代码更新前Application Insights运行正常
  • 发布后异常表现:
    • 门户概览图表无请求数据(呈平线)
    • Live Metrics面板显示“不可用:无法连接到你的应用程序”
    • Transaction Search仅能检索到TRACE级日志,无请求、依赖等核心遥测数据
    • 涉及应用:.NET 8 ASP.NET Core

排查与修复步骤

1. 验证SDK配置完整性

  • 检查Program.cs中是否正确启用Application Insights请求跟踪:
    // 确保已添加基础配置
    builder.Services.AddApplicationInsightsTelemetry();
    // 确认未手动禁用请求收集
    builder.Services.Configure<ApplicationInsightsServiceOptions>(options =>
    {
        options.EnableRequestTrackingTelemetryModule = true;
    });
    
  • 核对appsettings.json或环境变量中的Instrumentation Key/Connection String,确保与Azure门户中目标AI实例一致,避免发布时被覆盖。

2. 检查App Service运行时配置

  • 进入Azure门户目标App Service的配置 > 应用程序设置:
    • 确认APPINSIGHTS_INSTRUMENTATIONKEY或APPLICATIONINSIGHTS_CONNECTION_STRING存在且值正确
    • 排查是否存在禁用AI的环境变量(如ApplicationInsights__Enabled设为false)

3. 修复Live Metrics连接问题

  • 确认项目已安装Microsoft.ApplicationInsights.PerfCounterCollector包(.NET 8默认包含,若手动移除需重新安装)
  • 若App Service使用自定义NSG,需允许出站访问dc.services.visualstudio.com和live.monitor.azure.com

4. 排查遥测过滤规则

  • 检查代码中是否存在遥测处理器,错误过滤了请求遥测:
    // 错误示例:丢弃所有请求遥测
    public class FilterTelemetryProcessor : ITelemetryProcessor
    {
        private readonly ITelemetryProcessor _next;
        public FilterTelemetryProcessor(ITelemetryProcessor next) => _next = next;
        public void Process(ITelemetry item)
        {
            if (item is RequestTelemetry) return; // 此处会导致请求数据丢失
            _next.Process(item);
        }
    }
    
  • 检查AI门户中的数据采样设置,确认未将请求数据的采样率设为0%

5. 分析App Service日志

  • 打开App Service的日志流,搜索Application Insights相关报错(如初始化失败、遥测发送异常)
  • 查看stdout日志,确认是否存在SDK依赖缺失或权限问题

内容的提问来源于stack exchange,提问作者prb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 13:23:16