Track telemetry data with Application Insights

Application insights is a great measurement tool which provides you more insights into the usage of your application. This will help you solve exceptions, performance problems and it can even be helpful to improve the user experience of your application if you are interested in that of course. This service can be used for several types of applications, web, mobile and windows applications. Multiple programming languages are supported like .NET, PHP, Phyton, Ruby and many more. Application Insights is a tool for developers. Google Tag Manager provides functionalities that are very similar as Application Insights, but AI (Application Insights) is way too complex for the customer/marketeers. If you only want to use one tool for tracking telemetry data you can export data from Application Insights and import it in PowerBI. Will share my experience with this functionality soon. This blog post will cover the basics to start with Application Insights, but also how you can implement custom tracking which can be valuable to understand what's happening on your website. In this blog, I'll focus on using Application Insights while building web applications with C#/Powershell.




USING PowerShell:


$InstrumentKey = ""
$CustomMeasurements = @{
measure1 = 111;
measure2 = 222
}
$CustomProperties = @{
"Actual IP" = $ipaddress;
"DeveloperMode" = "true"
}

Function Build-PostData 
{
Try {
Return @{
name = "Microsoft.ApplicationInsights.Dev.$InstrumentKey.Event";
time = [Datetime]::UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
iKey = $InstrumentKey;
data = @{
baseType = "EventData";
baseData = @{
ver = 2;
name = "sample";
measurements = $CustomMeasurements;
properties = $CustomProperties;
}
};
}
} Catch {
Throw $_
}
}

Try {
$postData = Build-PostData | ConvertTo-Json -Depth 5
Try {
$Response = Invoke-RestMethod -Method POST -Uri "https://dc.services.visualstudio.com/v2/track" -ContentType "application/json" -Body $postData
Write-Host "Request success:"
Write-Host $Response
} Catch {
Write-Host "Request fail, please check the detailed error:"
Write-Host $_
}
} Catch {
Throw $_
}


Using C# code:

            TelemetryClient tclient = new TelemetryClient();
            tclient.InstrumentationKey = ConfigurationManager.AppSettings["InstrumentationKey"];
            tclient.TrackEvent("Name", parameters);

Comments

  1. A very interesting solution and I think it can work in this application. I also like to use such IT solutions very much. What suits me best is cooperation with https://grapeup.com/services/application-development/ where I can be sure that such applications running in the cloud can be used in my business.

    ReplyDelete

Post a Comment