Self-Hosted Sentry
repository·master·Indexed 27 days ago
https://github.com/getsentry/self-hostedA feature-complete version of Sentry packaged for low-volume deployments and proofs-of-concept. This repository provides nightly builds, installation scripts, and configuration for services including Snuba, Postgres, Pgbouncer, Redis, Memcached, and Clickhouse. It includes a patch system for modifying configuration files and support for remote development via Google Cloud Workstations and Artifact Registry, manageable through the sentry CLI.
What's inside sentry-self-hosted
- Self-Hosted Sentry provides a feature-complete version of Sentry packaged for low-volume deployments and proofs-of-concept. For detailed installation instructions, configuration, and management, refer to the official documentation.
Create a new patch for optional modifications
masterTo create a patch for a configuration file, follow these steps:
- Copy the original file to a temporary file (e.g.,
docker-compose.ymlbecomesdocker-compose.my-feature.yml). - Apply your desired changes to the temporary file.
- Generate a unified diff patch using the
diff -Narucommand. - Organize the patch by creating a new directory under
optional-modifications/patches/[patch-name]and moving the.patchfiles there.
Template command:
diff -Naru [original file] [patched file] > [destination file].patch- Copy the original file to a temporary file (e.g.,
Configure Google Cloud for Remote Self-Hosted Development
masterTo enable remote development, you must set up two Google Cloud services: Google Cloud Workstations (to run virtual machines) and Artifact Registry (to store base images).
1. Create an Artifact Registry
- Navigate to the Google Cloud Artifact Registry console.
- Create a new repository.
- Recommended name:
sentry-workstation-us. - Recommended region:
us-west1.
2. Set up Cloud Workstations
- Navigate to the Cloud Workstations control panel.
- Create a Cluster: Create one cluster per region (e.g.,
us-westinus-west1). - Create a Configuration: Within the cluster, create a configuration with the following settings:
- Name: Use the convention
[INSTALL_KIND]-[SIZE]-[CLUSTER_NAME](e.g.,postinstall-standard-us-west). - Install Mode: Choose
preinstall(if./install.shhas not run) orpostinstall(if it has). - Resource Allocation: Choose
small,standard, orlarge(e.g.,E2instances are sufficient for most work). - Image: Select
Custom container imageand choose your uploaded Docker image. - Disk: Select
Create a new empty persistent disk(10GB is recommended). - IAM: Set appropriate policies to allow user access.
- Name: Use the convention
Apply optional modifications using patches
masterOptional modifications are implemented via a patch system that allows you to modify existing Sentry configuration files (like
.env,config.example.yml,sentry.conf.example.py, ordocker-compose.yml) to suit your infrastructure.To apply patches:
- Run the patch commands from the root directory of the repository.
- Use the
-p0flag with thepatchcommand to ensure files are applied to the correct absolute paths. - Crucial: After applying patches, review the modified files for any required manual steps (such as providing credentials or TLS certificates) before running the
install.shscript. - Run
./install.shto finalize the installation with the new configurations.
WARNING This system is experimental. Use it at your own risk.
Build and upload workstation Docker images
masterWorkstation configurations require Docker images located in the Artifact Registry. You can build either
preinstallorpostinstallimages using the Dockerfiles provided in the repository.First, authenticate your local environment with Google Cloud and Docker:
export GCP_PROJECT_ID=my-gcp-project gcloud auth application-default login gcloud config set project $GCP_PROJECT_ID gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://us-docker.pkg.devThen, define your environment variables and push the image:
export GROUP=sentry-workstation export REGION=us export PHASE=pre # Use 'pre' for preinstall, 'post' for postinstall export REPO=${GROUP}-${REGION} export IMAGE_TAG=${GROUP}/${PHASE}install:latest export IMAGE_URL=us-docker.pkg.dev/${GCP_PROJECT_ID}/${REPO}/${GROUP}/${PHASE}install:latest # Build the image docker build -t ${IMAGE_TAG} -f ./${PHASE}install/Dockerfile . # Tag and push to Artifact Registry docker tag ${IMAGE_TAG} ${IMAGE_URL} docker push ${IMAGE_URL}export GCP_PROJECT_ID=my-gcp-project gcloud auth application-default login gcloud config set project $GCP_PROJECT_ID gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://us-docker.pkg.dev export GROUP=sentry-workstation export REGION=us export PHASE=pre export REPO=${GROUP}-${REGION} export IMAGE_TAG=${GROUP}/${PHASE}install:latest export IMAGE_URL=us-docker.pkg.dev/${GCP_PROJECT_ID}/${REPO}/${GROUP}/${PHASE}install:latest docker build -t ${IMAGE_TAG} -f ./${PHASE}install/Dockerfile . docker tag ${IMAGE_TAG} ${IMAGE_URL} docker push ${IMAGE_URL}Configure Nginx binding port
masterThe port on which Nginx binds is determined by the
SENTRY_BINDenvironment variable.ports: - "$SENTRY_BIND:80/tcp"Configure Redis and Memcached
masterThe setup uses
redis:6.2.20-alpineandmemcached:1.6.45-alpine.Redis Configuration:
- Uses a bind mount for
./redis.confat/usr/local/etc/redis/redis.conf. ulimits:nofilesoft/hard limits are set to10032.
Memcached Configuration:
- The command uses
-Ifollowed by${SENTRY_MAX_EXTERNAL_SOURCEMAP_SIZE:-1M}to set the maximum external sourcemap size.
- Uses a bind mount for
Configure Sentry event retention via cleanup
masterThe
sentry-cleanupservice runs a cron job that executessentry cleanup --days $SENTRY_EVENT_RETENTION_DAYS. The number of days to retain events is determined by theSENTRY_EVENT_RETENTION_DAYSenvironment variable.command: '"0 0 * * * gosu sentry sentry cleanup --days $SENTRY_EVENT_RETENTION_DAYS"'Configure Sentry service environment variables
masterThe
sentryservice uses several environment variables for configuration. Many of these can be passed through from the host system or a.envfile by leaving them empty in thedocker-compose.yml.Key variables include:
DOCKER_PLATFORM: Sets the platform for the build (e.g., for Apple silicon Macs).SENTRY_STATSD_ADDR: Address for StatsD monitoring.SENTRY_EVENT_RETENTION_DAYS: Number of days to retain events.SENTRY_KAFKA_MAX_POLL_INTERVAL_MS: Kafka polling interval.SENTRY_MAIL_HOST: The host for the SMTP service.SENTRY_MAX_EXTERNAL_SOURCEMAP_SIZE: Maximum size for external sourcemaps.SENTRY_SYSTEM_SECRET_KEY: The system secret key.LAUNCHPAD_RPC_SHARED_SECRET: Shared secret for Launchpad RPC.
To support custom CA certificates, the following variables are hardcoded to use the system CA bundle:
DEFAULT_CA_BUNDLE(used by botocore)REQUESTS_CA_BUNDLE(used by requests)GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR(used by grpc/google modules)
Configure Postgres and Pgbouncer
masterThe setup uses
postgres:14.23-bookwormandedoburu/pgbouncer:v1.25.2-p0.Postgres Configuration:
POSTGRES_USER: The database user (defaults topostgres).POSTGRES_HOST_AUTH_METHOD: Set totrust.
Pgbouncer Configuration:
DB_USER: Set to${POSTGRES_USER:-postgres}.DB_HOST: Set topostgres.DB_NAME: Set topostgres.AUTH_TYPE: Set totrust.POOL_MODE: Set totransaction.ADMIN_USERS: Set topostgres,sentry.MAX_CLIENT_CONN: Set to10000.
Configure Uptime Checker settings
masterThe
uptime-checkerservice can be customized via the following environment variables:UPTIME_CHECKER_RESULTS_KAFKA_CLUSTER: The Kafka cluster to report results to (default:kafka:9092).UPTIME_CHECKER_REDIS_HOST: The Redis host (default:redis://redis:6379).UPTIME_CHECKER_ALLOW_INTERNAL_IPS: Set totrueto allow uptime checks against private IP addresses (default:false).UPTIME_CHECKER_FAILURE_RETRIES: Number of retries before reporting a failure (default:1).UPTIME_CHECKER_STATSD_ADDR: StatsD address (default:${STATSD_ADDR:-127.0.0.1:8125}).
environment: UPTIME_CHECKER_RESULTS_KAFKA_CLUSTER: kafka:9092 UPTIME_CHECKER_REDIS_HOST: redis://redis:6379 UPTIME_CHECKER_ALLOW_INTERNAL_IPS: "false" UPTIME_CHECKER_FAILURE_RETRIES: "1" UPTIME_CHECKER_STATSD_ADDR: ${STATSD_ADDR:-127.0.0.1:8125}Configure Launchpad worker concurrency
masterThe concurrency for the
launchpad-taskworkerservice is controlled by theLAUNCHPAD_TASKWORKER_CONCURRENCYenvironment variable. If unset, it defaults to4.LAUNCHPAD_WORKER_CONCURRENCY: "${LAUNCHPAD_TASKWORKER_CONCURRENCY:-4}"