Initial Sentry for Online Bug Tracking (PART 1)

Sentry Release +sourceMap (2)

The first two chapters covered the basic usage and setup of Sentry, and this chapter continues to illustrate some advanced applications of Sentry.

Get contextual information about the bug

Analysis a bug, if you know the line where the error, basically solved the problem of the 70%, but in some situations, is not enough, such as an API request return of data, a strange error this time, but our bug information if there is no error and ask, so we want to recover the bug is in trouble, So Sentry also provides an interface to the context of bug information

Docs. Sentry. IO/enriching – e…

It is mainly about user, tag, level and extra.

For example, if we need to monitor an important API, every time something goes wrong, we need to tell it what data is being requested when the error message is returned. How do I write ni? Look at the code below

Sentry.setUser({"email": "[email protected]"});
Sentry.setTag('api'.'api/list/get')
Sentry.setLevel('error');
Sentry.setExtra('data', {
  req: {a:1},
  res: {b:1},
  header:headers
})
Sentry.captureException(new Error('throw new api'))

Copy the code

Sentry Indicates the information received by the background

The above code is the custom error message. If your project is simple, you don’t even need to write sentry. captureException, just init Sentry, and it will automatically catch errors.

Keep reading.

Sentry automatic upload error

At this stage, the main core applications of Sentry have been introduced, but there are many downsides, such as

  • Errors require a manual call to captureException, which can be logged automatically
  • How to combine with VUE is not reflected here

Go straight to code

<template <div class="sentry"> < button@click ="handlerError" @click="handlerError2" </button> </div> </template> <script> export default {name: 'sentry', methods: { handlerError() { throw new Error('throw new Error') }, handlerError2() { this.data.list = 1 } } } </script>Copy the code

The code is simple, two buttons

  • The first button throws an error directly
  • The second button, because it does not define data, is bound to fail as well

When we click on a button, an error is triggered. When this happens, sentry is not explicitly called. Will the error be recorded? Let’s go to sentry’s background records and see

Apparently it will. Why, Ny?

Because within @Sentry/Integrations (the API used to enhance Sentry), it reinitializes errorHandler at initialization, we can log error messages without writing captureException

Code: github.com/getsentry/s…

While @Sentry/Integrations provides support for this, I personally don’t recommend it because it forces the binding of errorHandler in this way, and if we need to further customize errors, it won’t be able to do it.

In a real business environment, we might have multiple systems, but they are all under one system. Is there a way to share a Sentry project without creating a Sentry project for each system, and then distinguish between the different systems?

The Sentry doesn’t provide a direct solution, but the way it sets the environment, I think, can solve this problem indirectly, is that when the code sets the environment, different systems, give it an identifier, so that when the release number, also add this representation, You can identify it.

// Initialize sentry, process.env.node_env with two values development and production
 Sentry.init({
      dsn: 'https://[email protected]/1511376'.environment: process.env.NODE_ENV,
      integrations: [new Integrations.Vue({ Vue, attachProps: true})].release: releaseConfig[releaseEnv].release || ' '
    })
Copy the code

This way you can see bugs between different systems in the background of Sentry. I personally don’t recommend this, but the team currently has a large system with a variety of smaller systems, and it would be a hassle to have a Sentry project configured for each system.

Well, it’s over.

Sentry actually has been used before, but it’s 8 x version, no bug tracking system in the new company, so also need to install a set of, but found that sentry has been updated to 9. The x version, this version, no matter from the system installation and the project’s deployment and 8 x are quite different, stepped on some pit, write a tutorial, avoid to pit.

The only disadvantage of this system is that it does not provide screenshots, which requires the development of plug-ins by ourselves. Besides, the webpack plug-in of Sourcemap that is officially provided for uploading is relatively poor, and it is better to provide it by the community.

About how to install Sentry

For sentry installation, it is best to ask o&M to help install it, because there are many dependent environments (nginx, Redis, PostgreSQL, STMP services).

  1. The official website installation method (Python+Docker), provides two ways, one Docker installation, one Python environment installation.

Docs. Sentry. IO/server/inst…

  1. The community installs from scratch, from Docker, to dependencies, and finally to Sentry, which is very clear and appropriate for white players

Learnku.com/articles/42…

For the above two methods, docker-compose is recommended by the official website for installation. The specific method is to fork a Docker script recommended by the official website, customize the configuration, and then update the version through git. If there is a problem, modify git and then remotely pull down the installation, which is more convenient. This is the way it is currently used

Github.com/getsentry/o…

In the pit of

A. The email cannot be received due to incorrect email Settings

  • The official SMTP port provided by Tencent Mail is 465, but the actual port of enterprise email is 587, which is a huge pit
  • Now the latest version is 9.x version, which is different from the previous 8.x configuration. Then, I choose the installation mode of Docker-compose, and I need to set environment variables separately in. Env

See solution page learnku.com/articles/94…

B. 8x client apis (Raven) are not applicable and deprecated. Any references to Raven are in the past, so don’t read them.

Docs. Sentry. IO/clients/jar…

On the whole, the bug tracking system is very good, not only support JS client, but also support various back-end languages, the key is free.