Thursday, 28 May 2015

Adventures in Application Insights - Part 1

If, like I was, you’re struggling to get anything out of Azure Application Insights, I hope to be of some help.

It all started well enough – I added App Insights to a web app, this setup the ApplicationInsights.config file for me and boom, I had some data in App Insights on the web. Then I wanted to write a custom event to the cloud so I added the following code into the app…

  var tc = new TelemetryClient();
  tc.TrackEvent("Testing");
  tc.Flush();

I ran my app and imagine my dismay when nothing happened. I checked around in blog posts, looked at the official documentation, tried a bunch of things – but stubbornly the above lines of code simply didn’t want to work for me.

Instrumenting a Console App

The web project I’m adding this to isn’t the simplest, so rather than hack it around too much I then decided to create a simple Console App and debug through it to see what was happening. Here it is in its entirety…

using Microsoft.ApplicationInsights;
namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            var tc = new TelemetryClient();
            tc.TrackEvent("Testing");
            tc.Flush();
        }
    }
}

Not a great deal going on there! Having seen the ApplicationInsights.config file in the other project I added one to my console app too – well, I copied it from the web app to be fair. I ran the app and once again – nothing. At that point I decided it was time to do some debugging – but I couldn’t find symbols for Microsoft.ApplicationInsights.dll (and others from the App Insights stable), so I dragged out my trusty copy of Reflector and created some. If you didn’t already know, Reflector can generate missing PDB’s for you, it’s cooler than a penguins chilly bits and well worth the cost.

With a .pdb in hand I then stepped into the TrackEvent method and further down the call chain until I got to this point in the code…

[EditorBrowsable(EditorBrowsableState.Never)]
public void Track(ITelemetry telemetry)
{
  if (this.IsEnabled()
  {
    string instrumentationKey = this.Context.InstrumentationKey;
    if (string.IsNullOrEmpty(instrumentationKey))
    {
      instrumentationKey = this.configuration.InstrumentationKey;
    }
    if (!string.IsNullOrEmpty(instrumentationKey))
  ...

When I inspected the instrumentationKey it was empty - and this indicated to me that despite having an ApplicationInsights.config file, this wasn't actually being picked up. A quick look on disk and I saw that the file wasn't in the same directory as my .exe, so I went back to the app and set the properties of the file as shown below...

The main thing to note is that I changed Copy To Output Directory. With that altered I ran the app again and this time Boom, it threw an exception…

Drilling down on the exception the root cause was this…

{"Type 'Microsoft.ApplicationInsights.Extensibility.RuntimeTelemetry.RemoteDependencyModule, Microsoft.ApplicationInsights.Extensibility.RuntimeTelemetry' could not be loaded."}

The Config File

This alerted me to the content of the .config file that I'd blatantly copied and pasted from the web project, and opening it up it was evident what was happening - I'd 'told' it to load some types that didn't exist in my simple console app - or rather, the file I copied across included a bunch of types that were not referenced...

<?xml version="1.0" encoding="utf-8"?>
<?XML:NAMESPACE PREFIX = "[default] http://schemas.microsoft.com/ApplicationInsights/2013/Settings" NS = "http://schemas.microsoft.com/ApplicationInsights/2013/Settings" /><applicationinsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
  <!-- 
    Learn more about Application Insights configuration with ApplicationInsights.config here: 
    http://go.microsoft.com/fwlink/?LinkID=513840
    
    Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file.
  -->
  <telemetrymodules>
    <add type="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights"></add>
    <add type="Microsoft.ApplicationInsights.Extensibility.RuntimeTelemetry.RemoteDependencyModule, Microsoft.ApplicationInsights.Extensibility.RuntimeTelemetry"></add>
    <add type="Microsoft.ApplicationInsights.Extensibility.PerfCollector.PerformanceCollectorModule, Microsoft.ApplicationInsights.Extensibility.PerfCollector">
...

Here the TelemetryModules section is quite clearly defining a bunch of plug-ins, the first exists (as it's in Microsoft.ApplicationInsights which I have referenced), the second and third do not and sure enough the second is the subject of the exception I received. Armed with this knowledge I did a hatchet job on the .config file and removed anything I didn't have referenced from Nuget or directly. I then ran the app again and to my dismay - still nothing happened. I was expecting to see an HTTP Post request flying over the wire to Azure, but instead there was nothing.

Flush, aha, he saved every one of us!

(Sorry for the abysmal pun, I couldn’t help myself). I did a bit more digging on the TelemetryClient and found the Flush() method which I have added into the code samples above, but didn't have in my code at the time. With this added I was delighted to see a message show up inside Visual Studio that alerted me to the fact that I had managed to send an event to Azure..

I also saw this pop up in Fiddler...

So far so good. I then logged into Azure and lo and behold, I got my event!

I could even drill down and see “more” data about the event…

OK, so “more” data is somewhat subjective, but it did tell me that my event came from the UK which is correct. I have no doubt that I could augment the data being collected from my application so that the amount of detail here would be better.

Looking at what was sent to the server, it’s a simple JSON request as follows (I’ve blanked out my App Insights key, which I’m surprised to find twice in the content. If I’d designed this, the app insights key would have been a custom header, but that’s just an aside)…

And there you have it – one event in Azure, an hour or more messing around with it to understand what it’s doing, and I’ve got a load closer to working out why my web app wasn’t sending any telemetry (or rather, the custom telemetry I was expecting to send).

I hope that helps someone else! Next time I’ll see what’s up with my web app.

46 comments:

Unknown said...

This article delivers me step by step details of Console App which is good for understanding this topic. web app development US

Unknown said...

Good post regarding the web application development for our business. Thanks for sharing.

Web Application Development in Chennai | Android application development company

Unknown said...
This comment has been removed by the author.
Unknown said...

The best programmers who meet expectations https://youteam.co.uk/

Oliver Maurice said...

If you really want to catch cheater you should plan beforehand. This blog will lead you to some great info on the subject.

Unknown said...

It is but very important that great geniuses are really into programming. The world is moving so quickkly now and programmers has helped in many innovations.

Scott Porter
West Palm Beach digital agency

Anbarasan14 said...

Nice blog!! I hope you will share more info like this. I will use this for my studies and research.
PHP Training Institute in Chennai
Best PHP training in chennai
Ethical Hacking Course in Chennai
PHP Training in Chennai
Web Designing Course in Chennai
PHP Training in Chennai
PHP Course in Chennai

Aditi Ray said...

TreasureBox is operated by a group of young, passionate, and ambitious people that are working diligently towards the same goal - make your every dollar count, as we believe you deserve something better.
laptop table
shoe storage nz
outdoor furniture covers nz

meldaresearch said...

When it comes to the delivery of Buy Research Papers Online, we complete and ensure the clients get their essays well in time before the deadline. This is meant to ensure that the client has adequate time to go through the Research Paper Writing Service Online and assess whether there are changes they may need.

Denil Wolter said...

The main purpose of education is to help students gain the knowledge and skills so that they will be able to function in society. Students need to be provided with the necessary skills so that they can learn to become productive citizens. There are many advantages that are associated with receiving an education. Students will be able to contribute to their community and help make it a better place to live. Education basically helps shape society because it helps students learn to become more sociable and helps them develop relationships with their peers. Students will be more qualified for different job positions if they have a good solid education. Education is vital to each student’s life, therefore, by working hard to provide the best instruction possible will help train students to become future leaders and will lead to a better life.
Education is essential to every student’s life as well as their future. Students can have a prosperous life by receiving a good quality education. My thoughts are that students need to learn from the books along with other various materials just as I did while growing up. The classroom curriculum should be decided by their teacher and the teacher should set clear goals as to what is expected from the students. Students should work hard to achieve their goals because it will certainly be worth it in the end. According to essentialism, ‘Schools should not radically try to reshape society but schools should transmit traditional moral values and intellectual knowledge that students need to become model citizens’. Read about education help at http://www.top-essay-writing-service.com . The school should stress the importance of values because some children are not taught these at home. Teaching children good values helps build their character and helps them become respectable people. In regards to education, I think society is important because this is a place where we all live so we should work to make it a better place.

meldaresearch said...

It can be awful for any student who attains low grades due to low-quality Custom Research Papers. Luckily, you have a Research Papers for Sale Help online that will help you handle even the most challenging Affordable Term Papers.

Florahmelda said...

Professional Coursework Writing Services online produces different assignments, including Coursework Writing Assistance, to help students deal with the Coursework Assignment Writing challenges they face every day.

meldaresearch said...

Do you ardently require Essay Writing Help Writing Services from a writing firm with a distinguished track record? Are you unsure of which Custom Essay Writing Service Provider to contract for your essays? Do not let a burdensome Custom Essay Writing Services task drag you down.

Sankar said...

I have read your blog its very attractive and impressive. I like it your blog.
Final Year Projects for CSE in Dot Net

.Net Training in Chennai

Final Year Project Centers in Chennai

Dot Net Training in Chennai

unkown said...

Shop Online in Auckland Newzealand on a single click. We provide you quality items which you will be buy online at lowest price..! Buy online sofa beds nz at lowest price on Treasurebox store.

Pinoy Swertres said...

now a days pinoy tv shows are updated on pinoy channel

Emily Goutagny said...

You can let the application run and take a look at the data that is collected in the Azure Portal. Depending on the technology and instrumentation www.hardwoodfloorrefinishingmn.com/

Ben Johnson said...

Thanks for sharing...

devops training in chennai
devops training in chennai BITA Academy
devops certification training in chennai
devops training in chennai BITA Academy
devops training in chennai velachery
devops training in chennai anna nagar
devops training center in chennai
devops coaching center in chennai
devops jobs in chennai
devops training institute in chennai
devops training in chennai t nagar
devops training institutes in chennai
devops course in chennai
devops certification course in chennai
devops training in porur

Aliamay said...


Get all the latest clicksud online seriale online of clicksud and all the seriale online daily on this blog.

Emily Goutagny said...

One of the main features of Application Insights is Application Monitoring. There are plenty of charts in the Azure Portal that give an overview on www.seattletreeremovalpros.com/

Unknown said...

Experience the best electronics dealing with us and shop latest appliances and electronics. How many times you notice handsome electronic appliance waiting to be carted away in its latest state or design? We have been passionate enough to showcase the local public with spectacular deals in the area of furnishing and home décor. Not all the websites claiming to be the sources of high-quality electronics keep up with all the demands of ordinary man. We here have been dealing with every type of electronic appliances like Metal Detector, Photography Studio Set with Stand, Metal Detector, Solar Charger, Camera Bag, PC Gaming Keyboard Mouse Set and many more.

Michaela Mil said...

Thanks for useful guidelines. Although, I think I might also need a good monitoring app to control available WiFi networks. Currently, I'm considering mSpy - it is a leading parental control app that allows one to track a phone and also provides access to installed programs and files.

Technogeekscs said...

Wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.
Data Science
Selenium
ETL Testing
AWS
Python Online Classes

Desi Ingredients said...

Doramasmp4 esperamos que la estés pasando genial viendo. DoramasMP4 siempre será el primero en tener el episodio, así que por favor marque y agréguenos en Facebook para actualizarlo.
https://issuu.com/doramasmp4/docs/top_shows.docx

Desi Ingredients said...

Doramasmp4 esperamos que la estés pasando genial viendo. DoramasMP4 siempre será el primero en tener el episodio, así que por favor marque y agréguenos en Facebook para actualizarlo.
https://doramas-sub-espanol.jimdosite.com/

Firmware File said...

Flash file is used to upgrade or reinstall the operating system in your device. It resolves different issues like application stopped working, Boot loop issue, dead issues, and IMEI issues. Y51l volte

ncrhotgirls.com said...

Explore the profiles of guwahati escorts, guwahati call girls, call girls in guwahati
and escorts in guwahati for female companionship in top rated hotels.
Get affordable escort services in guwahati hotels now.
College escorts in Guwahati |
Housewife escorts in Guwahati |
Assamese call girls in Guwahati |
Nepali call girls in Guwahati |
Female escorts in Guwahati |
High profile escorts in Guwahati |
Russian escorts in Guwahati |
College call girls in Guwahati |

Technogeekscs said...

Thanks for the post. It was very interesting and meaningful. I really appreciate it! Keep updating stuff like this.
Python Training Institutes in Pune
Best Training Institute for AWS in Pune
Data Science Course in Pune

Snehal Harshe said...
This comment has been removed by the author.
teju said...

Thanks for the best share,
movie hd apk

Isabell Kiral said...

This field is very much profitable and through this many developers are earning a lot of money. If you are jobless, you should join this field and start a good career. I also want to develop an app like this website.

Michael Smith said...

I from an overall perspective expected to thank you for this sorting pulling out!! I've totally respected every single piece of it, I've had you bookmarked to find the proportion of the latest things you make. The HP Printer Error Code 0xc05d1281 occurs due to ink system failure. Contact us our helpline number to fix the error.

sanshi said...

Thanks for your sharing great article, I am very happy to read this article and I like it very much!I would also recommend it to my friends.
sun news live
sun news
sun tv live
news 7 live
sun news live today
sun tv news
sun tv news live
sun tv live news
சன் நியூஸ்
thanthinews

Jamie Starr said...

Hi, I really enjoyed reading your post, and hope to read more. thank you so much for sharing this informative blog. Please check out sorry for your loss quotes 

Anveshj said...

Thanks fort he best share and i loved it, 192.168.o.1

YoWAPlus said...

Adventures in yo whatsapp Insights from the homepage specializing in whatsapp versions https://yowaplus.net is an exciting adventure.

Alpha said...

Yeedi vacuum cleaner is considered the smartest robot vacuum out there. Find more info here and read the guide thoroughly so you don't miss a thing.

APK said...

Free download whatsapp yc whatsapp from here. YC Whatsapp APK 2022

APK said...

Descargar Minecraft APK Gratis

Descargar Youtube vanced 2022

Martin Washington said...

Thank you for sharing this useful information, download free fonts suitable for all models, for those of you who are passionate about editing press now
click

jyotikumar said...

I was looking for this article. Delhi Hot Girls A responsibility of appreciation is for posting.

Zack Knight said...

Descargar Cuphead CDV APKSi desea echar un vistazo a la colección múltiple de los archivos apk del juego, puede visitar aquí

James Smith said...

you can expect to receive business law assignment sample from our academic professionals catered to your specific assignment needs. Unlike other services, we won’t dust our hands off after paraphrasing off a Wikipedia page.

Didani said...

The competition for this robot vacuum is increasingly high right now. You can see that every product has 1k+ purchases online. I am considering to purchase this yeedi vac 2 pro as my first robot vacuum.

chloe decker said...

Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing.
math assignment help

Angel17 said...

Such a nice read. I enjoy reading this one. Thanks for sharing! www.appliancerepaircalg.ca