Python for Entrepreneurs Transcripts
Chapter: Monitoring and logging in production
Lecture: Concepts: Monitoring with Rollbar
0:01 Let's review the core concepts of integrating Rollbar into a Pyramid web application
0:05 like the Blue / Yellow Rockets App.
0:08 So, most of this is going to happen in the configuration.ini file.
0:13 We replaced our app:main with pipeline:main and the pipeline
0:17 basically lets Rollbar get a look at all the requests and then it feeds it on to our app,
0:24 and then it rolls it back and so if there is kind of errors or anything like that,
0:28 Rollar will get to catch them before they flow back to the user.
0:36 if we want to use that injected in code, we also have the ones
0:40 that we got directly from Rollbar that they pull in themselves,
0:43 so rollbar.access_token, rollbar.environment,
0:46 be sure to set the environment correctly,
0:48 remember that really helps knowing whether you should freak out
0:51 if you see an error or "oh no, that's just test, don't worry about it",
0:54 we can say which branch back in GitHub we want to go from,
0:57 we also need to add this filter:rollbar
1:00 and set our environment and access token there as well.
1:04 it looks like in the slides I have dev in production, don't make those different, whatever,
1:08 those should make them the same.
1:11 OK, so you put that in here, make sure you set, you install Rollbar the package
1:16 and you set it as a requirement in your setup, and once you've done that,
1:19 then you can just config.include('rollbar.contrib.pyramid'),
1:25 in your main setup somehow and that is all you have to do,
1:30 all the errors that are uncaught will be reported to Rollbar, how lovely is that?
1:33 Now, there is one more step, because sometimes you actually handle errors
1:38 there is a crash and you don't want to let your app crash,
1:40 you never want to let your app crash, so ideally you handle these errors
1:44 and Rollbar will say "you didn't handle this one,
1:47 you should have a try / except or more error handling" or something,
1:50 but if you do handle it, it won't show up in Rollbar unless you take some special steps.
1:55 So if we are going to report handled errors,
1:58 we are going to need to import Rollbar initialize it with our access token
2:03 and the mode production dev, whatever, probably pull that out of a configuration file,
2:06 and then we are going to do a try / except block,
2:12 so we'll try something risky and if we just want to report a message
2:15 not a full on error, we can say "we got an IO Error for the risky operation
2:18 and this is just a warning, we handled it, it's cool".
2:21 If it's entirely uncaught, maybe we want to actually submit it as a full-on error
2:27 as if it were uncaught, so we can report exception info
2:30 and that will just create more or less what you saw when we didn't handle it at all.
2:34 But this way we can catch the error, still report it,
2:37 but not have our users see an entirely terrible crashed server right,
2:43 that definitely shakes people's confidence in your product.
2:46 Alright, that's Rollbar, super easy to integrate, they've got a free plan
2:52 and it is super valuable, I really appreciate it having it around,
2:55 so if you depend on your site being up for your business,
2:58 something like Rollbar is definitely recommended.