Reputation: 4817
We have we mobile backend with Application Insights. When using the Application Insights API I can track custom data with the following methods
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.
Which would be most appropriate to log the version of the mobile device using the backend?
Or should I use properties, like this?
var client = new TelemetryClient();
client.InstrumentationKey = client.Context.Properties.Add("ApiClientVersion", versionNumber);
Upvotes: 1
Views: 1278
Reputation: 3461
You probably want to add that information to every tracking request that AI sends. For this you need a TelemetryInitializer.
There's a sample here.
In short: You need to create an implementation of ITelemetryInitializer
which adds your custom information to the telemetry context, and then you need to add your telemetry initializer to the TelemetryConfiguration
instance.
TelemetryConfiguration.Active.TelemetryInitializers.Add(
new YourCustomInformationTelemetryInitializer());
In YourCustomInformationTelemetryInitializer
you add the information in the Initialize
method like this:
public void Initialize(Microsoft.ApplicationInsights.Channel.ITelemetry telemetry)
{
telemetry.Context.Properties["AppVersion"] = "1.2.3";
telemetry.Context.Properties["OtherSpecialInfo"] = "whatever";
}
Whatever you add to the telemetry context properties will be visible in the Azure portal.
Upvotes: 2