代码之家  ›  专栏  ›  技术社区  ›  Martin Staufcik

将角色名称添加到Application Insights遥测

  •  0
  • Martin Staufcik  · 技术社区  · 6 年前

    我使用此代码记录使用 TelemetryClient :

    var appInsightsRoleName = "tracking";
    
    var telemetry = new ExceptionTelemetry();
    telemetry.Exception = exception;
    telemetry.SeverityLevel = SeverityLevel.Error;
    telemetry.Context.InstrumentationKey = appInsightsKey;
    telemetry.Context.Operation.Id = Guid.NewGuid().ToString();
    telemetry.Properties.Add("cloud_RoleName", appInsightsRoleName);
    
    var ai = new TelemetryClient();
    ai.TrackException(telemetry);
    

    通过设置 cloud_RoleName 财产。

    异常已成功登录到应用程序洞察,但问题是其角色名称未传播到应用程序洞察中:

    enter image description here

    异常记录在下 no role name .

    1 回复  |  直到 6 年前
        1
  •  0
  •   lawrencegripper    6 年前

    我相信 cloud_RoleName is populated by the global Context.Cloud property on the TelemetryClient Object.

    您可以在创建 远程客户端 通过做 ai.Context.Cloud.RoleName (sudo代码,可能在app insights sdk版本之间有所不同)然后将为客户端在其生命周期内输出的所有事件设置该代码。