Help


Documentation & Tutorials

Configure an Sentry server to track errors

Configuring a Sentry Server on a Scaleway Instance

This tutorial details how to setup a Sentry server on a Scaleway instance to start error tracking in your applications.

Requirements

  • You have an account and are logged into cloud.scaleway.com
  • You have configured your SSH Key

Sentry Overview

Sentry is an open source solution for error tracking in applications. It is written in Python and can provide real-time reporting of errors in applications based on a client/server architecture. You can easily integrate it into your applications via its SDK and let them automatically report the errors via common messaging tools like Slack, IRC and more. This helps to reduce the time for development of your applications and increases the user experience. You can find all reports on a dashboard which makes it easy to triage the problem - how often it occurs, which impact it has on the user experience of your application, which part of your code causes the problem and so on.

Installing Sentry

In this tutorial, we will install sentry on a Ubuntu Xenial based instance.

1 . Update the system and install the required packages:

    sudo apt-get update && apt-get upgrade -y
    sudo apt-get install -y redis-server redis-tools python-setuptools python-pip python-dev libxslt1-dev libxml2-dev libz-dev libffi-dev libssl-dev libpq-dev libyaml-dev postgresql nginx-full supervisor

2 . Install virtualenv via pip:

    sudo pip install -U virtualenv

3 . Select a location for the environment and configure it with virtualenv. As exemplified, the location used is /www/sentry:

    virtualenv /www/sentry/

4 . Activate the virtualenv now:

    source /www/sentry/bin/activate

Note: Activating the environment will adjust the PATH and pip will install into the virtualenv by default.

5 . Now that the environment is setup, install sentry on the machine. Again pip is used:

    pip install -U sentry

Sentry relies on a lot of dependencies, and pip will download all the required packages. The installation can take up to a few minutes.

Creating a Database

We need to have a database ready to use before we launch the software. Sentry uses PostgreSQL to store all information, and we can create the database as follows:

1 . Enable citext extension as it is required for the installation (the database creation will fail is this step is skipped):

    sudo su - postgres
    $ psql -d template1 -U postgres
    psql (9.5.12)
    Type "help" for help.

    template1=# create extension citext;
    CREATE EXTENSION
    template1=# \q

2 . Create the sentry database in a second step:

    $ createdb sentrydb
    $ createuser sentry --pwprompt
    $ psql -d template1 -U postgres
    psql (9.5.12)
    Type "help" for help.

    template1=# GRANT ALL PRIVILEGES ON DATABASE sentrydb to sentry;
    GRANT
    template1=# ALTER USER sentry WITH SUPERUSER;
    ALTER ROLE
    template1=# \q
    exit

Configuring Sentry

1 . Initialize Sentry:

    sentry init /etc/sentry

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

Note: You can also specify any other directory for your configuration files by replacing the part /etc/sentry. If you run sentry init without specifying the path, the files will be stored in the directory ~/.sentry.

2 . Edit the file /etc/sentry/sentry.conf.py and add the database credentials: It should look like the following example:

    DATABASES = {
      'default': {
        'ENGINE': 'sentry.db.postgres',
        'NAME': 'sentrydb',
        'USER': 'sentry',
        'PASSWORD': 'ASecurePassword',
        'HOST': 'localhost',
        'PORT': '5432',
        'AUTOCOMMIT': True,
        'ATOMIC_REQUESTS': False,
      }
    }

3 . In order to receive mails from our Sentry instance, configure the e-mail in the file /etc/sentry/sentry.conf.py:

    mail.from: 'sentry@localhost'
    mail.host: 'localhost'
    mail.port: 25
    mail.username: ''
    mail.password: ''
    mail.use-tls: false

Note: The SMTP ports are blocked by default for security reasons. You can open a support request to get them unlocked. Click here for more information.

4 . Initialize the database by running the upgrade function of Sentry:

    SENTRY_CONF=/etc/sentry sentry upgrade

Configuring a reverse proxy

By default, Sentry listens on port 9000. Therefore we will configure a small nginx proxy that listens on port 80 and forwards all requests on the standard HTTP port to port 9000.

1 . Edit the file /etc/nginx/sites-enabled/default and put the following content in it:

    server {
      listen 80 default_server;
      server_name sentry.local;

      location / {
        proxy_pass         http://localhost:9000;
        proxy_redirect     off;

        proxy_set_header   Host              $host;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
      }

    }

2 . Save the file and restart your Sentry server:

    service nginx restart

Running Sentry as a service

Our Sentry server is ready now, but the services have to be started manually at each time when we reboot your instance.

1 . Configure Sentry server as a service with supervisord standard put the following configuration in the file /etc/supervisor/conf.d/sentry.conf:

    [program:sentry-web]
    directory=/www/sentry/
    environment=SENTRY_CONF="/etc/sentry"
    command=/www/sentry/bin/sentry start
    autostart=true
    autorestart=true
    redirect_stderr=true
    stdout_logfile=syslog
    stderr_logfile=syslog

    [program:sentry-worker]
    directory=/www/sentry/
    environment=SENTRY_CONF="/etc/sentry"
    command=/www/sentry/bin/sentry run worker
    autostart=true
    autorestart=true
    redirect_stderr=true
    stdout_logfile=syslog
    stderr_logfile=syslog

    [program:sentry-cron]
    directory=/www/sentry/
    environment=SENTRY_CONF="/etc/sentry"
    command=/www/sentry/bin/sentry run cron
    autostart=true
    autorestart=true
    redirect_stderr=true
    stdout_logfile=syslog
    stderr_logfile=syslog

2 . Save the file and reload supervisor:

    sudo supervisorctl reread
    sudo supervisorctl update
    sudo supervisorctl start all

Your Sentry server is running now, and you can integrate it with your applications. You can also add additional features by adding different Plugins into Sentry.

Connecting to the Sentry interface

1 . Once the installation is finished, connect from a browser: http://your.sentry.server.ip/

2 . Login with the user that you have created at the upgrade function during the installation.

You will be requested to finish the installation by providing some additional parameters and, once you have done, the Sentry Dashboard displays:

Sentry Dashboard

To create a new project click on the button in the top right corner and choose your environment. Sentry will show you instructions how to implement it in your project.

Sentry is a mighty tool that can be used to automatize your workflow and increase the user experience by reducing the time to market of your applications. There are many SDK’s for various programming languages available and you can check the documentation for your favourite language.

Discover a New Cloud Experience

Deploy SSD Cloud Servers in seconds.