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

时间:2019-02-11 15:55:28

标签: azure .net-core azure-functions

我使用以下代码通过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下。

2 个答案:

答案 0 :(得分:0)

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

您可以在创建TelemetryClient后通过执行ai.Context.Cloud.RoleName来设置它(sudo代码,在应用程序见解SDK版本之间可能有所不同),然后在客户端的整个生命周期中为所有客户端输出的事件设置它。

答案 1 :(得分:0)

ApplicationInsights 从环境变量 df = df.groupby('supply_area').agg( {'supply_area': 'first', 'transaction_date': ','.join, 'price': ','.join}) 中选取角色名称。

这是在 WEBSITE_HOSTNAME

中完成的

在 Azure 中,这个变量是默认设置的,ApplicationInsights 会自动去掉后缀“.azurewebsites.net”。

在其他环境中,您可以自行设置此环境变量,以避免 ApplicationInsights 中的角色名称为空。

相关问题