Azure Application Insights Tutorial | Amazing telemetry service

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
👍︎︎ 1 👤︎︎ u/MrStLouis 📅︎︎ Feb 05 2020 🗫︎ replies
Captions
hey guys this Adam and I have a question for you did you ever try to build application across multiple services and multiple components if you did you already know that creating a proper logging solution might be a tough challenge but this challenge might be in the easier if you use the right tools and the right tool for the job is our application insights and that's the topic for today so stay tuned other application insights is your everyday monitoring service for your application in Azure it's your application performance management service and it's part of the bigger service of your monitor and this is important because whenever you're going to be searching for some documentation about application inside you're going to be redirected to either monitor or log analytics because those services are tied together into one big service so how does it work first of all let's imagine scenario where we have web application with three pages home orders and products those applications usual we'll call some back-end service like a web service which will handle all the requests maybe generate pages handle orders products and all the things within your web application and then this web service might have additional service that it connects to and usually it will because inertia you pretty much develop everything using components so this web service might call an SQL some external API or maybe your own internal API so for some additional jobs and for this kind of architecture it's quite tricky to set up logging and this is where actually application insights common because first of all you can setup application insights on your front-end pages for some client-side monitoring this will pretty much work like Google Analytics so it will track your user behavior on your front-end pages and some requests to the back-end service they can also install it on your web service or your entire IP is to grab the server-side monitoring of your application and this will work actually with an error or known are services as well because this is pretty much an SDK or an agent that you need to install notice that you cannot install it an external API or SQL if you don't have any control over it but it will still allow you to track the dependency calls to those services so you're still good you have the data inside of the application inside you can do a lot of stuff with it so you can actually create others connect with power bi maybe Visual Studio use forest API or continuous export to analyze the logs yourself so you have moved to put ways to analyze and react to whatever is happening within your application and is one of the best ways to do distributed logging very easily with an azure what does it track first of all the most important ones are request rates dependency rates and exceptions and exception logging is one of the most powerful features of the service it very nicely shows where exactly within your application and the exception happened what caused it and what can you do to remediate this issue it will even show you the entire trace of the entire request with user flows what led to this exception I very often found myself finding the issues with my code without even needed to debug the code itself so I really love this feature additionally it tracks page views load performance and things like that because it really acts like Google Analytics as well allowing you to see the user and sessions and analyze those session within the azure additionally it allows you to track host diagnostics and even custom events so you can build your own events and track them with an application insights as you see with this application insights can pretty much track most of the important stuff of your applications this makes it one of my favorite services for monitoring in azure once you actually gather the metrics there's multiple tournament reviews that you can use to view the data of your logs for instance application map is another cool feature of application insights it creates a visual diagram of your application based on the logs itself so it's pretty neat that it allows you to visualize how your application is working solely based on the logs of those applications another view is smart detection view where it grabs automated log detection for failure and performance anomalies so if you went over for the night and something happened within your application you will see those events grouped by the category within this panel of smart detection you will get even automated alert with email notification about something happen with your application so you can very quickly react to those additionally you have you analytics as I said this is one of the features that imitates Google Analytics you can track user retention segmentation demographics and all the cool stuff about users from the perspective of the front-end application there's also live metrics stream one of the cooler features for developers because it allows you to see your logs on the fly as they come in so if you're developing distributed applications read in real time and you're seeing some events flying by some requests being failed you can actually very quickly see and react to them within this panel and actually refresh his life so you can pretty much see everything as it goes and see all the dependency calls all the request rates all the tracers and all the errors that are happening within your application you also have Search Search panel allows you to visualize your logs and traces on this panel and see them over the time and if you need some more advanced features you also have analytics panel which allows you to write a very powerful query using cousteau query language so you can actually grab your logs and write a custom sql-like queries and see the analytics and analyze the logs yourself from entire application and because application in size is very powerful it has a lot of additional views like metrics Explorer as it is part of our monitor you can create dashboards out of pretty much any metrics that are stored with an application insights you can actually connect from visual studio because there's a native integration there you can do snapshot debugging if you actually found some error in production you can debug from memory dumps connect with power bi REST API or even to continue the export of your logs to something like Bob storage and use pretty much any tool to report on your logs and analyze those logs yourself a lot of features that you can actually use to review pretty much any logs in any way possible of your applications and that concludes how the application insights can help you within your applications and we can actually go to live demos today we're gonna do a lot of live demos a lot of cool live demos first of all we're gonna create a web application in Azure and attach application insights to this then we're gonna create a server-side monitoring using dotnet core then we're gonna do a client-side monitor so we're gonna track our jQuery like application we're gonna be doubling with failure viewers I'm gonna imitate some issues within our code and try to debug it live additionally I'm gonna investigate the performance I'm gonna query the application telemetry logs in log analytics and lastly I'm gonna show you how to do it without even using the code so a code less monitoring of application insights so what is the demo architecture for today first of all we're gonna set up a very simple jQuery application which will connect to a server side API which was written in dotnet core and then we're gonna phone all the logs to application insights after this we're gonna create a small function up which will call external other services a queue service and a block service and everything from that we're gonna funnel the application inside so that we can see this nice application map at the end which will show us our architecture and entire dependency calls from end to end perspective so let's go to the portal so let's create a web application and attach application instance to this to do that let's go to create resource type web app and search for web app this is other application service let's hit create let's create a new resource group called up in size intro let's give the same name to the our servers let's see if it's free it is so let's use that I'm gonna choose the runtime stack as dotnet core 3.0 and I'm gonna host myself in north Europe I'm gonna choose an app service plan I'm just gonna change the name so this is more convenient for me and I'm just gonna leave it as s1 by default next I'm gonna go to monitoring tab in which case it says do you also want to provision application insights with the service in which case I'm saying yes I do and I'm gonna hit create new give it the same name and just review and create and hit create right now this will create two services for me one being an app service this is my hosting environment for my front-end application and another will be application inside that will automatically get tied to this app service by default I'm going to show you later that in a configuration tab when this service is created and after that I'm gonna actually show you how can you extend it to another application using the same application inside instance my services will be provisioned in just couple of seconds after which you just click go to the resource to review what was created right now there's nothing here because I didn't deploy any application yet but if I will go to my resource group you'll actually notice that first of all we have observers plan hosting our observers so this is our compute power but we also have application inside service if you go to application insights you will see the most important stuff which is the connection string and instrumentation key this is like your password for the application inside this is again very similar to how Google Analytics works and it's a good example and there's a lot of panels that we're gonna be going through today a lot so right now I'm gonna leave them there so let's go back to our application let's go back to our app service and nothing is something interesting here with an Settings tab in the configuration pane you can find the default configuration for that environment and one of those application settings as see are upsetting instrumentation key which is the key value for your service so you don't really have to configure anything additionally by default any application deployed to this observers will use those variables by default whenever deployed to this service instance so this is pretty cool of course if you already have up in service you don't really have to do this and redeploy entire service you can simply create just application insights and input those parameters in the configuration so it's up to you all right so what's the demo since we have the service provision let's actually create a very small application I have a lot of samples for you today and first of all we're gonna create a new dotnet application using dotnet new MVC I have two windows of Visual Studio code one with my samples and a second one with empty folder called demo where I'm gonna create my project so as we see we need dotnet new MVC so I'm gonna run this command in a terminal to create a sample web application within dotnet car once I do that the next thing that you need to do is to add microsoft application insights for asp.net core package so I'm gonna up the package and the demo that we're doing here is using the code to report application logs but there's also a way to do this on up services which I'm going to show you later for now let's add the package and once the packages are that you need to do two things first of all you need to add this application inside section to your code to the application settings development setting so I can just add it here and add this new section and this is actually the decision for you to make if you add this section here and add the instrumentation key you will be actually also longing everything from your local development environment so it's up to you whenever you want to do it or not I usually do it but in this case demo it's not required if you don't want to log from the local development also add the stood up setting and the next thing that you need to do is add the telemetry setting so you need to add this line services add application insights telemetry and you need to do it before add controller reviews or if you're using older version of.net core this will be before services at NBC so let's grab this line and it has to be done with and startup CS phone so let's go to the startup CS file and let's find this add controller reviews and let's add this additional line here once this line is added and the file is saved let's add an additional view so what we did so far is that we added server-side monitoring and this is pretty much as simple as it gets just the single line with the package and your application is already doing server-side monitoring if this is so easy let's see how easy it is to add a client-side monitoring for our jQuery application to do that go back to our snippets and copy this raw HTML which will add the snippet for our views so let's go to views heard go to the layout and pretty much inside of the header find the head section and at the end of the head section insert this this will pretty much the output inclusion for JavaScript snippet for the application insights and to ensure this works you also need to add within the view imports another line which actually injects application insights Java script snippets to your tags and you can actually review it by this squiggly line disappearing at this point you actually set up of server-side monitoring and client-side monitoring and to test that let's actually implement a very small API and very small application on the front and side since the setup is complete now it's up to us to test it I post the video here for a second to fix the order of the Falls because I notice it's incorrect the next thing that you need to do is add a controller we need the controller so that when we call an endpoint we actually have an endpoint to call and I call the demo controller so just copy at this entire file and go to your application open controllers folder create a new file on the demo controller see yes and paste in the code so here what it does is actually calls the function which we will supply in a second by this function URL but until you do so you can actually comment this lines out and just return text hello world this will return a very simple response saying hello world to our JavaScript application once you have this done you can actually go back and go to this pane and copy the add button HTML so let's copy that this is from this Add button demo API HTML and go to our home view to our index and add this entire HTML at the very back of the screen you can very quickly test if everything is working by hitting f5 to run this application using dotnet core and if everything worked fine we should see our application running this is how I created a very small app running locally I added a message here remember to disable adblock because as I originally said application insights are working like Google Analytics so if you have something like you block origin it will actually block the application in sites as small so remember to disable it once you disable it you can actually call functions and see the hello world message if everything works fine at this point you can actually like this to Azure and see the telemetry already running so let's do that let's close this application let's close the debug session and let's deploy this application to other to do that let's open the editor go to the other extension tab here let's open our other app services let's refresh to find our newly created up instance intro of service let's right click hit deploy to web app let's select the demo folder that we're in and let's add the configuration for deployment just hit deploy close all the paints and let it run all right the deployment finish so can I have actually hid in the bronze website to open external website this is our other observers actually already with an azure CA call hello world you can actually see this running this means at this point we can actually go back to application insights and start reviewing the logs so let's go back to our portal let's go back to application insights and there's a lot of stuff that you can actually see here but the first one that we want to do is go to live metrics stream because it's the first place and the ileus place where you're gonna see your logs all those panels have like five ten minute delay on whatever is happening but here you're gonna see everything live so we have this request pane as you see some requests were coming through so let's go back to application let's hit the button couple more times as you see I'm pressing it a lot let's go back to our application as you see big spike because something was happening some requests were flying and you see that currently in the panel so I already know that the telemetry is set up correctly and application in sirs are gathering the logs from your application so let's close this panel and let's go to application map if I will go to application map by default notice that I already started gathering some logs first of all I'd notice that we have one instance of our application this is one that app service running the application there were already ten calls made to this application on average it was four point eight millisecond per call and currently only one instance is running when you hit on it you can see what are the requests that were made since we were only refreshing the home page we see cat and slash on the home page an average response time if you would be going back to application and switching the pages between home privacy in just couple of minutes you're gonna see those pages appearing there and if you're gonna call more functions and you go back here and refresh it after a couple of minutes you're gonna see more requests notice something interesting what happened right now I refreshed and I already noticed that we're getting some information but it's still only six calls because there's a small delay on the logging part we have app insights intro and the client this means those are the calls made from the JavaScript there are six calls made to external service this is our actually web service notice that it did actually not figure out that this service is this back-end service but we're gonna fix that in a second but you can actually see that all the calls were made we were calling the API slash demo average response time was 66 milliseconds and all the cool stuff so this actually closed this for a second and let's go back to application insights and refresh after a moment it was actually able to figure out that the client calls were actually to our back-end so they actually combined this into a single instance of our application allowing us to review the client-side part the Java scripts the calls made the back-end get API demo and all the application insights as Aria actually closed this foreign by mistake and you can actually review all the calls on the backend notice that we're getting some library is the bootstrap the home index the jQuery all the things that we're doing on the backend as well so let's a bit a bit more complexity to our application so let's create a function up very quickly create resource type function there's gonna be a function of available let's hit create and very quickly create a function of which will serve as our back-end service an internal API for the background jobs so let's pick the same resource group let's call it up inside function let's choose the runtime stack of dotnet chorus well same region which is nor Fura for me but before you hit reviewing create go to the next stop which is the monitoring inside of the monitoring instead of choosing to use the new application insights choose the existing one already so that make sure that application insights are actually serving both observers and the function up at the same time hit review and create and hit create after a minute the function has been provisions I'm gonna go to the resource and within the function up I'm gonna create a very small restful endpoint for our application so I'm gonna choose in this case developing the portal well you should not do it for production is very cool for demo purposes so let's hit web poop plus API let's get create and let it create very small HTTP function for now we don't need most of that what is it within the function we can actually remove most of it and just leave the message of hello Adam so let's remove that let leave hello Adam message let's save this and to review that this actually everything runs correctly we can actually open the portal in the new tab go to our resource group up inside intro go to the application insights live metrics stream and in here you will be able to review the functions and to do that let's hit run couple of times and see the functions being already executed you can see the traces from the function as you see request successfully merge the route executed c-sharp HTTP trigger function process the request which is our first message here that means the tracing and the login is currently working just fine and to work with that we can actually grab this function URL from here let's copy that and let's go to our web application and let's go back to our call let's close this window let's open our demo control controller let's paste the URL here put the function code of course you should not leave that function code there for production but for the demo it's okay then let's uncomment this section and return the text now let's just deploy this to our observers the deployment finish had brought the website sure that open all external website call functions and you see hello Adam this is the response from our error function I'm gonna close this window and go back to our application insights now so see see the live metric stream are hot showing that something is happening with our our applications we can go to application insights go to application map and wait here for just couple of minutes after a couple of minutes I just gonna hit refresh to see the new result as you see now we can see entire dependency chain happening from our jQuery to our back-end to our background service in the back and also you can see two instances that are happening for the function one for the front-end you can review all the calls we made only one kid for the API HTTP trigger that we created for the functions the average response time and everything like that so let's close this demo by adding one more thing to our application very quickly let's enhance the applications by adding some queues and storage accounts so let's do copy this entire code into the functions so let's go to the function ops actually you have this already opened here let's place this here and let's also grab the code for bindings so let's save that let's go to files of course it's gonna fail now because I didn't ant new bindings I need to go to function JSON let's add the bindings let's hit save it should compile successfully so let's close that in let's go back here actually I'm missing comma here let's save that and see compilation succeeded right now this will actually try to save the bindings and what it will do is actually save a message to the queue called demo queue and it will save to the container called demo container and it will save it to the default storage that is used for those functions overall reason is to show you the dependency calls to the next general service that you don't have control over like the blob storage and a queue service so let's go back to our application let's go to the front end let's open the website let's call the function couple more times SEC we're still getting hello ah sure so everything works correctly but what we can also review is that within our research group we can go to the storage account that is used for the functions and we can open the storage Explorer to review two things first of all the blob storage the demo container as you see for every call we're making there's a new blob and let's hit review more blobs and the same for the queue so I'm pretty much outputting all the messages to the blob and to the queue at the same time and reason to do that is to show you how powerful application insights really are and to do that I can actually go back now to application insights go to application map and review after just couple of minutes that the new dependency chain and I will need to hit review a couple of times I just need to wait a minute or two so let's hit refresh right now and not something interesting cleaned up backend service background service and two external dependency calls to our services do you notice something familiar about this diagram this is pretty much the diagram of our architecture that we drawn in the beginning for the demo purposes we were actually able to draw the same diagram using the logs alone and nothing else this is what is amazing about the application map and application instance in general we're making distributed logging across multiple services and yet application instances are actually able to combine those in a singular poles this is pretty much one of the coolest feature of the service alright time so for last some demos for quick demos about failures and trace detection so let's open live metrics stream and in the meanwhile let's go back to the functions to make a very small mistake in the code so let's open function ops and let's try to convert something into integer that cannot be converted I'm pretty sure this will fail every time of the line 22 and remember that line number if we go back to our application and call functions multiple times notice that I didn't get any response something probably failed on the pakkun and i made a mistake on the purpose here because I wanted to be sure that my front end doesn't show anything yet we'll be able to trace it back so let's go first of all to life metrics stream notice that we already see some failure rates happening in the real time and while we could sit here and see this in the life the usual case that you're not sitting and not watching the live metrics seen what you would do on the other hand is go to application insights go to application map and after a couple of minutes I'm going to refresh this page to show you how to investigate this error let's hit refresh again to see some of the URLs already happening on the back end and you can actually very quickly see this is happening within functions you can click on this you can see top failing requests HTT trigger one you can click on it and this is very powerful feature first of all it tells you the errors over the time it groups them by the error message by the type of the exception what kind of fate dependencies did it have so in this case you can actually quickly see format exception let's hit on this one can't - so it happened twice it groups you and finds you the most common mistake it and it shows it as suggested so you can actually click on this to go even deeper and notice a lot of cool features in here first of all this one notice that it shows me entire session from my client web application calling my back-end API I can actually call this to get even more real estate then calling my back-end servers and then calling the functions and in function executing and then all the dependence is calling the checking so the head is there any blob on the blob storage and putting the blob doing the same etcetera etc all those dependencies until you get to the point where the rows ever happening notice that it still recognizes that this is everything within one session and at some point I made a call have actually happened and finished with exception when you click on this exception you will see those error messages here and the cool thing is this checkbox here just my code when you click on it and scroll down notice that in line 22 I've made an error if you remember correctly this is actually line 22 so it pointed me out exactly where within my function code did I make mistake that caused this issue so I definitely have to even deep dive and debug my session to see where I made a mistake and even more powerful feature is here a snapshot debugger if you want to use it you can actually debug this live using visual studio but for now this is it this is actually pretty powerful profiler that you can use to trace end to end transaction details of your application and telemetry if you want you can also use application map to investigate the slow performance of your request or you can use performance tab to do so here you're gonna see pretty much similar to errors pane where you can actually trace all the requests by their time and find the most clogging requests on your back-end API and also for those review what was happening and how did it actually what will the common parameters for those records that were slow so it actually will group by and try to navigate you to those slow requests so you have common demand denominator that caused the slow performance you will actually very easily find it using this feature and lastly you can honestly use either search as I said to review those logs here or you can do something better by going to overview hitting logs on the top and you can actually write those queries to see your traces and requests so you can actually type requests limit 50 press shift enter to see the live logs of your application and this is pretty powerful language I really advise you to learn crystal because it's being introduced into more and more service it's part of log analytics application insights other data Explorer and probably in future more services it's really nice language it will allow you to combine the logs into a single view and even then either export this to power bi or add it and pin it to dartboard as a live diagram it can also change the charts so you can review your logs as a chart and all that is pretty cool but what happens if you don't want to change the logs to log your application in site metrics many services with another actually supports application insights out-of-the-box instead of adding this package to my code adding this package to my front-end and tracking everything what you can do actually for some services with another you can actually go to like an app service an app service has the stop here application insights where you can actually enable your out-of-the-box agents without changing your code and if you're using any of your applications here it will actually allow you to set up without setting up within your code this is the code list setup for application insights and there is a lot of additional stuff and a lot of additional services that support this out of the box so you not always have to change your code to take the advantage of application insights and lastly what I want to show you just additional views with an application insights so here are the metrics so this is the part of our monitor you can even do alerts on this so you can unload yourself whenever there are felled requests you can use smart detection which later on will show you the common errors here group by category there is also a way for you to created automated availability tests so it will testing your application whenever it goes down it will notify you although is it is pretty expensive because it's ten dollars per one availability tests but don't forget that you also have this Google like analytics within the users so you can track users session events funnels or even do we like user flows for entire application what was happening in your back-end and front-end and how was user navigating for your application and there's a lot a lot a lot more features application insights is very powerful service that you should take advantage whenever you're deploying a frontal or back-end or multi service applications with another Wow we went through so many demos in such a quick time I hope you caught up but I just wanted to show you how powerful application insights very are and how many things you can achieve with a such a simple setup it's such a powerful service for login and telemetry if you're developing cross service applications using multiple components this should be your service to go for those purposes but for today that's it if you liked the video hit thumbs up leave a comment and subscribe if you want to see more and definitely see you next time [Music]
Info
Channel: Adam Marczak - Azure for Everyone
Views: 68,652
Rating: 4.9429026 out of 5
Keywords: Azure, Log, Logging, Insights, Application Insights, App Insights, Telemetry, azure app service, azure monitor, Distributed
Id: A0jAeGf2zUQ
Channel Id: undefined
Length: 34min 26sec (2066 seconds)
Published: Tue Feb 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.