Python for Entrepreneurs Transcripts
Chapter: Monitoring and logging in production
Lecture: Creating your Rollbar app

Login or purchase this course to watch this video and the rest of the course contents.
0:02 Now you've seen what Rollbar is all about, you probably want to add it to your app and the first thing you need to do is
0:08 create an app in Rollbar that represents your app that you are actually building,
0:13 so you can create a brand new project or I am going to create one from GitHub repo, and that's it, I just click that button and boom, it was done,
0:23 so you can see I did this from the demos repository, I'll probably end up changing these codes over time,
0:30 but if we were going to do JavaScript like AngularJs, jQuery-type stuff, and catch client side errors you can use this code
0:39 and we are going to do mostly server-side error tracking this is going to be for our Python app, so we are going to want to use this code.
0:47 Now it says "if you want to set up the client side bit you just drop this in", boom, you are done, you can drop that in like your layout,
0:54 your master layout page there, and then, it also shows you how to handle error messages and things like that,
1:02 we'll go down to the configuration reference, actually click on code brace integrations, Python and then we have Pyramid.
1:13 So it says in your ini file, production.ini or whatever, you are going to add this to the Rollbar includes, you can do it here in the includes,
1:23 I actually like to have that in code so let's go over and do that in code here, so in our dunder init, come up to the top, there is an init_includes
1:34 and we just need to add one more of those so we are going to use rollbar.contrib.pyramid.
1:41 Now, this is not the package name, it is package name but this is the PyPi package, which contains that as a subpackage.
1:51 OK, and then we need to add this into our pieces here so let's go and do it like this and let me just do a divider
2:05 and this actually appears above this main, so be sure to not put it there twice, it hates that.
2:12 So here is our Rollbar setting, and we are going to put our production key here,
2:29 so let's go and do that and I'll put maybe a note "js key =" whatever it does, like so,
2:38 so in case we want to put that in later, I guess we could look it up.
2:41 Anyway, here we have our things, now it says rollbar.acces_token, rollbar.environment
2:46 and we don't actually have to worry about this, we don't have to pull these in, all we have to do is basically have the configuration there
2:55 and we are going to have Rollbar go and when it gets included, it's going to go look in that configuration.
3:00 That's cool, right, and this is not misspelled, so we'll do that. Right, a few more steps here,
3:14 so next it says, we want to replace our app:main which is right here, with this bit here, like so, and the name is blue_yellow_app.
3:32 So we want to make sure that appears where it says YOUR_APP_NAME, OK, Alright, that's looking solid, anything else we have to do? All we need to do is
3:44 filter part here, I'll put that down below as well, a little bit of copy and paste into various places, I think we are ready to go.
3:59 OK, let's just run it and see that it hangs together. It does not hang together and why not? Because there is not module name Rollbar,
4:07 of course there isn't. We haven't done anything that has triggered PyCharm to say
4:12 "hey, don't forget to include this", but we will make sure we put it in our setup.py.
4:20 Alright, so let's just put Rollbar in here, I'll come back and organize that, now it says oh this is not satisfied, let's go and install that for us
4:28 into our virtual environment, now we can give it another try. We got much better chances of success.
4:35 Oh I'm missing access token somewhere, oh, again, I am using the wrong one, let's go switch back here to our configuration file,
4:46 that's the one we are actually working with. So if we run this again, excellent, look at that Rollbar is already initialized,
4:54 so we don't need to do it again, very cool. Alright, so it looks like it's working, one thing I just want to double check
5:01 before we get going is notice it says environemt=production, let's change that to dev, first of all,
5:06 let's take that away from it, let's move this stuff over into the production.ini, what else do we need to check? Check this little top bit here,
5:22 and we have the filter I believe at the bottom. Fantastic. OK, so this is all setup and good to go, we got our production, our production,
5:40 maybe give a little extra space here, production there and guess what, that's cool for production but this is the development one,
5:48 so let's go to the few places where it says production, and put in dev, dev, dev. Alright, well, it looks like we got it working,
5:56 where do you think we should go crash this up, that seems like a good idea, let's just go and make sure this is empty.
6:03 Alright, if we go to items we go to our dashboard, it says "it looks like you have no data, no errors",
6:08 and it just comes back and tells us our keys, and encourages us to set up, here you can see all the different languages supported
6:14 again if I click on Python, I get like the basic usage, how to set it up as middleware, here at Pyramid which is really cool, we've already done that
6:23 so let's go and see if we can make this crash, we tried to write good software, let's try to write some bad stuff, alright.
6:29 So let's make the home page, let's make the sign in crash, and here we'll just say something like this,
6:38 "raise Exception('Boom!')", something like that. Alright, so if I try to sign in and if I submit that form, something bad should happen,
6:49 so let's just clear out those logs there. OK, let's do a little log out / log in. "cat", here we come. Bam, exception.
7:02 Now this is what an exception looks like in your dev mode. But in production, you don't see all this, like users just see something like nginx,
7:11 bad request or could not process request 500 error. And that's it, just boom 500, nothing else.
7:19 So imagine you don't see this and now, let's go look at our app. OK that didn't look good, does it, did it submit it, we'll go find out.
7:31 Now look at that, I refresh Rollbar and guess what, boom, there is an exception. Now, that's pretty straight forward, because the way we wrote it,
7:42 but let's just go look around and see what we've got. OK, so we've had..., here is how many times it's occurred
7:49 in the last 60 minutes hours and days, and we can see OK, here apparently is the call stack, let's look at arguments, check this out,
8:01 we have sign in email and password and how fantastic is it that they are staring out the password, like that is just attention to detail
8:09 like nobody's business. OK, so that is really cool, the error was this, it happened on this line, because we wrote this but in a real crash
8:18 we'd have our inbound data that we could look at, OK so somebody who is signing in,
8:22 this was their user email address and this is their password and it crashed, we also looked if there's locals I don't really think there is much there,
8:30 OK, occurrences, it occurred once on Firefox on my Mac, surprise surprise, people - no, there is no person, we didn't integrate the people API
8:41 there, these are the browsers, it loos like Firefox is causing us, Firefox 50 is causing us a lot of problems,
8:47 obviously this is both more important in the JavaScript reporting as well as in real life.
8:54 OK, we have IP addresses, this is the one, is there expected deploy? No,
9:00 see if it click over here what do we get? Here is exception, you get all the information. Here is some other information I didn't show you,
9:09 these are the parameters that are actually running in Pyramid. So, it contacts the account controller and see it's in dev environment framework,
9:18 there's Pyramid, there's the version of Python, level of error and here is the version of our notifier,
9:25 not that that matters so much, here is what our POST consisted of, and our GET request consisted of, these are the actual headers,
9:33 I mean, just it goes on and on right, look at all this stuff, there is probably cookies in here somewhere,
9:37 here is the host name, look at this if we want to replay it, let's see, I wonder if it still crashes- let's find out.
9:52 Yep, it looks like we still got some trouble going on here, boom, not the best, is it? OK, so this is really cool, you can even see the raw json
10:03 which is what was submitted by the API. So that's it, we've integrated this error tracking and error monitoring into our web application.


Talk Python's Mastodon Michael Kennedy's Mastodon