Sentry 9 - haiquang9994/dev_env GitHub Wiki

This guide follow https://lcx.wien/blog/self-hosted-sentry-9/

Clone Sentry

cd /usr/src
git clone --depth 1 --branch 9.1.2 https://github.com/getsentry/self-hosted.git

Telegram Plugin

vim requirements.txt
# Add plugins here
sentry-telegram

Create script.sh

vim script.sh
Change config of top
#!/usr/bin/env bash

#Fix starting screen setup issue https://github.com/getsentry/sentry/issues/12722
echo "Set config.yml"

cat <<EOT > config.yml
auth.allow-registration: false
beacon.anonymous: true
mail.backend: 'smtp'
mail.from: "[email protected]"
mail.host: "smtp.example.com"
mail.password: "somesecurepassword"
mail.port: 465
mail.use-tls: true
mail.username: "[email protected]"
system.admin-email: "[email protected]"
system.url-prefix: "https://devnull.example.com/"
EOT
echo "Build Sentry onpremise"
make build

docker container stop sentry-cron sentry-worker sentry-web sentry-postgres sentry-redis
docker container rm sentry-cron sentry-worker sentry-web sentry-postgres sentry-redis

docker run \
  --detach \
  --name sentry-redis \
  redis:3.2-alpine

docker run \
  --detach \
  --name sentry-postgres \
  --env POSTGRES_PASSWORD='sentry' \
  --env POSTGRES_USER=sentry \
  -v /opt/docker/sentry/postgres:/var/lib/postgresql/data \
  postgres:11

echo "Generate secret key"
docker run --rm sentry-onpremise config generate-secret-key > key
SENTRY_SECRET_KEY=$(cat key)

echo "Run migrations"
docker run \
  --rm \
  -it \
  --link sentry-redis:redis \
  --link sentry-postgres:postgres \
  --env SENTRY_SECRET_KEY=${SENTRY_SECRET_KEY} \
  -v /opt/docker/sentry/sentry:/var/lib/sentry/files \
  sentry-onpremise \
  upgrade

echo "install plugins"
docker run \
  --rm \
  -it \
  --link sentry-redis:redis \
  --link sentry-postgres:postgres \
  --env SENTRY_SECRET_KEY=${SENTRY_SECRET_KEY} \
  -v /opt/docker/sentry/sentry:/var/lib/sentry/files \
  sentry-onpremise \
  pip install sentry-plugins

echo "Run service WEB"
docker run \
  --detach \
  --link sentry-redis:redis \
  --link sentry-postgres:postgres \
  --env SENTRY_SECRET_KEY=${SENTRY_SECRET_KEY} \
  --name sentry-web \
  --publish 9000:9000 \
  -v /opt/docker/sentry/sentry:/var/lib/sentry/files \
  sentry-onpremise \
  run web
sleep 15
echo "Run service WORKER"
docker run \
  --detach \
  --link sentry-redis:redis \
  --link sentry-postgres:postgres \
  --env SENTRY_SECRET_KEY=${SENTRY_SECRET_KEY} \
  --name sentry-worker \
  -v /opt/docker/sentry/sentry:/var/lib/sentry/files \
  sentry-onpremise \
  run worker
sleep 15
echo "Run service CRON"
docker run \
  --detach \
  --link sentry-redis:redis \
  --link sentry-postgres:postgres \
  --env SENTRY_SECRET_KEY=${SENTRY_SECRET_KEY} \
  --name sentry-cron \
  -v /opt/docker/sentry/sentry:/var/lib/sentry/files \
  sentry-onpremise \
  run cron

echo "Set config https://github.com/getsentry/sentry/issues/12722"
date
sleep 60
date
docker exec sentry-web sentry config set sentry:version-configured '9.1.0'

Create account

docker exec -it sentry-web bash
sentry createuser --superuser

Install Telegram Plugin

docker exec -it sentry-web bash
pip install sentry-telegram
docker restart sentry-web

Start

docker start sentry-postgres sentry-redis sentry-cron sentry-worker sentry-web

Stop

docker stop sentry-cron sentry-worker sentry-web sentry-postgres sentry-redis

Tunnel for browser

<?php

use GuzzleHttp\Client;

require dirname(__DIR__) . '/vendor/autoload.php';

header("Access-Control-Allow-Origin: *");

$envelope = file_get_contents('php://input');
$pieces = explode("\n", $envelope);
$header = @json_decode($pieces[0], true);
$content = @json_decode($pieces[2], true);

if (isset($header["dsn"]) && isset($content['exception'])) {
    $dsn = parse_url($header["dsn"]);
    $sentry_key = $dsn['user'] ?? '';
    $host = $dsn['host'] ?? '';
    $project_id = intval(trim($dsn["path"], "/"));
    $url = "https://$host/api/$project_id/store/?sentry_key=$sentry_key&sentry_version=7";
    try {
        $client = new Client();
        $response = $client->post($url, [
            'headers' => [
                "Content-Type" => "application/json",
            ],
            'body' => $pieces[2],
        ]);
        echo $response->getBody()->getContents();
    } catch (Exception $e) {
    }
}
⚠️ **GitHub.com Fallback** ⚠️