Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!
Python Zone is brought to you in partnership with:

Ken Cochrane is a software engineer with broad-based experience designing and implementing database-backed web applications, specializing in Python and Java. Ken is a DZone MVB and is not an employee of DZone and has posted 12 posts at DZone. You can read more from them at their website. View Full User Profile

Running Sentry on DotCloud

02.03.2012
Email
Views: 1264
  • submit to reddit
This content is part of the Python Zone, which is presented to you by DZone and New Relic. Visit the Python Zone for news, tips, and tutorials on the Python programming language.  New Relic provides the resources and best practices to help you monitor these applications.
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.

  1. Create a place to store your project
    $ mkdir -p ~/projects
  2. Go into the projects directory
    $ cd ~/projects
  3. Clone git repo from github, requires git client
    $ git clone git://github.com/kencochrane/sentry-on-dotcloud.git
  4. Go into the new project directory
    $ cd sentry-on-dotcloud
  5. Creating the virtualenv (using virtualenvwrapper, virtualenv, and pip)
    $ mkvirtualenv --no-site-packages --distribute sentry-on-dotcloud
  6. Install all of the Sentry requirements via pip and the requirements.txt file.
    $ pip install -r requirements.txt
  7. Installing the dotCloud client http://docs.dotcloud.com/firststeps/install/ (hereare the steps for Linux and Mac OSX)
    $ sudo pip install -U dotcloud
  8. Sign up for a dotcloud account https://www.dotcloud.com/accounts/register/ if you haven't already.
  9. 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
    $ dotcloud
  10. Create your dotcloud application
  11. Change the SENTRY_KEY settings in these files, to the same unique value.
    • sentry_config.py
    • sentryproj/settings.py

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=='

  1. Add your email address to SENTRY_ADMINS in sentryproj/settings.py . This will send you emails when an error occurs.
    SENTRY_ADMINS = ('youremail@example.com',)
  2. Push your code into dotcloud
    $ dotcloud push sentry .
  3. Find out your application url
    $ dotcloud url sentry
  4. Open url in your browser and start using sentry on dotcloud.
  5. First things first you should change the admin password from the default one that was created on deployment.
  6. Test out sentry using the raven client to make sure it is working as it should. Open up a python shell on your local machine and do the following.

Replace the server_url with your sentry url you found out in step 14. Make sure it ends in /store/ . Also make sure you replace my_key with your sentry key

>>> from raven import Client
>>> server_url = "http://sentry-username.dotcloud.com/store/"
>>> my_key='1234-CHANGEME-WITH-YOUR-OWN-KEY-567890'
>>> client = Client(servers=[server_url], key=my_key)
>>> client.create_from_text('My event just happened!')
('48ba88039e0f425399118f82173682dd', '3313fc5636650cccaee55dfc2f2ee7dd')

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.

  1. 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


Links:




Source: http://kencochrane.net/blog/2012/01/running-sentry-on-dotcloud/
Published at DZone with permission of Ken Cochrane, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Python is a fast, powerful, dynamic, and versatile programming language that is being used in a variety of application domains. It has flourished as a beginner-friendly language that is penetrating more and more industries. The Python Zone is a community that features a diverse collection of news, tutorials, advice, and opinions about Python and Django. The Python Zone is sponsored by New Relic, the all-in-one web application performance tool that lets you see performance from the end user experience, through servers, and down to the line of application code.