Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

Setup Sentry via Python on Ubuntu 16.04

Last Updated: Fri, Jun 7, 2019
Linux Guides Programming Python Server Apps
Archived content

This article is outdated and may not work correctly for current operating systems or software.

Introduction

Sentry is an open source solution for error tracking. Sentry tracks exceptions and other useful messages from applications that would traditionally be written to log files, and instead utilizes a user-friendly interface.

Prerequisites

Some basic prerequisites which you’ll need in order to run Sentry:

Installation

First update your system:

sudo apt-get update

Create the sentry user that will be running the software:

sudo adduser sentry

sudo adduser sentry sudo

Install python and build-essential packages:

sudo apt-get install -y python build-essential

Create the file /etc/apt/sources.list.d/pgdg.list:

sudo touch /etc/apt/sources.list.d/pgdg.list

Import the signing key and update package lists:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

sudo apt-get update

Install PostgreSQL:

sudo apt-get install postgresql-9.5

Download the Latest Redis 4.x source:

wget http://download.redis.io/releases/redis-4.0.1.tar.gz

Unzip the Redis source into its own folder, so we can cd in and build it in the next step:

tar -xvf redis-4.0.1.tar.gz

Build it from source:

cd redis-4.0.1

make

Run Redis in background:

src/redis-server --daemonize yes

Install pip and related libraries:

cd ~

sudo apt-get install python-setuptools python-dev libxslt1-dev gcc libffi-dev libjpeg-dev libxml2-dev libxslt-dev libyaml-dev libpq-dev python-pip

Install Python virtual environment:

sudo pip install -U virtualenv

Install postgresql-contrib:

sudo apt-get install postgresql-contrib-9.5

Login as the postgres user and enable the citext extension:

sudo su - postgres

$ psql -d template1 -U postgres

psql (9.5.12)

Type "help" for help.

template1=# create extension citext;

CREATE EXTENSION

template1=# \q

Create the sentry database:

$ createdb sentry_db

$ createuser sentry --pwprompt

$ psql -d template1 -U postgres



template1=# GRANT ALL PRIVILEGES ON DATABASE sentry_db to sentry;

GRANT

template1=# ALTER USER sentry WITH SUPERUSER;

ALTER ROLE

template1=# \q

exit

Login as the sentry user and create a virtual environment for Sentry:

sudo su - sentry

virtualenv ~/sentry_app/

source ~/sentry_app/bin/activate

Install Sentry on the machine:

pip install -U sentry

Initialize Sentry:

sentry init

This command will create the configuration files in the directory ~/.sentry/.

Open the configuration file ~/.sentry/sentry.conf.py:

nano ~/.sentry/sentry.conf.py

Then add the database credentials. It should look like the following example:

DATABASES = {

    'default': {

        'ENGINE': 'sentry.db.postgres',

        'NAME': 'sentry_db',

        'USER': 'sentry',

        'PASSWORD': 'securedpassword',

        'HOST': 'localhost',

        'PORT': '5432',

        'AUTOCOMMIT': True,

        'ATOMIC_REQUESTS': False,

    }

}

Initialize the database:

sentry upgrade

Running Sentry as a service

Log out of the sentry user:

exit

Install Supervisor:

sudo apt-get install -y supervisor

Configure the Sentry server to startup whenever the server boots using supervisord. Put the following configuration in the file /etc/supervisor/conf.d/sentry.conf:

[program:sentry-web]

directory=/home/sentry/sentry_app/

environment=SENTRY_CONF="/home/sentry/.sentry"

command=/home/sentry/sentry_app/bin/sentry run web

autostart=true

autorestart=true

redirect_stderr=true

user=sentry

stdout_logfile=syslog

stderr_logfile=syslog



[program:sentry-worker]

directory=/home/sentry/sentry_app/

environment=SENTRY_CONF="/home/sentry/.sentry"

command=/home/sentry/sentry_app/bin/sentry run worker

autostart=true

autorestart=true

redirect_stderr=true

user=sentry

stdout_logfile=syslog

stderr_logfile=syslog



[program:sentry-cron]

directory=/home/sentry/sentry_app/

environment=SENTRY_CONF="/home/sentry/.sentry"

command=/home/sentry/sentry_app/bin/sentry run cron

autostart=true

autorestart=true

redirect_stderr=true

stdout_logfile=syslog

stderr_logfile=syslog

Save the file and reload Supervisor:

sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start all

Sentry is now configured and listens on port 9000. Navigate to http://you_server_ip:9000 in your favorite browser to finish setting up Sentry.

Want to contribute?

You could earn up to $600 by adding new articles.