哪种 Application Insights 自定义 api 方法最适合跟踪客户端版本

Which Application Insights custom api method is best for tracking client version

我们有带 Application Insights 的移动后端。使用 Application Insights API 我可以使用以下方法跟踪自定义数据

TrackPageView - Pages, screens, blades or forms
TrackEvent - User actions and other events. Used to track user behavior or to monitor performance.
TrackMetric - Performance measurements such as queue lengths not related to specific events
TrackException - Log exceptions for diagnosis. Trace where they occur in relation to other events and examine stack traces.
TrackRequest - Log the frequency and duration of server requests for performance analysis.
TrackTrace - Diagnostic log messages. You can also capture 3rd-party logs.
TrackDependency - Log the duration and frequency of calls to external components on which your app depends.

使用后端登录移动设备版本哪个最合适?

或者我应该像这样使用属性吗?

var client = new TelemetryClient();
client.InstrumentationKey =     client.Context.Properties.Add("ApiClientVersion", versionNumber);

您可能希望将该信息添加到 AI 发送的每个跟踪请求中。 为此,您需要一个 TelemetryInitializer。

有一个示例 here

简而言之:您需要创建 ITelemetryInitializer 的实现,将您的自定义信息添加到遥测上下文,然后您需要将遥测初始化程序添加到 TelemetryConfiguration 实例。

TelemetryConfiguration.Active.TelemetryInitializers.Add(
    new YourCustomInformationTelemetryInitializer());

YourCustomInformationTelemetryInitializer 中,您可以像这样在 Initialize 方法中添加信息:

public void Initialize(Microsoft.ApplicationInsights.Channel.ITelemetry telemetry)
{
    telemetry.Context.Properties["AppVersion"] = "1.2.3";
    telemetry.Context.Properties["OtherSpecialInfo"] = "whatever;
}

添加到遥测上下文属性的任何内容都将显示在 Azure 门户中。