Why use error log Sentry?

The original pattern

By logging the error log to the log file of the server, and then querying the log content of the current day to modify the error.

disadvantages

  • 1. High level of hassle: We had to log in to the server to find the corresponding records and write our own email code
  • 2. Low timeliness: We need to actively query where the bugs come from and analyze the problems. In fact, for web services with users, we need to know immediately when errors occur (sending emails to ourselves (if there are many errors), the emails will be too many and burst).
  • 3. Low concentration: We can’t manage bugs centrally. The advantage of centralized management is that we can easily assign bugs to different people to fix
  • 4. Poor customization: Different customized emails are required for project management

2. Sentry installed

Sentry profile

  • 1.Sentry is an error log management system developed using Django-Rest Framework (DRF)
  • 2.Sentry is cross-platform application monitoring, with a focus on error reporting.
  • 3. Sentry has a free version of the established Sentry official website, but it has certain limitations (email frequency and speed). For some small projects, it is recommended to use the free version of the official website directly

Install the sentry

Sentry has two installation modes

  • 1. Python installation is cumbersome and requires a lot of manual configuration
  • 2. Docker installation (recommended)

Centos7 installation docker

  • Notice The running memory size of the VM or server must be greater than 2 GB (3 GB is allocated before the VM is started).
  • Notice To use the proxy network, configure the YUM proxy
  1. Install docker dependencies
yum install -y yum-utils device-mapper-persistent-data lvm2
Copy the code
  1. Install the docker – ce
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce
Copy the code
  1. Start the Docker background service
sudo systemctl start docker
Copy the code
  1. A test run
docker run hello-world
Copy the code
  • Pay attention to
  • For proxy Internet access (proxy needs to be configured)
- find / -name docker. Service - vim/usr/lib/systemd/system/docker. Service - add - under service The Environment HTTP_PROXY = = "http://username:password@ip:port"Copy the code
  1. Setting boot
sudo systemctl enable docker
Copy the code

Centos7 installation sentry

yum install git
git clone https://github.com/getsentry/onpremise.git
Copy the code

(Gitee can be used to search getSentry /onpremise if git is inaccessible.)

Install docker-compose using PYTHon3

Yum install python3 pip3 install docker-compose docker-compose --version If command not found find / -name docker-compose Create a soft link for it ln -s /python3/lib/..... /docker-compose /usr/bin/docker-compose docker-compose --versionCopy the code

Curl gets docker-compose directly

The curl -l https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose- ` ` uname - s - ` uname -m ` > /etc/usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-composeCopy the code

onpremise

  • There are two pits before running./install.sh
  • 1. You may need to change the permission of./install.sh (Chmod -r 777./install.sh).
  • 2. If you use the company agent to access the Internet, you need to configure the agent for each docker container when creating it
  • Docker container proxy configuration
  • In the current user’s home directory
mkdir .docker
touch ./docker/config.json
vim ./docker/config.json
Copy the code
{
  	"proxies":
   	{
      "default":
      {
      	"httpProxy": "http://username:pwd@ip:port",
      	"httpsProxy": "https://username:pwd@ip:port"
      }
    }
 }
Copy the code
  • Run. / install. Sh
CD onpremise./install.sh Docker-compose run --rm web createUser docker-compose run -- docker-compose run --rm web createUserCopy the code
  • Docker-compose run –rm web can be used as an alias for the docker-compose run –rm web and python sentry commands

Docker-compose run –rm web sentry alias docker-compose run –rm web sentry

  • If you do not use Chrome, you will be denied access to static resources from sentry. IO.

Please wait while we load an obnoxious amount of JavaScript You may need to disable adblocking extensions to load Sentry.

  • Centos download Google
Google chrome --no-sandbox # centosCopy the code

Configure the mail pit

  • 1. Need/onpremise/sentry/config. Yml configured SMTP
  • Configure mail
  • Write dead if qq.com is directly prohibited to send, need to modify the source re
  • Qq mailbox pit
  • Ali cloud disables port 25. If you use Ali Cloud as sentry server, please use 465, but Sentry does not support SSL
  • Ali cloud server pit
  • Sentry does not support SSL
  • 2. Note that the user password needs to use the authorization code of each mailbox (for specific search, such as qq mailbox authorization code).
  • 3. Add the server email user name to your whitelist of email addresses that receive error messages to avoid interception

3. Sentry applications

  • 1. Create a project create Project
  • 2. The project needs to be identified by DSN
  • 3. Choose To apply Python
  • 4. Create a Python script
pip install raven
Copy the code
from raven import Client
dsn = "http://88f33332e0d643bf8924dd3be378de9e@xxxxxxx:9000/6"
client = Client(dsn)

try:
    3/0
except ZeroDivisionError:
    Client.captureException()
Copy the code
  • 5. Run the script and you can see the error message of your script in the project
  • 6. Personalized customization can be set in the project, such as how to send emails once for the same content, the frequency of sending emails, which IP addresses can be accessed and so on.

Specific Settings through document review

Sentry is integrated with Django

  • Setting in the configuration
INSTALLED_APPS = [
...,
'raven.contrib.django.raven_compat',
]
RAVEN_CONFIG = {
    'dsn': "http://88f33332e0d643bf8924dd3be378de9e@xxxxxxxxxx:9000/6",
    # If you are using git, you can also automatically configure the
    # release based on the git info.
    # 'release': raven.fetch_git_sha(os.path.abspath(os.pardir)),
}
Copy the code

Manage.py can send tests via Raven Test, and any errors can be sent to Sentry for us. Because of the integrated development mode of django configuration app, configuration is that easy.

  • Sentry can also integrate with various applications such as Github GitLab to enrich personal customization and complement it later