GlitchTip on Clever Cloud, a Sentry alternative

glitchtip
We recently discovered glichtip, which is an open source error tracking tool. Glichtip is a great alternative to Sentry. Learn how to deploy it on Clever Cloud.

At Clever Cloud, we like to have some context about our application status and logs. That’s why we have a lot of tools deployed to gain some observability. A lot of them are freely available for our customers (a log view, a metrics view or Grafana). Still, there are some tools that we use internally that could be helpful to many. We discovered recently glichtip, which is an open source error tracking. Glichtip is a great alternative to Sentry and less complex to deploy. We will add that Glichtip is compatible with the Sentry’s open source SDK.

Context

We used Sentry to analyse the errors coming from our own application logs. We were still using the 9.1 version until we had too many trouble to keep it running. We then had to upgrade or find a new solution. All Sentry version post 9.1 require many more components to deploy (as Kafka, Snuba or Clickhouse). This is still possible to deploy it with a self hosted script. We wanted every component to be standalone outside of the main Sentry application, it meant that we had to provide authentication to all components. It was not a big issue, but it took us more time that what we first expected. And at the same time, we discovered a new project: Glitchtip.

Glitchtip

All started by a French tweet, about the discovery of a new tool: Glitchtip. This tweet said that Glitchtip is compatible to Sentry, free and easy to self host it, so it was evident that we were going to give it a try.

What does Glitchtip provide? Inside your application, with the Sentry SDK, you will transfer some of your error logs. Then the tool help you to track those errors, to better understand when a new version tool creates new errors, organize or search them… In a quick word, it’s a very useful tool to debug your deployed software.

Clever Cloud deploy

Setup

First, we will download Glitchtip Docker project and customize it a bit to match how docker applications are run in Clever Cloud.

# Get latest Glitchtip release
git clone https://gitlab.com/glitchtip/glitchtip.git

# Go to the folder
cd glitchtip

Then open your favorite code IDE and open the Dockerfile:

# Remove
FROM glitchtip/glitchtip:latest

# And add instead:
FROM glitchtip/glitchtip:v1.12.2

COPY docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

Here we will set-up the last Glitchtip release. When we were writing this blog it was the v1.12.2. You can find them here. We set up a new script to use docker-entrypoint.sh which will enable us to start or the Glitchtip web application or the Glitchtip worker. The docker-entrypoint.sh should contain the following script:

# docker-entrypoint.sh script:
#!/bin/bash

if [ "${START_TARGET}" = "worker" ]; then
  mkdir /tmp/sandboxed
	cd /tmp/sandboxed && nohup python -m http.server 8080 &
	/code/bin/run-celery-with-beat.sh
else
  /code/bin/start.sh
fi

# Don't forget to make it executable:
chmod u+x docker-entrypoint.sh

Deploy

Glitchtip comes with a Dockerfile, which means we will use a a docker runtime. It also requires a PostgreSQL Database and a Redis cache, which means we will deploy a PostgreSQL addon and a Redis addon. Adding a -o option in all create command line can be used to specify which organisation to use.

# Create the docker applications:
clever create --type docker glitchtip-web
clever create --type docker glitchtip-worker

# Create the PG addon
clever addon create postgresql-addon --plan s_sml --addon-version 14 glitchtip-postgres

# Link the addon
clever service link-addon glitchtip-postgres -a glitchtip-web
clever service link-addon glitchtip-postgres -a glitchtip-worker

# Create the Redis addon
clever addon create redis-addon --plan s_mono glitchtip-redis

# Link the addon
clever service link-addon glitchtip-redis -a glitchtip-web
clever service link-addon glitchtip-redis -a glitchtip-worker

Config

For now we will configure Glitchtip through environment variables. As we use several applications, let’s deploy an addon configuration provider.

# Create a config addon:
clever addon create config-provider --plan std glitchtip-config

# Link the addon
clever service link-addon glitchtip-config -a glitchtip-web
clever service link-addon glitchtip-config -a glitchtip-worker

Now that we have deployed a config addon provider let’s update its configuration. To do it go to the Clever Cloud console and then select the glitchtip-config. In the variable panel, select the expert mode and add the following required variable, (fill their value based on the provided commentary):

# In the config addon provider add:
CC_DOCKER_EXPOSED_HTTP_PORT="8080"
# Copy paste here the POSTGRESQL_ADDON_URI environment variable of the glitchtip-postgres addon 
DATABASE_URL="postgresql://user:password@host:port/database"
# Provide a valid email server
EMAIL_URL="smtp://email:password@smtp_url:port"
# Copy paste here the application domain name of the glitchtip-web application instead (should look like: https://app-da7a7a7a-da7a-4242-7a7a-da7a42427a7a.cleverapps.io)
GLITCHTIP_DOMAIN="MY_APP_DOMAIN_NAME"
# Copy paste here the REDIS_ADDON's environment variable of the glitchtip-redis addon 
REDIS_HOST= < REDIS_HOST >
REDIS_PASSWORD= < REDIS_PASSWORD > 
REDIS_PORT= < REDIS_PORT >
# Generate your own custom secret key for Glitchtip
SECRET_KEY= < choose a secret key >

Note that you can find more information about how to configure Glitchtip in its documentation.

Each docker application requires some custom configuration too:

#glitchtip-web custom env
clever env set CC_RUN_SUCCEEDED_HOOK "./manage.py migrate" -a glitchtip-web
clever env set START_TARGET "web" -a glitchtip-web
#glitchtip-worker custom env
clever env set START_TARGET "worker" -a glitchtip-worker

Deploy and run

Now that everything is set, it’s time to deploy and run your Glitchtip application.

# Remove initial git
rm -r .git 

# Init a git repository
git init

# Add your files
git add .

# Commit the changes
git commit -m "clever init and deploy"

# Deploy the application
clever deploy -a glitchtip-web
clever deploy -a glitchtip-worker

# Open Glitchtip in your browser
clever open -a glitchtip-web

Your glitchtip is now almost ready to use. One last action is required: you need to create a super user to administrate Glitchtip.

# Connect in SSH to your Clever application:
clever ssh -a glitchtip-web

# Run 
./manage.py createsuperuser

Great job! You should now have an access to glitchtip admin page (available on your application /admin path). You can then create users or connect to your favorite social application to authenticate your users. You will find more information on the documentation. You can set your own keycloak on Clever Cloud and use it to connect to Glitchtip!

Connect Glitchtip to an application

We will reuse the akka application example we used for our scala exemple blogpost. And we will then see how we can forward our own error logs to Glitchtip.

Create a Glitchtip project

The first step will be to login with new root user (or any Glitchtip user you created or linked with a social application). Glitchtip will ask you to create your organisation. In our case let’s set clever-cloud. As we want to monitore our application error’s logs, we will need to create a new project directly in Glitchtip UI. Let’s call it “myakka” and create it’s associated “Scala-dev” team.

Once this project is create you will be able to get a DSN. We will load it later as environment variable for the akka application.

Create a Glitchtip Token

Go to Profile/auth token and craft a new glitchtip token with at least the following project rights: read, write and releases. Save it for later.

Setup the AKKA example application on Clever Cloud

The first step will be to deploy AKKA example application on Clever Cloud as mentionned in the scala exemple blogpost. Clone the project and instead of the main branch, use the blogpost-sentry one.

# Clone Clever Cloud akka example project:
git clone https://github.com/CleverCloud/scala-akka-http-postgres-example.git

# Checkout blogpost-sentry
git checkout blogpost-sentry

In this branch, we update a bit the application to connect it to Sentry. Then we send only the starting server HTTP logs with a custom status tag (success or failure). This is code we use in the blogpost-sentry branch:

# Register Sentry
Sentry.init(sentryConfig.sentryDsn)

# Send a message to Sentry with a tag
Sentry.getContext().addTag("status", status)
Sentry.capture(message)
Sentry.getContext().clear()

In addition, you have to add a .sentryclirc file. This file should contain:

[defaults]
url=GLITCHTIP_APP_DOMAIN_NAME
org=clever-cloud
project=myakka

Configure Glitchtip environment variables

Use the post_build.sh script as CC_POST_BUILD_HOOK. This will run the mandatory sbt flywayMigrate as well as create a new release on Sentry (based on the commit ID).

# Set CC_POST_BUILD_HOOK
clever env -a myakka set CC_POST_BUILD_HOOK "./post_build.sh"

You also need to set Glitchtip token and Glitchtip dsn as environnement variables:

# Set Glitchip required env variables
clever env -a myakka set SENTRY_AUTH_TOKEN < custom_glitchtip_token >  
clever env -a myakka set SENTRY_DSN < custom_glitchtip_dsn >  

Deploy the application

You can now deploy myakka project:

# Deploy myakka
clever deploy

Try it

As soon as this done, you should see your first issue on Glitchip! That’s all, you can now add all the application you want to Glitchtip and enjoy this tool to centralise your application logs and errors. If you’re used to this product or just try it feel free to share with us any feedback on Twitter.

Blog

À lire également

SuperBOL: The COBOL revolution in the Cloud

COBOL, a programming language that is over 60 years old, continues to power a large proportion of the IT systems of the world's major companies, particularly in the financial and insurance sectors.
Features

Clever Cloud welcomes the first startups to the UP Programme

Clever Cloud is proud to announce the arrival of the first five startups selected to join its UP Programme, an initiative dedicated to supporting young technology companies in their growth phase.
Company

A minor update resulted in a cascade of errors: how it went wrong, what we’ve learnt

On Friday, August 2nd, 2024 Clever Cloud’s platform became very unstable, leading to downtime of varying duration and scope, for customers using services on the EU-FR-1 (PAR) region, and remote zones depending on the EU-FR-1 control plane (OVHcloud, Scaleway, and Oracle). Privates and on-premise zones weren’t impacted.
Company Engineering