Sentry is an open source application monitoring and error tracking solution. This solution consists of SDKS corresponding to various languages and a set of huge data backend services. The application uses the token bound to it to access the Sentry SDK to configure data reporting. The Sentry SDK can also be configured to report version information and release environment associated with errors. In addition, the Sentry SDK automatically captures related operations before exceptions occur, facilitating subsequent exception tracing. After the abnormal data is reported to the data service, it is filtered, extracted, and displayed on the Web page of the data background.
Sentry has been used for several years to monitor front-end errors. The unified @zz-common/ Sentry library that we packaged on the SDK side. In this way, vUE, React, small program, node, SSR unified access and error hierarchical management are realized. See this article for a look at the business Front End Error Monitoring System (Sentry) Policy upgrade. The Sentry we used before was an older version of the source code installation. Then the client needs to access Sentry and upload the Mapping file. But older versions of Sentry always failed to upload. So we’re going to upgrade Sentry. This article is intended to document the Sentry upgrade deployment and problems encountered.
Deploy the Sentry service
Docker-based Compose is officially available for quick deployment of Sentry service. Docker is an open source containerization technology for building and containerizing applications. Compose is a tool for configuring and running multiple Docker apps, allowing you to configure all of your app’s services from a single profile and create and run them with one click.
Deployment and configuration requirements:
- The Docker 19.03.6 +
- Compose 1.24.1 +
- 4 CPU Cores
- 8 GB RAM
- 20 GB Free Disk Space
Install the docker
yum install docker -y
# Check version informationDocker info or docker -vCopy the code
Docker image acceleration:
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://registry.docker-cn.com", // The official mirror"https://mirrors.tuna.tsinghua.edu.cn", // Tsinghua Mirror"http://hub-mirror.c.163.com", // netease 163 image"https://docker.mirrors.ustc.edu.cn", // USTC Mirror]}# restart docker
sudo systemctl daemon-reload
sudo systemctl restart docker
Copy the code
Install the docker – compose
wget -O /usr/local/ bin/docker - compose chmod 777 https://github.com/docker/compose/releases/download/1.27.3/docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
# Check docker-compose version
docker-compose version
Copy the code
Clone the source code to the installation directory:
git clone https://github.com/getsentry/onpremise.git
Switch branches that need to be installedGit checkout 21.4.1Copy the code
Run the deployment script:
cd onpremise
./install.sh
Copy the code
Start the service
docker-compose up -d
Copy the code
Sentry service function
Using the Docker ps command, we can see many services started by Sentry
- redis
- kafka
- clickhouse
- zookeeper
- postgres
- memcached
- stmp
- sentry-cron
- sentry-worker
- sentry-web
- nginx
The overall operation flow of Sentry is shown below:
The configuration file
Onpremise main configuration files after deployment
- Config. yml: indicates the configuration file
- Sentry.conf. py: Python code that overwrites or is incorporated into the Sentry service to affect sentry operation.
- Env: mirroring version, data retention days, and port number
Example Upgrade the Sentry service
Now that the new service is installed, you need to migrate the old data to the new service. The previous service used a separate Postgres cluster.
Modifying the Database Configuration
Configure the database to a separate cluster by modifying the sentry.conf.py file
DATABASES = {
'default': {
'ENGINE': 'sentry.db.postgres'.'NAME': 'sentry'.'USER': 'postgres'.'PASSWORD': 'postgres'.'HOST': 'HOST'.'PORT': '7001'.'AUTOCOMMIT': True,
'ATOMIC_REQUESTS': False,
}
}
Copy the code
Running the Upgrade Command
Sentry provides a one-click upgrade command to upgrade the database to the corresponding new version, but note that the previous version must be above 9.1.2. Incompatible if less than 9.1.2. User and project data can only be exported by command. Discard previous error messages.
docker-compose run --rm web upgrade
Copy the code
Problems encountered during the upgrade
The disk usage is too large
As data is reported, the local disk usage of the server increases. If the default Sentry configuration is kept for 90 days, the disk usage remains at a relatively high value after full access. In addition, such a large amount of data is also a burden for data query. To ease the burden, you need to start on both the server and business application sides. In consideration, we changed the data retention period to 7 days. Env file:
SENTRY_EVENT_RETENTION_DAYS=7
Copy the code
Docker data store location needs to be modified. By default, Docker Volume is mounted in the /var directory. The capacity of our /var directory is only 100G, which will soon be full with the running of the service. Therefore, we need to modify the docker Volume mount directory.
Create a folder in the directory with the maximum capacity
mkdir -p /opt/var/lib
# Stop docker service
systemctl stop docker
# Migrate data
/bin/cp -a /var/lib/docker /opt/var/lib/docker && rm -rf /var/lib/docker && ln -s /opt/var/lib/docker /var/lib/docker
Restart the Docker service
systemctl start docker
Copy the code
Number of users Lost
After the upgrade, the number of users fails to be obtained, that is, the Sentry service cannot obtain the real IP address.
Obtain IP address is disabled by default in Sentry management background. You need to manually enable it.