sentry spring boot 使用

 

1. pom.xml 加入库

<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry-spring</artifactId>
    <version>1.7.5</version>
</dependency>
<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry-logback</artifactId>
    <version>1.7.16</version>
</dependency>

2. 在resource 里边加入 logback.xml

<configuration>
    <!-- Configure the Console appender -->
    <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- Configure the Sentry appender, overriding the logging threshold to the WARN level -->
    <appender name="Sentry" class="io.sentry.logback.SentryAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>WARN</level>
        </filter>
    </appender>

    <!-- Enable the Console and Sentry appenders, Console is provided as an example
 of a non-Sentry logger that is set to a different logging threshold -->
    <root level="INFO">
        <appender-ref ref="Console" />
        <appender-ref ref="Sentry" />
    </root>
</configuration>

3.  @Configuration 里边加入:

    @Bean
    public HandlerExceptionResolver sentryExceptionResolver() {
        return new io.sentry.spring.SentryExceptionResolver();
    }

    @Bean
    public ServletContextInitializer sentryServletContextInitializer() {
        return new io.sentry.spring.SentryServletContextInitializer();
    }

4. resource 增加 sentry.properties (不是在application.properties 里)文件里边写入:

dsn=https://your-dsn-url@sentry.io/1464303

 

5. 调用:

private static LoggerAdapter logger = new LoggerAdapterFactory().getLoggerAdapter(some.class);
logger.Info("abc");
  •   mac 上边安装docker 用 dmg 形式,到网站上边注册一下id pwd 登陆进去。

        下边是安装sentry 的步骤:

  1. Start a Redis container

    $ docker run -d --name sentry-redis redis
    
  2. Start a Postgres container

    $ docker run -d --name sentry-postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=sentry postgres
    
  3. Generate a new secret key to be shared by all sentry containers. This value will then be used as the SENTRY_SECRET_KEYenvironment variable.

    $ docker run --rm sentry config generate-secret-key
    
  4. If this is a new database, you’ll need to run upgrade (这一步要输入邮箱密码时间比较长)

    $ docker run -it --rm -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-postgres:postgres --link sentry-redis:redis sentry upgrade
    

    Note: the -it is important as the initial upgrade will prompt to create an initial user and will fail without it

  5. Now start up Sentry server

    $ docker run -d --name my-sentry -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-redis:redis --link sentry-postgres:postgres sentry
    

            如果要改端口可以这样: 

             docker run -d -p 9000:9000 --name my-sentry -e SENTRY_SECRET_KEY='key' --link sentry-redis:redis --link sentry-                   postgres:postgres sentry

 

     6.   The default config needs a celery beat and celery workers, start as many workers as you need (each with a unique name)

$ 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

     7. 127.0.0.1:9000 就可以进去了。

 

但是我进去后发现了dsn是空的,怎么办?

a.我把docker 还原出厂设置

b. https://github.com/getsentry/onpremise

c. 修改config.yml 增加

如下操作(写自己的ip地址:system.url-prefix: 'http://192.168.1.1.0:9000'):

I fixed this when I set the following code at config.yml

###################
# System Settings #
###################

# If this file ever becomes compromised, it's important to regenerate your a new key
# Changing this value will result in all current sessions being invalidated.
# A new key can be generated with `$ sentry config generate-secret-key`
# system.secret-key: 'changeme'
system.url-prefix: 'http://my-sentry-host:9000'

Than

 docker-compose stop

docker-compose build # Build the services again after updating
docker-compose up -d # Recreate the services

d. 使用时用:{your-ip}:9000 进去

可以使用了。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值