When you want to track your exception and log messages in a UI rather than storing it in a file(which we usually do), we can use  SENTRY.  Sentry provides real-time crash reporting and exception tracking for your web and mobile apps.

In this Tutorial we will look on how to set up Sentry on a ubuntu VPS.

Update package list and upgrade packages:

sudo apt-get update && sudo apt-get upgrade

Required Packages:

apt-get install python-dev python-pip libpq-dev python-virtualenv libxml2-dev libxslt1-dev  postgresql-9.3 libffi-dev libssh-dev nginx supervisor

Installation:

cd <installation source directory>

virtualenv env

source env/bin/activate

pip install sentry

Post Installation Steps:

Create sentry config files

sentry init <installation source directory>

Change Postgresql settings

sudo su postgres

psql

ALTER USER postgres PASSWORD 'mynewpassword';

\q                      # to exit

createdb -E utf-8 sentry (as user postgres)

Based on whether you want to use it as postgres user or any other user change one of the below setting to md5

local   all             postgres     peer
local   all             all          peer

Redis

Newer versions of sentry need Redis >  2.8.9, visit  this link for more details on the ppas added below.

add-apt-repository ppa:chris-lea/redis-server
apt-get install redis-server

Modify <installation source directory>/sentry.conf.py 

SENTRY_WEB_OPTIONS = {
    'workers': 5,  # the number of web workers
    'protocol': 'uwsgi',  # Enable uwsgi protocol instead of http
}

Note: accordingly change postgresql, smtp and redis settings in config file.

Migrate Database

SENTRY_CONF=<installation source directory> sentry upgrade

You will be asked to create a superuser in between migration, which will be used to login into Sentry. In case if that doesnt happen use

SENTRY_CONF=<installation source directory> sentry createuser
 

Nginx Configuration Changes: 

Add following lines to /etc/nginx/sites-enabled/sentry

server {
listen 80 <your ip address/domain>;
location / {
    include     uwsgi_params;
    uwsgi_pass  127.0.0.1:9000;
  }
}

sudo service nginx restart

Supervisor:

If we visit the domain or IP set you will receive a 502 Page, because the sentry application is not yet up and running, Lets Daemonize sentry through a supervisor.

Add Below Lines to /etc/supervisor/conf.d/sentry.conf

[program:sentry-web]
command=/bin/bash -c "SENTRY_CONF=<installation source directory> <installation source directory>/env/bin/sentry run web"
# format of command should be SENTRY_CONF=/home /home/env/bin/sentry run web
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/supervisor/sentry-out.log
stderr_logfile=/var/log/supervisor/sentry-err.log

[program:sentry-worker]
command= /bin/bash -c "SENTRY_CONF=<installation source directory> <installation source directory>/env/bin/sentry celery worker"
# format of command should be SENTRY_CONF=/home /home/env/bin/sentry celery worker
environment=C_FORCE_ROOT="true"
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/supervisor/sentry-celery-out.log
stderr_logfile=/var/log/supervisor/sentry-celery-err.log

[program:sentry-beat]
command= /bin/bash -c "SENTRY_CONF=/home /home/env/bin/sentry celery beat"
environment=C_FORCE_ROOT="true"
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/supervisor/sentry-beat-out.log
stderr_logfile=/var/log/supervisor/sentry-beat-err.log


then execute these commands in shell to update the configurational changes.
supervisorctl reread
supervisorctl update

 

Now visit your domain and Login with Credentials you created during database migration

set domain as http://<yourdomain> (without trailing slash) and SMTP Details if any and start exploring sentry.

Visit this tutorial to learn how to create a project, team and track a Django Application. 

 

 

Subscribe To our news letter

Subscribe to our news letter to receive latest blog posts into your inbox. Please fill your email address in the below form.
*We don't provide your email contact details to any third parties
Latest Comments
Related Articles
Postgresql Installation and management basics. Jagadeesh V

PostgreSQL or simply postgres is the most advanced, SQL-compliant and open-source objective-RDBMS. In This Article, you will learn how to Install, Connect and Manage a ...

Continue Reading...
Clustering of Docker Containers using Docker Swarm Jagadeesh V

There are many available ways of Docker clustering. Kubernetes, Docker cloud, Docker Swarm etc., In this Tutorial we will learn setting up a cluster using ...

Continue Reading...
Understanding Logstash Parsing Configurations and options Jagadeesh V

In This Tutorial we will learn to customize Logstash to parse any type of Log Files. Logstash helps us to process logs and other event ...

Continue Reading...