- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个自定义的 AI 遥测初始化程序。最近,我开始收到编译器警告,说 Context.Properties 已过时:“TelemetryContext.Properties 已过时。使用 GlobalProperties 设置全局级别属性。对于项目级别的属性,请使用 ISupportProperties.Properties。”
ISupportProperties.Properties
? public class JsonTelemetryInitializer : ITelemetryInitializer
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly SystemOptions _systemOptions;
/// <summary>
/// Constructor
/// </summary>
/// <param name="accessor">For accessing the http context</param>
/// <param name="systemOptions">System options</param>
public JsonTelemetryInitializer(IHttpContextAccessor accessor, IOptions<SystemOptions> systemOptions)
{
_httpContextAccessor = accessor;
_systemOptions = systemOptions.Value;
}
/// <summary>
/// Initialize the custom telemetry initializer
/// </summary>
/// <param name="telemetry">Telemetry</param>
public void Initialize(ITelemetry telemetry)
{
if (_httpContextAccessor.HttpContext == null)
{
return;
}
if (_httpContextAccessor.HttpContext.User.Identity.IsAuthenticated)
{
const string tenantId = "northstar_tenantid";
if (!telemetry.Context.Properties.ContainsKey(tenantId))
{
var user = _httpContextAccessor.HttpContext.User;
telemetry.Context.Properties[tenantId] =
ClaimsHelper.GetClaim<int>(user, TokenNames.TenantId).ToString();
var userId = ClaimsHelper.GetClaim<int>(user, TokenNames.UserId).ToString();
telemetry.Context.Properties["northstar_userid"] = userId;
var deviceId = ClaimsHelper.GetClaim<string>(user, TokenNames.DeviceId);
if (deviceId != null)
{
telemetry.Context.Properties["northstar_deviceid"] = deviceId;
}
telemetry.Context.User.Id = userId;
var sessionId = ClaimsHelper.GetClaim<string>(user, TokenNames.SessionId);
if (!string.IsNullOrEmpty(sessionId))
{
telemetry.Context.Session.Id = sessionId;
}
}
}
}
}
最佳答案
1.How do I do that? Use ISupportProperties.Properties?
只需将 ITelemetry
转换为 ISupportProperties
。
我的示例代码如下:
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
public class MyTelemetryInitializer:ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
//cast ITelemetry to ISupportProperties
ISupportProperties propTelemetry = (ISupportProperties)telemetry;
if (!propTelemetry.Properties.ContainsKey("isuport_key"))
{
propTelemetry.Properties.Add("isuport_key", "isupport_value");
}
}
}
2.I am logging the tenant Id, and deviceID, from claims in the principal, per request. Is that considered app global or a support property?
根据我的理解,您可以使用支持属性(项目级别),因为它与您之前使用的类似 telemetry.Context.Properties["northstar_deviceid"] = deviceId;
关于azure - Application Insights - 如何在 TelemetryInitializer 中使用 ISupportProperties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52821523/
我有一个自定义的 AI 遥测初始化程序。最近,我开始收到编译器警告,说 Context.Properties 已过时:“TelemetryContext.Properties 已过时。使用 Globa
我是一名优秀的程序员,十分优秀!