Python for Entrepreneurs Transcripts
Chapter: Monitoring and logging in production
Lecture: Introduction to logging and monitoring
0:03 The last thing you want to see in your web app is some kind of crash,
0:07 a 500 error or maybe it's even a little more subtle than this falling octacad,
0:12 maybe it's some button doesn't work, because behind the scenes,
0:20 So, how do we know when this has happened? Right,
0:24 our server is not going to tell us, it's just going to return 500 to the user and that's it.
0:28 Our users will tell us sometimes, if someone comes to buy something from you
0:33 and they see this page instead, they are going to lose a lot of faith in your app,
0:37 in your product, they are going to wonder - did you already charge their credit card
0:41 or did it crash before? Should they try to buy it again,
0:44 will they be charged but not receive their product? Whatever it is.
0:49 This is really bad when your app crashes or behaves badly.
0:54 So how do we know about it?
0:57 Well, users will sometimes tell you, but for every user that tells you
1:00 something is wrong, there will be plenty of users that have come to your site
1:05 and just got, "this thing is crap" and left.
1:07 So, relying on the users is not enough,
1:09 and often they will say "well, it crashed and I tried this and it didn't work",
1:12 how do you know what crashed, how do you track that down?
1:15 So, we want to first talk about how we can at least record this information locally,
1:19 some of it, so that we have it, and ideally, we would get notified,
1:24 right away like possibly by the time the user was done typing up an email saying
1:29 look I went to this URL it crashed, you've already actually got it fixed,
1:33 or you are already working on the fix and you can shoot them a quick note
1:37 "hey thanks, I already noticed here is the problem, come back in 15 minutes
1:41 and everything will be working great",
1:43 that actually turns a bad experience into pretty good experience,
1:46 if you hit a website and the owner already
1:51 like maybe proactively emails you saying "hey, I saw you run into this error,
1:54 I am working on it, it will be fixed soon", before you even contact them,
1:57 that's ridiculously good customer service; so, how are we going to do that?
2:00 Well, two main things- we are going to start with logging,
2:04 so having logging is important not just for the errors the users run into,
2:08 but also for auditing who logged in from where, when,
2:11 people trying to hack your website, what other things are going on,
2:17 are you running out of memory and so on, how many requests per second,
2:21 there is just lots of stuff that you want to do in logging
2:24 that you are going to come back and look at.
2:27 But that's just what I would think of as level one, right,
2:30 logging puts into a file what has happened, and if you bother to go sift through that file,
2:34 you might learn something about what's happening, that's great.
2:37 But, like I said, ideally, you'd like to know straight away when that happened,
2:42 so we are going to talk about monitoring with the Rollbar,
2:44 and how we can actually capture, not just some of what went wrong,
2:49 but possibly even the state of the variables in the call stack, the URL,
2:53 the platform version, the browser version, everything about the application state
3:01 from both the client side and the server-side and send those notifications to us right away.
3:06 Slack, text message, whatever.
3:09 That's what this chapter is about, first we are going to focus on logging
3:12 and then we are going to sort of take it to level two the next level with monitoring.