Running Sentry on DotCloud
Sentry is a realtime event logging and aggregation platform. At it’s core it specializes in monitoring errors and extracting all the information needed to do a proper post-mortum without any of the hassle of the standard user feedback loop.
The main feature of sentry and the ability to send all of your application logs to one place, and then aggregate them, so that you only get one error email for the same error. This will keep your mailbox from flooding, when something goes wrong.
Putting your logging server on a different server or network then your production servers is a good idea. If something goes wrong, and you can't access your servers, you can still see what errors were getting thrown before the servers started having problems.
Follow these easy steps to get sentry up and running on DotCloud.
Create a place to store your project:
$ mkdir -p ~/projects
Go into the projects directory:
$ cd ~/projects
Clone git repo from github, requires git client:
$ git clone git://github.com/kencochrane/sentry-on-dotcloud.git
Go into the new project directory:
$ cd sentry-on-dotcloud
Creating the virtualenv (using virtualenvwrapper, virtualenv, and pip):
$ mkvirtualenv --no-site-packages --distribute sentry-on-dotcloud
Install all of the Sentry requirements via pip and the requirements.txt file:
$ pip install -r requirements.txt
Installing the dotCloud client http://docs.dotcloud.com/firststeps/install/ (here are the steps for Linux and Mac OSX):
$ sudo pip install -U dotcloud
Sign up for a dotcloud account https://www.dotcloud.com/accounts/register/ if you haven't already.
The first time you use the dotCloud account you will need to add your api key. So type dotcloud and follow the steps. You can find your API key at http://www.dotcloud.com/account/settings:
Create your dotcloud application:
$ dotcloud create sentry
Change the SENTRY_KEY settings in these files, to the same unique value.
Here is an example on how to generate a good unique key that you can use in the files above:
>>> import base64 >>> import os >>> KEY_LENGTH = 40 >>> base64.b64encode(os.urandom(KEY_LENGTH)) '6+tSEh1qYwDuTaaQRcxUjMDkvlj4z9BU/caCFV5QKtvnH7ZF3i0knA=='
Add your email address to SENTRY_ADMINS in sentryproj/settings.py . This will send you emails when an error occurs:
SENTRY_ADMINS = ('email@example.com',)
Push your code into dotcloud:
$ dotcloud push sentry .
Find out your application url:
$ dotcloud url sentry
Open url in your browser and start using sentry on dotcloud.
First things first you should change the admin password from the default one that was created on deployment. look inside of
mkadmin.pyfor the username and password.
Test out sentry using the raven client to make sure it is working as it should.
You will get this value from the "Projects / default / Manage / Member: <username>" page. It will be under "Client DSN".
Open up a python shell on your local machine and do the following.
Replace the sentry_dsn with your sentry_dsn you found above:
>>> from raven import Client >>> sentry_dsn = dsn='https://public_key:firstname.lastname@example.org/project_id' >>> client = Client(dsn=sentry_dsn) >>> client.captureMessage('My event just happened!') ('48ba88039e0f425399118f82173682dd', '3313fc5636650cccaee55dfc2f2ee7dd')
Open up a terminal window and type the following command (replacing the 3rd parameter with the Sentry DSN you found above):
$ raven test https://public_key:email@example.com/project_id
If you go to the sentry webpage you should see your test message. If not, double check everything, and see if there was any errors during the send.
Once this is all up and running you can install the raven client in your applications, and start sending your logs to sentry.
Optional: If you don't like the URL they gave you, you can use your custom domain. Assuming your application was sentry.www and your domain was www.example.com you would do the following:
$ dotcloud alias add sentry.www www.example.com
Once you get comfortable with how things work, don't forget to change your DEBUG setting to False. Go ahead and fork my project and get started today.
- For more info about dotcloud, sentry, and Raven and what you can do with with it. Check out their docs
- DotCloud overview: http://docs.dotcloud.com/firststeps/platform-overview/
- Sentry Documentation: http://sentry.readthedocs.org/en/latest/index.html
- Raven Documentation: http://raven.readthedocs.org/en/latest/index.html
- Blog Post for this project: http://kencochrane.net/blog/2012/01/running-sentry-on-dotcloud/
- Virtualenv : http://pypi.python.org/pypi/virtualenv
- pip : http://www.pip-installer.org/
- virtualenvwrapper : http://www.doughellmann.com/projects/virtualenvwrapper/
- git : http://git-scm.com/