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

Azure Application Insights仅显示1个用户/会话问题求助

Azure Application Insights 用户/会话计数异常排查

环境与问题

  • 架构:前端基于React+Node.js,后端为C# API,分别部署在两个独立的Azure App Service中
  • 异常现象:API后端关联的Application Insights始终仅统计1个用户、1个会话,但实际已通过两个不同IP地址发起测试,且日志已记录对应访问;事件、错误等其他遥测数据均能正常采集,仅用户/会话计数不符合实际情况

已执行的排查操作

  • 初始配置:在Azure门户创建Application Insights资源并关联API App Service,问题未解决
  • 项目内配置:在Visual Studio项目中手动配置并关联现有Instrumentation Key,无效
  • 代码手动设置用户/会话ID:
    var telemetryClient = new TelemetryClient();
    telemetryClient.InstrumentationKey = "123";
    
    var ipAddress = HttpContext.Connection.RemoteIpAddress.ToString();
    
    if (ipAddress == "::1")
    {
       ipAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList[1].ToString();
    }
    
    telemetryClient.Context.User.Id = ipAddress;
    telemetryClient.Context.User.AuthenticatedUserId = ipAddress;
    telemetryClient.Context.Session.Id = ipAddress;
    
    logger.LogInformation("User.Id -> " + ipAddress);
    logger.LogInformation("User.AuthenticatedUserId -> " + ipAddress);
    logger.LogInformation("Session.Id -> Ip -> " + ipAddress);
    
    Kudu日志显示不同测试请求的IP已正确赋值,但Application Insights仪表板仍显示1个用户/会话,且User Id、Session Id字段显示为<undefined>
  • 前端配置尝试:安装applicationinsights@^2.7.2,在webpack.js和index.html中添加配置,本地环境测试用户/会话计数正常,但部署到Azure App Service后问题依旧,遥测中Session.Id已赋值但统计结果仍异常

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 21:15:01