Commit f7289d7d authored by 杨锐's avatar 杨锐

新增sentry-starter

parent 4a6d0577
......@@ -5,7 +5,7 @@
<parent>
<artifactId>commons-parent</artifactId>
<groupId>cn.quantgroup</groupId>
<version>0.2.6</version>
<version>0.2.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>commons-parent</artifactId>
<groupId>cn.quantgroup</groupId>
<version>0.2.6</version>
<version>0.2.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>commons-parent</artifactId>
<groupId>cn.quantgroup</groupId>
<version>0.2.6</version>
<version>0.2.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>commons-parent</artifactId>
<groupId>cn.quantgroup</groupId>
<version>0.2.6</version>
<version>0.2.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>commons-parent</artifactId>
<groupId>cn.quantgroup</groupId>
<version>0.2.6</version>
<version>0.2.7</version>
</parent>
<groupId>cn.quantgroup</groupId>
<artifactId>enoch-agent-spring-boot-starter</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>commons-parent</artifactId>
<groupId>cn.quantgroup</groupId>
<version>0.2.6</version>
<version>0.2.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cn.quantgroup</groupId>
<artifactId>commons-parent</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<parent>
<groupId>org.springframework.boot</groupId>
......@@ -22,6 +22,7 @@
<module>idgenerator-spring-boot-starter</module>
<module>enoch-agent-spring-boot-starter</module>
<module>elastic-job-lite-spring-boot-starter</module>
<module>sentry-starter</module>
</modules>
<packaging>pom</packaging>
......@@ -35,7 +36,7 @@
<lombok.version>1.16.20</lombok.version>
<guava.version>23.0</guava.version>
<apollo.client.version>0.10.2</apollo.client.version>
<common.parent.version>0.2.6</common.parent.version>
<common.parent.version>0.2.7</common.parent.version>
</properties>
<dependencies>
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>commons-parent</artifactId>
<groupId>cn.quantgroup</groupId>
<version>0.2.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sentry-starter</artifactId>
<name>sentry-starter</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-spring</artifactId>
<version>1.6.3</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cn.quantgroup</groupId>
<artifactId>commons-spring</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
package cn.quantgroup.tech.sentry;
import io.sentry.Sentry;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* {@link HandlerExceptionResolver} implementation that will record any exception that a
* Spring {@link org.springframework.web.servlet.mvc.Controller} throws to Sentry. It then
* returns null, which will let the other (default or custom) exception resolvers handle
* the actual error.
*/
public class CustomSentryExceptionResolver implements HandlerExceptionResolver, Ordered {
@Override
public ModelAndView resolveException(HttpServletRequest request,
HttpServletResponse response,
Object handler,
Exception ex) {
if (ex instanceof NoSentryCaptureRuntimeException) {
return null;
}
Sentry.capture(ex);
// null = run other HandlerExceptionResolvers to actually handle the exception
return null;
}
@Override
public int getOrder() {
// ensure this resolver runs first so that all exceptions are reported
return Integer.MIN_VALUE;
}
}
\ No newline at end of file
package cn.quantgroup.tech.sentry;
public class NoSentryCaptureRuntimeException extends RuntimeException {
public NoSentryCaptureRuntimeException() {
}
public NoSentryCaptureRuntimeException(String message) {
super(message);
}
public NoSentryCaptureRuntimeException(String message, Throwable cause) {
super(message, cause);
}
public NoSentryCaptureRuntimeException(Throwable cause) {
super(cause);
}
public NoSentryCaptureRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
package cn.quantgroup.tech.sentry;
public class SentryCaptureRuntimeException extends RuntimeException {
public SentryCaptureRuntimeException() {
}
public SentryCaptureRuntimeException(String message) {
super(message);
}
public SentryCaptureRuntimeException(String message, Throwable cause) {
super(message, cause);
}
public SentryCaptureRuntimeException(Throwable cause) {
super(cause);
}
public SentryCaptureRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
package cn.quantgroup.tech.sentry;
import cn.quantgroup.tech.util.TechEnvironment;
import io.sentry.Sentry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
import javax.annotation.PostConstruct;
@Configuration
@ConditionalOnProperty(name = "dsn")
public class SentryConfig {
@Value("${dsn}")
private String dsn;
@Bean
public HandlerExceptionResolver sentryExceptionResolver() {
return new CustomSentryExceptionResolver();
}
@Bean
public ServletContextInitializer sentryServletContextInitializer() {
return new io.sentry.spring.SentryServletContextInitializer();
}
@PostConstruct
public void initSentry() {
if (TechEnvironment.isPro()) {
Sentry.init(dsn);
}
}
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.quantgroup.tech.sentry.SentryConfig
\ No newline at end of file
......@@ -5,7 +5,7 @@
<parent>
<artifactId>commons-parent</artifactId>
<groupId>cn.quantgroup</groupId>
<version>0.2.6</version>
<version>0.2.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment