我使用以下代码通过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
属性来设置角色名称。
该异常已成功登录到应用程序见解中,但问题在于其角色名称未传播到应用程序见解中:
该异常记录在no role name
下。
答案 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 中的角色名称为空。