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