Laravel Telescope - Features & Examples

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys Andre here and today I'd like to take a look at debugging and monitoring your application with laravel telescope this is going to be a part of my premium course so if you like this video definitely sign up at useful laravel packages calm alright so let's take a look at laravel telescope the website describes it as an elegant debug assistant for laravel it provides insight into things like requests exceptions logs queries queues mail notifications and so on so let's go ahead and take a look at some of its features now also be sure to check out the video of Taylor announcing and demoing it at lirik on a you I'll link to that video below a lot of the examples I used from this video are similar to what Taylor demoed ok so I have a bunch of examples mostly in my routes file right here but I have yet to install telescope so let's go ahead and do that first so let's go into the documentation page and that US composer require and laravel telescope let's do that real quick ok next is to run the telescope install command let's do that okay and that published service provider assets and a config cool and now we have to migrate and I already set up my database and my credentials in my environment file I also set the app URL and I asked me users I have the auth scaffolding setup in their Bell and I have three users in here because we're gonna be looking at models as well so let's migrate and that added some entries into our database right here telescope entries and telescope monitoring okay so now if we go into our app and by default if you're in local development environment and we are local right here then you can go to slash telescope this is the app slash telescope and you'll see the UI there let me just make this a bit bigger so let's take a look at some of the files that it created so config telescope is where some of the settings are down here telescope and we will leave this the way it is there's also a telescope service provider and the first thing I want to do is change it to night mode there is a nice dark mode here and it looks pretty good so we'll stick with that so what else is in here so if you scroll down here you can also set the permissions on who can view it like I said by default in local anyone can view it but if you want to change that or if you still want to use it in production which we'll take a look at later then this is where you would define who gets access okay so let's go into our app in the browser over here sorry it's not in here let me just open a new tab here and just go to the main site and let's just login let's hit a few routes actually login I have a user named user at user calm and password okay so I'm logged in and the first feature is requests and as you can see there's a new button here it says load new entries and this will just show every single request that was made in our app just now so you can see these are all the routes I hit and you can dig down and see more information about that request for example if your a lot it is a lot than user the no-show here and down here there's more information about the headers the session the response and also the queries that are run so that's pretty cool so up here if you turn this on it will load the requests automatically so if I go here and I just go back home and let's go back here you'll see that it loads automatically so a lot of these other features always link back to the request specifying which request it was related to okay next is commands so as you can see we did a migrate command let's do a few more here let's do HP artist and inspire and let's make a model to HP arson make model say to do and let's do /a so it generates other things as well controller and migration and yep as you can see they loaded here the ones we just ran and you can go in and see the information about them the arguments and so on and so forth cool okay so let's see what's next the schedule so I already have a scheduler running on my computer and let me just go into here HTTP so console kernel and it's at a command here so let's just run that the inspire command every minute so I say every minute every minute and let's make sure to store the output store output okay so if I save this and there you go you see that after some time passed this showed up and you can see the output here so this is a good way to debug your scheduler and seeing if it's running correctly and if we go back and if we wait a few seconds here since I have it set to every minute there you go there is the next command so if you're not sure how to run it locally actually just learn this for this demo to crontab - e and put this command in the first line and that should run on your computer every minute these stars represent every minute and you can change this interval if you like but and if you have a server that should like if we're using forge that should be set up for you automatically and I do use forge so all right what's next jobs so I have a generic job here called some job and it is taking in the user as in the constructor and it's sleeping for 4 seconds and it's running a bunch of logs and that's so we can look at the log feature as well but right now I actually have horizon running if you look here there's horizon line running and in this other tab over here there is horizon so I also have a route that dispatches those jobs so if we're going to my routes file what's called so job slash the number and then that's it's gonna dispatch a certain number of jobs so let's do that I'm gonna do job slash say 5 sorry jobs slash five okay let's take a look at horizon so you can see they show up here and I think they passed yeah they all passed here so yeah horizon and telescope are very similar in this sense horizon has more features you can do things like balance your cue and have different rules for that but in telescope you can view the jobs that went through and drill down into each one and see more details like which user ran it and there's some tags associated similar to our horizon works which QR ran on which connections using and unless you're white spending that should be completed so yeah I could be a bug telescope is still fairly new and continually getting updates okay let's look at the next one for exceptions so no exceptions were thrown yet so I have around here for exceptions I think yeah so just throws a generic exception so let's hit that route slash exceptions so there you go and you see that here cool and just like everything else you can drill down and see more information about the exception if it was tied or like if a user that was logged in triggered it here's a message and here's a cool small feature if it's trigger triggered multiple times so I'm refreshing a few times here then it won't keep showing up on the list because that's gonna take up too much space but you can see that number of our currencies went up and you can go in and just see the other occurrences here so that's a pretty cool small feature okay so what's next stick a look at logs and I don't know why my logs didn't show I ran that job that had the logs run let's try that again so I'm gonna run the jobs run again some jobs let's say three this time class user not found what the hell oh sorry okay try again okay so rising processors them okay but does yeah no it stays pending let's see if the logs come in okay so I'm gonna restart horizon and try again okay let's run those jobs again three jobs let's see if they go in here they do okay so another processed cool and now the logs should show up and there they are awesome and I think all the other ones ran to say yeah there's something wrong with my queue worker so I just restarted horizon and now everything works as expected so yeah all I did in that job was just log the different types of logs with a job some job so just these different types so emergency alert and they show up at different color tags here and you can drill down as everything else there's not much it's just a long message cool this is a good alternative to just going to your server and dumping out the layer of a log files okay let's look at dumps so everyone's favorite level command is probably the DD die and dump the best debugging tool ever and laravel 5.7 introduced a new dump feature which allowed you to debug and dump data without stopping the execution of the script which is very handy let me just show you how that works quickly and how then that relates to this dump screen so let me just click off this and you'll see why in a second so I'm gonna run at the peach the artist in dump server so that's writing and in my routes I have a route called dumps I think where is it here and it's just grabbing to users dumping the first one and dumping the second one and then just returning a message so since our dump server is running and if I go to dumps then we shouldn't see the dumps here we should just see the return message okay and we do and we see it in our dump server here so that's pretty cool but if we don't have this dump server running I'm gonna control see out of it so I'm not running the server now the dumps will appear on the screen so there we go so works pretty much similarly to the dumps tab in Telescope where if you are on the dumps tab and go here then this should not show up because we're on the dumps tab so there you go and it appears here cool but if we're not on the dumps tab then it will show up in the browser so yeah that's a pretty cool feature and can be very handy for debugging and not interrupting your script so yeah that's pretty much it you can also see the requests that came from so if I click on this it goes to the request that that dump came from and you can review all the information about the request all right queries so as you expect every query that happens is logged here and you can again drill down to the request where it happened and you get a nice nicely formatted raw query that happened here and there's also a cool feature which allows you to monitor slow queries so let me show you that I'm not sure if it's in the config or the service provider let's see so the config is it in here no it is not it's in the service brother then no it's in the configure should be in the config okay right here so this lets you specify what a slow query is so right now all of our queries are running pretty quickly less than one millisecond obviously used to be higher if it was in a real production database but we can specify what a slow query is so they said to really low if you look at here some of them are below point five and some of them are above 0.5 and if they are above 0.5 or whatever threshold you set here then it will appear in red here so let's go into our app so I'm gonna hit this route and this should have some queries and it shows up because we're not in the dumb tab obviously this should have some queries long you know let's log out and log in again okay so that should have put a few queries in there so let's go ahead and see a little new entries so this should be read that I saved that okay there we go I just refreshed here's all the queries that just happened and the ones that are above five milliseconds are in red and you can go ahead and investigate what's going on now personally I still think using laravel debug bar which is a similar package which has been out for a very long time I still think that's better for queries because that if you use that before I probably make a video on that too but you'll see that every page you go to in your app there's a little debug bar down on the bottom and that allows you to monitor the number of queries on whatever page you're on and you can easily detect and +1 queries better because each page has a number of Cui's and so say you just go on different pages and you see the number of queries that ran on that page if it's unusually high then you can see that there might be n +1 issues on this specific page but for telescope it just dumps everything into here there's no real numbers on to how many queries on which page you're on so yeah just personal preference so yeah you can definitely combine them this should still work together nicely all right let's take a look at models next so this happened two minutes ago this is just when I logged in and since that updates the updated lat field then it tacks it as an update but this records all the crud options for all your models and again it goes back to the request and some other information here so let me show you what I mean so if I register another user actually let me delete a user yeah let's delete a user because I've arrived for that in my code so right here if I hit delete it's gonna take delete the third user and that will show up in our models file models tab I mean so it's it delete I delete it and you should see that here cool and if we register another user so let me just log out here and register users it's registering creates the user that should be added thereto to the model hi password ok cool and then that should show up here there you go cool okay let's take a look at the events so as I was doing stuff specifically in horizon there were events that were raised so you can drill down look at the events and you can see the Associated listeners with them you can drill down to the request you can see if there was a job associated with it you can view the job and it goes to the job so yeah all the information you need to know about events go here and I think I have a route for events too it also knows if it's a broadcast event if you're saying if you're using something say like pusher and you broadcast events so I have an event called here called some event and it it should implement should broadcast so let me just put that in so implements should bark should broadcast and then let's hit that route so events just raises this event and it just passes in a user is it dropping a user okay it wasn't my example but I forgot to put it here so let's quickly pass in the user so I'm just gonna use this handy package user oops okay and it's type into here let's import it okay and this should be public okay so now let's hit that route and we should see that it's tagged as they should broadcast event so back to our let's go to events event fired and note that no entry there you go so you can see that it's tied as a broadcast event okay now let's look at mail this is easily one my favorite features along with the dump tab so personally I use and love mail trap for testing email it's easy to use and the closest thing to sending a real email and gives me confidence that emails actually gets sent however if you're still early in development and just want to see your emails being sent out as well as a visual representation of how they look yes I know you can also view the contents of your email in the browser but that kind of interrupts your application code so this way you can just set your mail driver to log and inspect the email right in this tab over here so let's make sure I think I have it set to log so where's my Metro okay it's at the log so let's go ahead and trigger some emails so in the forgot password authentication stuff that just sends out an email so let's trigger that in this log out so if you go to log in I forgot your password so let's type in the user and that's send it okay so in mail if i refresh there it is right there and you can look at it again same as before you see all the information about it to from which mail bullets using and you can actually download the EML file and view it in different mail clients like again you can view the requester game from if the user was logged in or not logged in but the user that triggered the email and here is the actual email so you can quickly inspect it this should work because I said the app URL in our environment file so this should actually work and yeah it's a really handy way to test emails when you're still early in development okay what is next let's look at notifications so as you can see that reset password is a notification as well in laravel but I have another one in here what did I call it I call it invoice paid and usually you would pass in an invoice here but I don't have a model for invoice so it's not passing anything in but we can still see the information so notifications in here it's right here and you can have different channels by default there's only mail I think SMS leading next MOU and database notifications but there's a whole bunch of other drivers which you can use like slack or Twilio for a different text message service provider and yeah like I li expect this just has all the information about the notification that was triggered so it's one that this URL was a notification yeah notifications notifications okay and then we should see ain't no one here right there and you can see the channel here this would obviously change if it was a different channel and yeah as you expect all the information about that notification cool ok the cache as you can see there's some hits and misses when we were logging in and there's some caching going on there but I think I have a route for cash as well I do so all it's doing is remembering the user for one minute so if I hit this there's gonna be it's gonna look for it in the cache it's not gonna find it so it's gonna set it for one minute and you'll see that reflected in the cache tab so let's hit this cache use your cache for one minute and there's no entries there and there you go you saw that it wasn't in the cache and so it said it so I'm gonna wait a minute actually no if i refresh this now now I was hitting the cache because it hasn't been a minute yet so I refreshed it three times you should see three entries here for hit okay but it's only cache for a minute so I'm gonna wait a few more seconds after a minute has passed and then it will miss and set again because it's been passed in one minute a few moments later okay so it's been over a minute let's go in here refresh this again it should be a Miss and it should set it again so no entries there you go so yeah good insight on the cache here and Redis is very similar so if you want to store information outside of the database in Redis this gives insight on to the Redis commands that have happened so I have another route here for Redis just setting my name and getting my name and you need to run this command for Redis events to happen and to show up in Telescope I just put in here you should definitely put this in a service provider of some sort and yeah let's see if this works so let's go to Redis there you go ready sytem set and there they are they're cool so generally speaking you would mainly use this for development but it can be used for a lightweight monitoring service for your production app so if it's in production it's obviously not going to store everything because that is a ton of information but it still stores by default some important information which you can use to monitor your application so let's first set our environment to production and now stuffs not gonna be recorded well not everything's gonna be recorded so if I go to the main page hit it a few times or a login none of that is gonna be request shown in the request actually I also don't have permission anymore because we're in production so that's not gonna work so now you have to go to your service provider and set this so let me just set the user I have in here it's going to put that users email address so this user should have access when they're logged in obviously you would make sure that the user isn't a min in a real app so let's go in here and it's login so a user user a.com and password so now I'm logged in and now I should be able to access this okay and I am but now so yeah you see me saw me hit all these routes but they're not being recorded because we are now in production so if you go into your service provider again right here is where it specifies if it's local then record everything but sorry not this this so if it's local return everything but if it's not local then only return this stuff so if it's an exception a report will exception if it's a failed job if it's a scheduled task or if it has a monitored tag which I'll show you that in a second as well so yeah exceptions will still go through so if I hit my exceptions route here world is going to end exceptions there you go just now so this is exception still get logged field jobs will get locked and when I want to show you is has monitor monitor tank so you can also monitor specific tags so each model gets a tag so it's going to be model name : the ID but another thing that gets tagged is logged in users so that would be tagged as off so fight mother off one monitor that and I'm logged in as user ID one right now now whatever user ID one does it's it's gonna be logged in here so you saw earlier that it wasn't being logged but now it will be so you'll see if I go to wait I'm not logged in yet so these won't be long Oh actually I am logged in so so you'll see a few more requests going because I'm monitoring that tag and there they are right there so cool so this is for instances when there's something weird going on with a certain user and you can monitor the tag and see what's going on so there you have you guys we managed to take a look at laravel telescope to debug and keep an eye on the things that are going on in your application definitely an excellent way to debug your application so you would probably just have this in another tab or another monitor open at all times so you can quickly keep an eye on everything in your app please like comment and subscribe if you haven't already done so thanks for watching guys see you in the next one okay thanks bye [Music]
Info
Channel: Andre Madarang
Views: 18,135
Rating: undefined out of 5
Keywords: laravel telescope, telescope laravel, laravel debug, laravel debugbar, laravel dump, laravel dump server, laravel telescope example, laravel telescope tutorial, andre madarang, drehimself, laravel package, laravel insight, laravel requests, laravel local, laravel development, laravel developemnt environment, laravel 5.7, laravel queues, laravel mail, laravel log, laravel database query
Id: ctU0FWbutHs
Channel Id: undefined
Length: 31min 10sec (1870 seconds)
Published: Thu Nov 22 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.