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

UiPath实现异常上报至Azure Application Insights遇阻求助

Azure Application Insights 异常上报失败排查(Invoke Code C#/VB.Net)

核心问题排查方向

  • 代码未完成发送流程:Application Insights SDK默认异步批量上报,Invoke Code执行完毕后进程可能直接终止,导致数据没来得及发送。必须手动触发刷新并等待发送完成。
  • 依赖包未正确引用:确认运行环境已安装Microsoft.ApplicationInsights NuGet包,版本建议使用稳定版(如2.21.0+)。
  • Instrumentation Key错误:检查in_key是否与Azure Portal中Application Insights资源的Instrumentation Key完全一致,注意大小写和特殊字符。
  • 网络/权限限制:运行环境需要能访问Application Insights的 ingestion 端点(https://dc.services.visualstudio.com/v2/track),企业内网需确认是否允许出站请求,无需额外Azure权限,但要确保网络连通。
  • 数据延迟:Application Insights数据 ingestion 通常有5-10分钟延迟,不要上报后立刻查询。

修改后的可运行代码示例

C# 版本

// 初始化配置
var config = Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CreateDefault();
config.InstrumentationKey = in_key;

using (var telemetryClient = new Microsoft.ApplicationInsights.TelemetryClient(config))
{
    // 上报异常
    telemetryClient.TrackException(in_exception);
    // 强制刷新缓存的遥测数据
    telemetryClient.Flush();
    // 等待发送完成(根据实际环境调整时长,1秒足够大部分场景)
    System.Threading.Thread.Sleep(1000);
}

VB.Net 版本

Dim config As New Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration
config.InstrumentationKey = in_key

Using telemetryClient As New Microsoft.ApplicationInsights.TelemetryClient(config)
    Dim exceptionTelemetry As New Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry(in_exception)
    exceptionTelemetry.Properties.Add("AdditionalProperty1", "Value1")
    exceptionTelemetry.Properties.Add("AdditionalProperty2", "Value2")
    
    telemetryClient.TrackException(exceptionTelemetry)
    ' 强制刷新并等待发送
    telemetryClient.Flush()
    System.Threading.Thread.Sleep(1000)
End Using

额外排查步骤

  1. 确认in_exception是有效的Exception实例,避免传入null或未正确捕获的异常对象。
  2. 在代码中添加日志(如控制台输出),确认TrackException代码段已被执行。
  3. 登录Azure Portal,进入目标Application Insights资源,在日志中执行查询:exceptions | order by timestamp desc,等待几分钟后查看结果。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 07:32:57