What is Sentry? docker deployment

Keywords: Docker Redis Java Python

What is Sentry? Docker deployment

1. what is Sentry?

Sentry is a log aggregation platform for real-time events. It specializes in monitoring errors and extracting all useful information for analysis, and no longer relies on user feedback to locate problems.

What's Sentry?
Sentry fundamentally is a service that helps you monitor and fix crashes in realtime. The server is in Python, but it contains a full API for sending events from any language, in any application.
Official website address, self-brain-filling
github Address on Official Website

2. Sentry deploys services using mirrors

2.1 Download Mirror:

docker pull redis
docker pull postgres 
docker pull sentry

2.2 Start redis and postgres

docker run -d --name sentry-redis --restart=always redis
docker run -d --name sentry-postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=sentry --restart=always postgres 

2.3 Generate the secret key, remember to save the key after generation

sai:Downloads ws$ docker run --rm sentry config generate-secret-key
1pmvmvs=ly89)k!8tw5x1nanj5@)0fk9u#zw^d&ai#n8z=t90w

2.4 Initialization of data structures

This step takes longer and is patient. In the middle, the user will be prompted to enter the super user:

#Initialize the data structure [During the upgrade, you will be prompted to create the initial user who will act as a superuser]
docker run -it --rm -e SENTRY_SECRET_KEY='1pmvmvs=ly89)k!8tw5x1nanj5@)0fk9u#zw^d&ai#n8z=t90w' --link sentry-postgres:postgres --link sentry-redis:redis sentry upgrade

2.5 Start sentry's three containers

my-sentry: sentry's web Service
sentry-cron: sentry's timing task, activity detection, etc.
sentry-worker: business processing, data persistence, alarm, etc.

docker run -d -p 9000:9000 --name my-sentry -e SENTRY_SECRET_KEY='1pmvmvs=ly89)k!8tw5x1nanj5@)0fk9u#zw^d&ai#n8z=t90w' --link sentry-redis:redis --link sentry-postgres:postgres sentry 

docker run -d --name sentry-cron -e SENTRY_SECRET_KEY='1pmvmvs=ly89)k!8tw5x1nanj5@)0fk9u#zw^d&ai#n8z=t90w' --link sentry-postgres:postgres --link sentry-redis:redis sentry run cron 

docker run -d --name sentry-worker-1 -e SENTRY_SECRET_KEY='1pmvmvs=ly89)k!8tw5x1nanj5@)0fk9u#zw^d&ai#n8z=t90w' --link sentry-postgres:postgres --link sentry-redis:redis sentry run worker 

2.6 docker PS-A to view container startup

Note: The container here can be restarted by: docker restart container id

2.7 visit http://localhost:9000/auth/login/sentry/

2.8 use, first set to Chinese.

2.9 Create project and set client key

3.0 java project uses:

import io.sentry.Sentry;
import io.sentry.SentryClient;
import io.sentry.SentryClientFactory;
import io.sentry.context.Context;
import io.sentry.event.BreadcrumbBuilder;
import io.sentry.event.UserBuilder;

/**
 * @author honglei
 * @since 2019-09-17
 */
public class MySentry {

    private static SentryClient sentryClient;

    public static void main(String... args) {
        /*
         It is recommended that you use the DSN detection system, which
         will check the environment variable "SENTRY_DSN", the Java
         System Property "sentry.dsn", or the "sentry.properties" file
         in your classpath. This makes it easier to provide and adjust
         your DSN without needing to change your code. See the configuration
         page for more information.
         */
        //Sentry.init();

        // You can also manually provide the DSN to the ``init`` method.
        String dsn = "http://663bc279986a4f81a46e338fdef693df:313a924a38854dff9518080b68852de2@192.168.1.108:9000/2";
        sentryClient = Sentry.init(dsn);
        sentryClient.setServerName("demo");
        /*
         It is possible to go around the static ``Sentry`` API, which means
         you are responsible for making the SentryClient instance available
         to your code.
         */
        //sentry = SentryClientFactory.sentryClient();

        MySentry mySentry = new MySentry();
        mySentry.logWithStaticAPI();
        mySentry.logWithInstanceAPI();
        mySentry.logWithMyProject();
    }

    /**
     * Examples using the (recommended) static API.
     */
    void logWithStaticAPI() {
        // Note that all fields set on the context are optional. Context data is copied onto
        // all future events in the current context (until the context is cleared).

        // Record a breadcrumb in the current context. By default the last 100 breadcrumbs are kept.
        Sentry.getContext().recordBreadcrumb(
                new BreadcrumbBuilder().setMessage("User made an action").build()
        );

        // Set the user in the current context.
        Sentry.getContext().setUser(
                new UserBuilder().setEmail("409178623@qq.com").build()
        );

        // Add extra data to future events in this context.
        Sentry.getContext().addExtra("extra", "thing");

        // Add an additional tag to future events in this context.
        Sentry.getContext().addTag("StaticAPI", "StaticAPI" + (System.currentTimeMillis() / 1000) / 60);
        /*
         This sends a simple event to Sentry using the statically stored instance
         that was created in the ``main`` method.
         */
        Sentry.capture("This is a test 4 logWithStaticAPI" + (System.currentTimeMillis() / 1000) / 60);
        try {
            throw new UnsupportedOperationException("logWithStaticAPI: This is a logWithStaticAPI Test throw exception");
        } catch (Exception e) {
            // This sends an exception event to Sentry using the statically stored instance
            // that was created in the ``main`` method.
            //Sentry.capture(e);
        }
    }

    /**
     * Examples that use the SentryClient instance directly.
     */
    void logWithInstanceAPI() {
        // Retrieve the current context.
        Context context = sentryClient.getContext();

        // Record a breadcrumb in the current context. By default the last 100 breadcrumbs are kept.
        context.recordBreadcrumb(new BreadcrumbBuilder().setMessage("User made an action").build());

        // Set the user in the current context.
        context.setUser(new UserBuilder().setEmail("409178623@qq.com").build());

        // This sends a simple event to Sentry.
        sentryClient.sendMessage("This is a test 4 logWithInstanceAPI ");
        try {
            throw new IllegalArgumentException("logWithInstanceAPI: An example method that throws an exception.");
        } catch (Exception e) {
            // This sends an exception event to Sentry.
            //sentryClient.sendException(e);
        }
    }

    void logWithMyProject() {

        try {
            throw new Exception("This is a exception Test throw exception");
        } catch (Exception e) {
            // Retrieve the current context.
            Context sentryContext = sentryClient.getContext();
            // Set the user in the current context.
            Sentry.getContext().setUser(new UserBuilder().setEmail("409178623@qq.com").build());
            // Add an additional tag to future events in this context.
            sentryContext.addTag("subject", "Test Mail Service" + System.currentTimeMillis() / 1000);
            // Add an additional tag to future events in this context.
            sentryContext.addTag("to", "hongleishen@hotmail.com");
            // This sends an exception event to Sentry.
            sentryClient.sendException(e);
        }
    }
}

Posted by fernado1283 on Tue, 01 Oct 2019 02:02:22 -0700