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 的步骤:
-
Start a Redis container
$ docker run -d --name sentry-redis redis
-
Start a Postgres container
$ docker run -d --name sentry-postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=sentry postgres
-
Generate a new secret key to be shared by all
sentry
containers. This value will then be used as theSENTRY_SECRET_KEY
environment variable.$ docker run --rm sentry config generate-secret-key
-
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 -
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 进去
可以使用了。