✨ 提供 sentry-stater
This commit is contained in:
parent
d06e51ba21
commit
81fef80c51
25
common/mall-spring-boot-starter-sentry/pom.xml
Normal file
25
common/mall-spring-boot-starter-sentry/pom.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?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>common</artifactId>
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>mall-spring-boot-starter-sentry</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.sentry</groupId>
|
||||||
|
<artifactId>sentry-spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.sentry</groupId>
|
||||||
|
<artifactId>sentry-logback</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,38 @@
|
|||||||
|
package cn.iocoder.mall.sentry.config;
|
||||||
|
|
||||||
|
import cn.iocoder.mall.sentry.resolver.DoNothingExceptionResolver;
|
||||||
|
import io.sentry.spring.SentryExceptionResolver;
|
||||||
|
import io.sentry.spring.autoconfigure.SentryAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义的 Sentry 自动配置类
|
||||||
|
*
|
||||||
|
* @author Hccake 2020/8/6
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@ConditionalOnClass({HandlerExceptionResolver.class, SentryExceptionResolver.class})
|
||||||
|
@ConditionalOnWebApplication
|
||||||
|
@ConditionalOnProperty(name = "sentry.enabled", havingValue = "true", matchIfMissing = true)
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
public class CustomSentryAutoConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于覆盖原有的 SentryStarter 提供的 SentryExceptionResolver 操作
|
||||||
|
* 解决使用 log appender 形式推送错误信息与全局异常捕获导致重复推送的情况
|
||||||
|
*
|
||||||
|
* @return DoNothingExceptionResolver
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnClass(SentryAutoConfiguration.class)
|
||||||
|
@ConditionalOnMissingBean(SentryExceptionResolver.class)
|
||||||
|
public SentryExceptionResolver doNothingExceptionResolver() {
|
||||||
|
return new DoNothingExceptionResolver();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package cn.iocoder.mall.sentry.resolver;
|
||||||
|
|
||||||
|
import io.sentry.spring.SentryExceptionResolver;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认什么也不做的 SentryExceptionResolver
|
||||||
|
*
|
||||||
|
* @author Hccake 2020/8/6
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class DoNothingExceptionResolver extends SentryExceptionResolver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModelAndView resolveException(HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
Object handler,
|
||||||
|
Exception ex) {
|
||||||
|
// do nothing here
|
||||||
|
|
||||||
|
// null = run other HandlerExceptionResolvers to actually handle the exception
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrder() {
|
||||||
|
return Integer.MIN_VALUE;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
cn.iocoder.mall.sentry.config.CustomSentryAutoConfiguration
|
@ -19,6 +19,7 @@
|
|||||||
<module>mall-security-annotations</module>
|
<module>mall-security-annotations</module>
|
||||||
<module>mall-spring-boot-starter-security-admin</module>
|
<module>mall-spring-boot-starter-security-admin</module>
|
||||||
<module>mall-spring-boot-starter-security-user</module>
|
<module>mall-spring-boot-starter-security-user</module>
|
||||||
|
<module>mall-spring-boot-starter-sentry</module>
|
||||||
<module>mall-spring-boot-starter-mybatis</module>
|
<module>mall-spring-boot-starter-mybatis</module>
|
||||||
<module>mall-spring-boot-starter-dubbo</module>
|
<module>mall-spring-boot-starter-dubbo</module>
|
||||||
<module>mall-spring-boot-starter-system-error-code</module>
|
<module>mall-spring-boot-starter-system-error-code</module>
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
<!-- 监控相关 -->
|
<!-- 监控相关 -->
|
||||||
<skywalking.version>8.0.1</skywalking.version>
|
<skywalking.version>8.0.1</skywalking.version>
|
||||||
<spring-boot-admin-starter-client.version>2.2.2</spring-boot-admin-starter-client.version>
|
<spring-boot-admin-starter-client.version>2.2.2</spring-boot-admin-starter-client.version>
|
||||||
|
<sentry.version>1.7.30</sentry.version>
|
||||||
<!-- 工具类相关 -->
|
<!-- 工具类相关 -->
|
||||||
<fastjson.version>1.2.56</fastjson.version>
|
<fastjson.version>1.2.56</fastjson.version>
|
||||||
<hibernate-validator.version>6.0.16.Final</hibernate-validator.version>
|
<hibernate-validator.version>6.0.16.Final</hibernate-validator.version>
|
||||||
@ -275,6 +276,17 @@
|
|||||||
<version>${spring-boot-admin-starter-client.version}</version>
|
<version>${spring-boot-admin-starter-client.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.sentry</groupId>
|
||||||
|
<artifactId>sentry-logback</artifactId>
|
||||||
|
<version>${sentry.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.sentry</groupId>
|
||||||
|
<artifactId>sentry-spring-boot-starter</artifactId>
|
||||||
|
<version>${sentry.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Test 相关 -->
|
<!-- Test 相关 -->
|
||||||
|
|
||||||
<!--- 日志相关 -->
|
<!--- 日志相关 -->
|
||||||
@ -350,6 +362,7 @@
|
|||||||
<artifactId>hibernate-validator</artifactId>
|
<artifactId>hibernate-validator</artifactId>
|
||||||
<version>${hibernate-validator.version}</version>
|
<version>${hibernate-validator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user