im currently trying to get event data from application insights from a c# class. Im going to save information about the assets reproduced in azure media player, like visits count, time watched and other stuff like that. My tracking data and my code is the following, and the event name where i save this info is "AssetPlayBackData". This event is tracked everytime a video is played on the azure media player. Now, how can i get the all the events called "AssetPlayBackData" from a c# class? I have read i should use LogsQueryClient with the method "QueryWorkspace" but im not sure. Thanks in advance!
var trackingData = {
assetName: "",
playStartTime: null,
playEndTime: null,
visitCount: 0,
playbackDuration: 0,
location: ""
};
player.on('play', function () {
var currentSrc = player.currentSrc();
var assetName = currentSrc.substring(currentSrc.lastIndexOf("/") + 1);
trackingData.assetName = assetName;
trackingData.visitCount++;
trackingData.playStartTime = new Date().toISOString();
trackingData.location = window.navigator.language;
});
player.on('ended', function () {
trackingData.playEndTime = new Date().toISOString();
trackingData.playbackDuration = (new Date(trackingData.playEndTime) - new Date(trackingData.playStartTime)) / 1000;
appInsights.trackEvent("AssetPlaybackData", trackingData);
trackingData.playStartTime = null;
trackingData.playEndTime = null;
trackingData.visitCount = 0;
trackingData.playbackDuration = 0;
trackingData.location = "";
});
I have tried the class TelemetryClien, but i havent found any methods to get this data in a c# class. LogsQueryCLient whith the method "QueryWorkspace" is a class that i have found interesting but im not sure if it is related with application Insights.
TelemetryClientis a class used to Send telemetry. You cannot read telemetry using the Application Insights SDKTo query data you can indeed use the
LogsQueryCLientclass from the Azure.Monitor.Query NuGet package.Azure Application Insights and Azure Log Analytics, including the workspaces are part of Azure Monitor. There are two flavours for Application Insights: classic and Workspace-based. Workspace-based Application Insights resources store the data inside Log Analytic workspaces, hence you need a workspace to be able to use the
LogsQueryCLientclass.Here is some example code
(source)