Skip to content

Commit b50c542

Browse files
committed
working on monitoring post
1 parent 58c317d commit b50c542

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

content/posts/170717-monitor-flask-apps.markdown

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ the post:
3333
* [pyrollbar](https://rollbar.com/docs/notifier/pyrollbar/) monitoring
3434
instrumentation library,
3535
[version 0.13.12](https://github.com/rollbar/pyrollbar/tree/v0.13.12)
36-
* [pip](https://pip.pypa.io/en/stable/) and
37-
[virtualenv](https://virtualenv.pypa.io/en/latest/), which come
38-
packaged with Python 3, to install and isolate the Flask and Rollbar
39-
libraries from other Python projects you are working on
36+
* [pip](https://pip.pypa.io/en/stable/) and the
37+
[virtualenv](https://virtualenv.pypa.io/en/latest/) virtual environment
38+
library, which come packaged with Python 3, to install and isolate the
39+
Flask and Rollbar libraries from other Python projects you are working on
4040

4141
If you need help getting your
4242
[development environment](/development-environments.html) configured
@@ -50,11 +50,37 @@ Use and abuse the source code as you desire for your own applications.
5050

5151

5252
## Installing Dependencies
53+
Change into the directory where you keep your Python virtualenvs.
54+
Create a new virtual environment for this project using the following
55+
command.
56+
57+
```bash
58+
python3 -m venv monitorflask
59+
```
60+
61+
Activate the virtualenv.
62+
63+
```bash
64+
source monitorflask/bin/activate
65+
```
66+
67+
The command prompt will change after activating the virtualenv:
68+
69+
<img src="/img/170723-monitor-flask-apps/activate-virtualenv.png" width="100%" class="technical-diagram img-rounded" style="border:1px solid #ccc" alt="Activating our Python virtual environment on the command line.">
70+
71+
Remember that you need to activate the virtualenv in every new terminal
72+
window where you want to use the virtualenv to run the project.
73+
74+
Flask and Rollbar can now be installed into the now-activated virtualenv.
5375

5476
```
5577
pip install flask==0.12.2 rollbar==0.13.12
5678
```
5779

80+
Our required dependencies should be installed within our virtualenv
81+
after a short installation period. Look for output like the following to
82+
confirm everything worked.
83+
5884
```
5985
Installing collected packages: MarkupSafe, Jinja2, itsdangerous, click, Werkzeug, flask, idna, urllib3, chardet, certifi, requests, six, rollbar
6086
Running setup.py install for MarkupSafe ... done
@@ -63,12 +89,30 @@ Installing collected packages: MarkupSafe, Jinja2, itsdangerous, click, Werkzeug
6389
Successfully installed Jinja2-2.9.6 MarkupSafe-1.0 Werkzeug-0.12.2 certifi-2017.4.17 chardet-3.0.4 click-6.7 flask-0.12.2 idna-2.5 itsdangerous-0.24 requests-2.18.1 rollbar-0.13.12 six-1.10.0 urllib3-1.21.1
6490
```
6591

92+
Now that we have our Python dependencies installed into our virtualenv
93+
we can create the initial version of our application.
94+
6695

6796
## Building Our Flask App
97+
Create a folder for your project named `monitor-flask-apps`. Change into
98+
the folder and then create a file named `app.py` with the following
99+
code.
100+
101+
```python
102+
103+
```
104+
105+
106+
Test it out.
68107

108+
We can see the error because we are testing our application locally,
109+
but what happens when our application is deployed and a user gets the
110+
error? They will typically quit out of frustration and you will never
111+
know what happened unless you add some error tracking and application
112+
monitoring.
69113

70-
Create a new directory
71-
(error occurs but we dont see it)
114+
We'll now modify our code to add Rollbar to catch and report those
115+
errors that occur for our users.
72116

73117

74118
## Handling Errors
32.1 KB
Loading

0 commit comments

Comments
 (0)