提交 c3352821 作者: 方治民

feat: 新增 sentry, springboot admin client & actuator 相关配置及测试用例

上级 9103e6eb
apply plugin: "com.gorylenko.gradle-git-properties"
group = 'com.yiring'
version = '0.0.1-SNAPSHOT'
......@@ -12,11 +14,20 @@ bootJar {
enabled = true
}
springBoot {
buildInfo()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
// Spring Boot Admin Client
implementation 'de.codecentric:spring-boot-admin-starter-client'
// Sentry
implementation "io.sentry:sentry-spring-boot-starter-jakarta"
// 💬 Mock/Test Env
runtimeOnly 'com.h2database:h2'
// 💬 Prod/Dev Env
......
/* (C) 2024 YiRing, Inc. */
package com.yiring.app.config;
import org.springframework.boot.actuate.audit.InMemoryAuditEventRepository;
import org.springframework.boot.actuate.web.exchanges.HttpExchangeRepository;
import org.springframework.boot.actuate.web.exchanges.InMemoryHttpExchangeRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Jim
*/
@Configuration
public class ActuatorConfiguration {
@Bean
public HttpExchangeRepository httpExchangeRepository() {
InMemoryHttpExchangeRepository repository = new InMemoryHttpExchangeRepository();
repository.setCapacity(100);
return repository;
}
@Bean
public InMemoryAuditEventRepository repository() {
return new InMemoryAuditEventRepository();
}
}
......@@ -4,6 +4,7 @@ package com.yiring.app.config;
import com.yiring.common.core.I18n;
import com.yiring.common.core.Result;
import com.yiring.common.core.Status;
import io.sentry.Sentry;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
......@@ -35,7 +36,11 @@ public class GlobalExceptionHandler {
@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
public Result<String> defaultErrorHandler(Exception e) {
log.error(e.getMessage(), e);
return Result.no(Status.INTERNAL_SERVER_ERROR, e);
try {
log.error(e.getMessage(), e);
return Result.no(Status.INTERNAL_SERVER_ERROR, e);
} finally {
Sentry.captureException(e);
}
}
}
......@@ -15,7 +15,6 @@ import com.yiring.common.annotation.RateLimiter;
import com.yiring.common.core.I18n;
import com.yiring.common.core.Result;
import com.yiring.common.core.Status;
import com.yiring.common.exception.BusinessException;
import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.service.FileManageService;
......@@ -75,7 +74,8 @@ public class ExampleController {
@Operation(summary = "测试失败")
@GetMapping("fail")
public Result<String> fail() {
throw BusinessException.i18n("Code.1");
// throw BusinessException.i18n("Code.1");
throw new RuntimeException("test fail");
}
@SaCheckLogin
......
......@@ -74,4 +74,6 @@ logging:
org.hibernate.type.descriptor.sql.BasicBinder: trace
# request log
com.yiring.common.aspect.RequestAspect: info
file:
path: ./logs
# ----------------------------------------------
server:
address: 127.0.0.1
# Sentry
sentry:
# https://sentry.yiring.com
# basic-api
dsn: https://fec8292ec19b34fd541c75f907fcec9b@sentry.yiring.com/2
traces-sample-rate: 1.0
debug: false
# Spring Boot Admin Client Config
spring:
boot:
admin:
client:
url: http://127.0.0.1:18891
username: admin
password: spa.developer@Yiring.com
# Spring Boot Actuator
management:
server:
port: 8182
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
mappings:
enabled: false
info:
build:
enabled: true
git:
enabled: true
env:
enabled: true
java:
enabled: true
os:
enabled: true
# 通过 gradle processResources 注入构建版本号
app:
version: ${version}
server:
address: 127.0.0.1
port: 8081
servlet:
context-path: /api
......@@ -17,7 +17,7 @@ spring:
max-file-size: 1024MB
max-request-size: 1048MB
profiles:
include: auth, conf-patch
include: auth, conf-patch, monitor
active: dev-postgresql
# DEBUG
......
......@@ -2,12 +2,14 @@ plugins {
id 'java'
id 'java-library'
// https://start.spring.io
id 'org.springframework.boot' version '3.2.2'
id 'org.springframework.boot' version '3.2.3'
id 'org.graalvm.buildtools.native' version '0.9.28'
// https://plugins.gradle.org/plugin/io.spring.dependency-management
id 'io.spring.dependency-management' version '1.1.4'
// https://plugins.gradle.org/plugin/com.diffplug.spotless
id "com.diffplug.spotless" version "6.25.0"
// https://plugins.gradle.org/plugin/com.gorylenko.gradle-git-properties
id "com.gorylenko.gradle-git-properties" version "2.4.1"
}
ext {
......@@ -29,6 +31,10 @@ ext {
// FIXED: 版本号不兼容,暂时去掉
springBootAdminVersion = '3.2.1'
// Sentry
// https://central.sonatype.com/artifact/io.sentry/sentry-spring-boot-starter-jakarta
sentryVersion = '7.4.0'
// Dependencies
// https://central.sonatype.com/artifact/com.github.xiaoymin/knife4j-openapi3-jakarta-spring-boot-starter
knife4jOpen3Version = '4.5.0'
......@@ -37,7 +43,7 @@ ext {
// https://central.sonatype.com/artifact/cn.dev33/sa-token-spring-boot3-starter
saTokenVersion = '1.37.0'
// https://central.sonatype.com/artifact/cn.hutool/hutool-core
hutoolVersion = '5.8.25'
hutoolVersion = '5.8.26'
// https://central.sonatype.com/artifact/com.alibaba.fastjson2/fastjson2
fastJsonVersion = '2.0.46'
// https://central.sonatype.com/artifact/com.xuxueli/xxl-job-core
......@@ -45,11 +51,11 @@ ext {
// https://central.sonatype.com/artifact/com.squareup.okhttp3/okhttp
okhttpVersion = '4.12.0'
// https://central.sonatype.com/artifact/io.minio/minio
minioVersion = '8.5.7'
minioVersion = '8.5.8'
// https://central.sonatype.com/artifact/io.hypersistence/hypersistence-utils-hibernate-63
hibernateTypesVersion = '3.7.1'
hibernateTypesVersion = '3.7.3'
// https://central.sonatype.com/artifact/org.hibernate.orm/hibernate-spatial
hibernateSpatialVersion = '6.4.2.Final'
hibernateSpatialVersion = '6.4.4.Final'
// https://central.sonatype.com/artifact/org.locationtech.jts/jts-core
jtsVersion = '1.19.0'
// https://central.sonatype.com/artifact/com.github.liaochong/myexcel
......@@ -68,8 +74,8 @@ allprojects {
mavenLocal()
// Nexus
// maven { url 'http://10.111.102.83:8081/repository/aliyun-maven/' }
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://mirrors.cloud.tencent.com/nexus/repository/maven-public/' }
maven { url 'https://maven.aliyun.com/repository/public' }
mavenCentral()
}
......@@ -101,6 +107,7 @@ subprojects {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "de.codecentric:spring-boot-admin-dependencies:${springBootAdminVersion}"
mavenBom "io.sentry:sentry-bom:${sentryVersion}"
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论