Automated setup for sentry including new project

Since we are often setting up new environments from scratch we would like to automated setting up sentry in each environment as well. Right now we are using the official sentry docker from dockerhub

This includes:

  • create the admin user (maybe solvable by automating the steps in docker and sending text into that)
  • creating a project
  • retrieving the DSN for a project

I had a look into the sentry-cli, but that looks more for solving issues and sending test messages, not for setting it up.

Are there any resources or examples for our kind of problem?

Thanks in advance,

I just learned that there is
but also which I should look into :slight_smile:

sentry-cli won’t help you here. You’d want to leverage our API.

Sorry to revive such an old thread, but thought I would chime in with how I did this sort of thing with via Python scripts and SaltStack.

Note: Sentry automatically creates a DSN when a Project model is saved so I had to delete that an re-create it later with a known DSN.

Note 2: I’ve installed sentry in /opt, if you install via pip I expect the location will be different.

#The Scripts

import sys

from sentry.runner import configure

from sentry.models import Project, ProjectKey

project_id = sys.argv[1]
project_name = sys.argv[2]
slug = project_name.lower()

p = Project.objects.create(id=project_id, name=project_name, public=False, slug=slug, team_id=1, organization_id=1)

import sys

from sentry.runner import configure

from sentry.models import Project, ProjectKey

project_name = sys.argv[1]
slug = project_name.lower()
public_key = sys.argv[2]
secret_key = sys.argv[3]

p = Project.objects.get(slug=slug)
ProjectKey.objects.create(project=p, public_key=public_key, secret_key=secret_key, roles=1)

#The Salt

    - name: SENTRY_CONF=/etc/sentry /opt/sentry/bin/python /etc/sentry/scripts/ 2 Foo
    - unless: echo "from sentry.models import Project; print Project.objects.get(name='Foo')" | SENTRY_CONF=/etc/sentry sentry shell | grep -q -i Foo

Then a similar state for the command:

- name: SENTRY_CONF=/etc/sentry /opt/sentry/bin/python /etc/sentry/scripts/ Foo FooPublicKey FooSecretKey
- unless: echo "from sentry.models import ProjectKey; print ProjectKey.objects.get(project__name='Foo')" | SENTRY_CONF=/etc/sentry sentry shell | grep -q -i Foo

Users are simpler, you can just execute straight through sentry CLI:

- name: SENTRY_CONF=/etc/sentry sentry createuser --email admin --password admin --superuser --no-input
- unless: echo "from django.contrib.auth import get_user_model; print get_user_model().objects.all()" | SENTRY_CONF=/etc/sentry sentry shell | grep -q -i admin

Of course executing these states assumes you’ve already put the Python scripts in place. I put them in /etc/sentry/scripts.

For anyone else arriving here after searching how to do this for Sentry On-Premise version 20, use the logic of this gist ->