安裝centry

一、成功安裝

  1. 安裝docker
    sudo yum -y install docker-io 
    
  2. 啓動docker
    service docker start
    
  3. docker換源
    sudo curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://6616fe43.m.daocloud.io
    
  4. 將docker加入到開機啓動中
    chkconfig docker on
    
  5. docker拉取redis postsql 和sentry
    docker pull redis 
    docker pull postgres 
    docker pull sentry
    
  6. 啓動redis和sentry
    docker run -d --name sentry-redis redis docker run -d --name sentry-postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=sentry postgres docker run --rm sentry config generate-secret-key
  7. 啓動sentry(上一行得到secret-key,然後把key複製到下面四行的單引號中)
    docker run -it --rm -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-postgres:postgres --link sentry-redis:redis sentry upgrade
    
    (這一步會提示輸入郵箱和密碼)
    docker run -d -p 9000:9000 --name my-sentry -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-redis:redis --link sentry-postgres:postgres sentry
    docker run -d --name sentry-cron -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-postgres:postgres --link sentry-redis:redis sentry run cron 
    docker run -d --name sentry-worker-1 -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-postgres:postgres --link sentry-redis:redis sentry run worker 
    

採集java終端:

  1. 創建java採集project 在這裏插入圖片描述
  2. 創建一個java項目,創建MySentry.java:
package com.lenovo.ai.uuid.sentry;

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;

public class MySentry {
    private static SentryClient sentry;

    public static void main(String... args) {
        Sentry.init();
        sentry = SentryClientFactory.sentryClient();
        MySentry myClass = new MySentry();
        myClass.logWithStaticAPI();
        myClass.logWithInstanceAPI();
    }

    void unsafeMethod() {
        throw new UnsupportedOperationException("You shouldn't call this!");
    }

    void logWithStaticAPI() {
        Sentry.getContext().recordBreadcrumb(
                new BreadcrumbBuilder().setMessage("User made an action").build()
        );
        Sentry.getContext().setUser(
                new UserBuilder().setEmail("[email protected]").build()
        );
        Sentry.getContext().addExtra("extra", "thing");
        Sentry.getContext().addTag("tagName", "tagValue");
        Sentry.capture("This is a test");
        try {
            unsafeMethod();
        } catch (Exception e) {
            Sentry.capture(e);
        }
    }

    /**
     * Examples that use the SentryClient instance directly.
     */
    void logWithInstanceAPI() {
        Context context = sentry.getContext();
        context.recordBreadcrumb(new BreadcrumbBuilder().setMessage("User made an action").build());
        context.setUser(new UserBuilder().setEmail("[email protected]").build());
        sentry.sendMessage("This is a test");
        try {
            unsafeMethod();
        } catch (Exception e) {
            // This sends an exception event to Sentry.
            sentry.sendException(e);
        }
    }
}
  1. 配置文件centry.properties:
dsn=http://[email protected]:9000/3

備註:a48a254da2b34b04aea48b8a55174756
在這裏插入圖片描述

  1. 工程結構: 在這裏插入圖片描述
  2. 運行MySentry,java,在web頁面上看到:
    在這裏插入圖片描述

監控js項目:

  1. 創建html
<html>
	<head>
		<script src="https://browser.sentry-cdn.com/5.5.0/bundle.min.js" crossorigin="anonymous"></script>
		<script type="text/javascript">
					Sentry.init({ dsn: 'http://[email protected]:9000/2' });
					myUndefinedFunction();
		</script>		
</head>
</html>

因爲myUndefinedFunction函數未定義,所以會出現js異常

  1. 在web頁面上,可以看到:
    在這裏插入圖片描述
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章