Wednesday 18 July 2012

Deploying Sentry on Heroku

For a recent personal project, I've been using Sentry to monitor errors and suchlike. I was hosting this on my VPS, but the app it is monitoring is hosted on Heroku, so I thought that (a) it would make more sense to have the monitoring In The Cloud (TM), and (b) it would be an interesting exercise with Heroku, which I have been enjoying using a great deal.

It turns out to be pretty simple, and I've made a git repo available to make it even easier.  Just follow these steps:
  1. Clone my GitHub repository:
    git clone https://github.com/OddBloke/heroku-sentry.git
  2. Generate a secret key and set it as SENTRY_KEY in sentry.conf.py. See point 11 here for a good example of how to generate a good key.
  3. Install the Heroku Toolbelt.
  4. Sign up for a Heroku account.
  5. Log in to your Heroku account from the CLI:
    heroku login
  6. Navigate to your clone of the git repo and create a new Heroku app:
    heroku apps:create
    This command creates a heroku remote in the git repo, which we will use in a minute.
  7. Take the URL it spits out (which will be something like http://floating-earth-1234.herokuapp.com/) and set that as SENTRY_URL_PREFIX in sentry.conf.py.
  8. Commit your changes:
    git commit --all -m "Personalise."
  9. Push your repository up to Heroku:
    git push heroku master
    If all goes according to plan, this will cause Heroku to deploy, and you will see the output as it installs Sentry and all of its requirements. Finally, it will tell you that your app is deployed to Heroku, but we're not quite done.
  10. We need to configure a database for Sentry to use. We're going to use the new Heroku Postgres offering, which is currently in public beta: 
    heroku addons:add heroku-postgresql:dev
  11. The previous command will have given you a database name, something like HEROKU_POSTGRESQL_CHARCOAL. Tell Heroku to use this database: heroku pg:promote HEROKU_POSTGRESQL_CHARCOAL
  12. Finally, we need to run the Sentry setup script, create a default user and tell Sentry to use it: 
    heroku run sentry --config=sentry.conf.py upgrade
    heroku run sentry --config=sentry.conf.py createsuperuser
    heroku run sentry --config=sentry.conf.py repair --owner=JustCreatedSuperuser
    You should use the name of the super-user you create with the second command as the --owner argument to the third command.
Voila!  You should now be able to see Sentry by pointing your browser at the URL you used for SENTRY_URL_PREFIX earlier.

If you have any problems, you can check out your logs using heroku logs.

One final note: Heroku doesn't provide SMTP for you, so you'll also have to modify the SMTP settings to point at your own mail server (or play around with the Heroku add-ons that do provide it).

14 comments:

  1. What happens when you run out of space in your db? Something that may happen when using Heroku's free tiers. How does Sentry handle that?

    ReplyDelete
    Replies
    1. I'm not sure how Sentry would handle that but, as I understand it, you should be able to seamlessly upgrade to higher database tiers, shown at https://addons.heroku.com/heroku-postgresql. You can also point Heroku at any database by modifying DATABASE_URL, so you could host the database yourself.

      Delete
    2. What happens when you run out of space in your db? Something that may happen when using Heroku's free tiers. How does Sentry handle that?سیاوش قمیشی

      شادمهر عقیلی

      Delete
  2. It took me a while to get the email settings for my Gmail/Apps server to work:

    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_HOST_PASSWORD = ''
    EMAIL_HOST_USER = 'noreply@schinckel.net'
    EMAIL_PORT = 587
    EMAIL_USE_TLS = True

    ReplyDelete
    Replies
    1. Am I right in thinking that a GMail account for that email address has to exist? Possibly that isn't an issue for Apps domains...

      Delete
    2. Thanks! I've been looking for this config tip for a while..

      Delete
  3. What about celery? Is there any way to run sentry without?

    Cheers,

    Laur

    ReplyDelete
  4. I just tried following the described process, but I only got as far as step 12. The first sentry config command returns an error on me.

    This is what I got, but I'm not sure where I would go about addressing the Celery error below.

    I'm new to both Heroku and Sentry so any help would be much appreciated.

    $ heroku run sentry --config=sentry.conf.py upgrade
    Running `sentry --config=sentry.conf.py upgrade` attached to terminal... up, run.1452
    Traceback (most recent call last):
    File "/app/.heroku/python/bin/sentry", line 5, in
    from pkg_resources import load_entry_point
    File "/app/.heroku/python/lib/python2.7/site-packages/distribute-0.6.36-py2.7.egg/pkg_resources.py", line 2809, in
    parse_requirements(__requires__), Environment()
    File "/app/.heroku/python/lib/python2.7/site-packages/distribute-0.6.36-py2.7.egg/pkg_resources.py", line 594, in resolve
    raise DistributionNotFound(req)
    pkg_resources.DistributionNotFound: celery>=3.0.15,<3.1.0

    ReplyDelete
    Replies
    1. Never mind me, got around that issue by updating the requirements.txt changing the line:
      celery<3.0
      to:
      celery==3.0.19
      (that's the current release I got from `pip install celery` without specifying a version)

      Then I reran git commit (step 8) and git push (step 9) and continued back at step 12. And I now have sentry running.

      (This at the very least got around the issue above, but I haven't got as far as setting up logging on an actual project yet, so I'm not sure if I'll have issues down the track that because of this)

      I'll see how it goes, knock would.

      Delete
  5. Just remove the celery requirement altogether. Latest sentry deals with it as a requirement anyway.

    ReplyDelete
  6. I love you man! :D Works like a charm. Only thing I changed was removed the celery line in your requirements file. Thanks again buddy, much appreciated!

    ReplyDelete
  7. If you want to know how track a phone, you better visit this site for some info

    ReplyDelete
  8. Slots Empire could be very aptly named for it has a whole empire of slots for actual cash for you to can} enjoy. They cater to every kind of gamers with their vast number of well-known actual cash on-line slots created by RealTime Gaming. Slots Empire is a fantastically designed on-line on line casino and a breeze to make use of with its distinctive graphics and animations. But it’s not all looks and nothing else, as you’ll find some of the valuable bonuses and over 200 https://xn--2o2b21qv5bour7xc.com/ actual cash slots — all completely powered by RTG. Slots.lv’s number of 3D on-line slots for actual cash additionally be|can be} unimaginable with many vivid top-class slots that provide a real video game-like experience. They are constantly updating their sport offering to ensure you|to make certain you} by no means run out of interesting video games.

    ReplyDelete