【Turn】Sentry Introduction

Sentry is an open source real-time error reporting tool that supports web front-end and back-end, mobile applications and games, supports mainstream programming languages ​​and frameworks such as Python, OC, Java, Go, Node, Django, RoR, etc.  It also provides GitHub, Slack, Trello, etc. Integration of common development tools .

basic concept

What is Sentry

Usually when we say Sentry, we mean Sentry's backend service, written by Django. Version 8.0 uses React.js to build the front-end UI. Before using Sentry, you also need to configure Sentry's SDK in your own application - usually called Raven in the package management tool of each language.

Of course, Sentry can also be the Sentry SaaS service provided by its company.

If you are looking for a similar service in China, try Fundebug ! Fundebug currently supports front-end JavaScript , WeChat applet, and back-end Nodejs bug monitoring. It is served in the form of SaaS and provides a basic free version.

 

DSN(Data Source Name)

The Sentry service supports multi-user, multi-team, and multi-application management. Each application corresponds to a PROJECT_ID, as well as PUBLIC_KEY and SECRET_KEY for authentication. This composes a DSN like this:

'{PROTOCOL}://{PUBLIC_KEY}:{SECRET_KEY}@{HOST}/{PATH}{PROJECT_ID}'

PROTOCOL is usually  http or  https, HOST is the hostname and port of the Sentry service, and PATH is usually empty.

Deploy the Sentry service

Install

Since Sentry has many dependencies, it is recommended to install it in a separate Virtualenv. Sentry relies on Unix-compatible systems, Python 2.7, PostgreSQL, and Redis, make sure you have these installed. Considering the deployment of a Python WSGI application, you may also need Nginx or Apache 2 as a front-end server, and a supervisor to manage the application.

With these, the installation of Sentry is very simple: pip install sentry.

configure

start up

I wrote a simple Supervisor configuration file myself for reference.

Using the Sentry SDK

Sentry's SDK is usually called Raven in the package manager of each language, and it is very simple to use. Take Python as an example:

from raven import Client
client = Client('https://<key>:<secret>@app.getsentry.com/<project>')

try:
    1 / 0 except ZeroDivisionError: client.captureException() 

This will use the  client object to submit log information to the Sentry server.

Of course, Sentry also provides convenient packaging for well-known web frameworks. Take the Python Flask framework as an example:

sentry = Sentry(dsn='http://public_key:[email protected]/1')

def create_app(): app = Flask(__name__) sentry.init_app(app, logging=True, level=logging.ERROR) return app 

Add contextual information

In order to solve a problem, contextual information is often also needed to reproduce the problem at the time, as well as to quickly understand the scope of the impact.

client.user_context({
    'email': request.user.email
})

Using the Sentry web service

search

Sentry's search supports  token:value syntax such as:

is:resolved user.username:"Jane Doe" server:web-8 example error

Supported tokens include:

  • is: problem status (resolved, unresolved, muted)
  • assigned: the assignment status of the issue (user ID, user email or  me)
  • release: specifies the issues that occurred in the release version
  • user.id
  • user.email
  • user.username
  • user.ip

notify

Merge & Sample

Data filtering

Integrate with other services

Integration with GitLab

Integration with Trello

refer to:

- [Sentry Python 文档](https://docs.getsentry.com/on-premise/clients/python)

来源:https://blog.csdn.net/scdxmoe/article/details/53539216

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325156478&siteId=291194637