Commit 99feec45356e3273b71a0a49573251b723fda147
1 parent
ab4e6d08
项目结构调整 x 22 : 优化 trace;将 sms 的集成测试,移到 biz-sms 下
Showing
10 changed files
with
88 additions
and
17 deletions
README.md
| ... | ... | @@ -40,10 +40,6 @@ |
| 40 | 40 | | 🚀 | 错误码管理 | 系统所有错误码的管理,可在线修改错误提示,无需重启服务 | |
| 41 | 41 | | | 通知公告 | 系统通知公告信息发布维护 | |
| 42 | 42 | |
| 43 | -计划新增功能: | |
| 44 | -* 邮件 | |
| 45 | -* 钉钉、飞书等通知 | |
| 46 | - | |
| 47 | 43 | ### 基础设施 |
| 48 | 44 | |
| 49 | 45 | | | 功能 | 描述 | |
| ... | ... | @@ -63,9 +59,6 @@ |
| 63 | 59 | | 🚀 | 日志服务 | 轻量级日志中心,查看远程服务器的日志 | |
| 64 | 60 | | 🚀 | 单元测试 |基于 JUnit + Mockito 实现单元测试,保证功能的正确性、代码的质量等 | |
| 65 | 61 | |
| 66 | -计划新增: | |
| 67 | -* 工作流 | |
| 68 | - | |
| 69 | 62 | ### 研发工具 |
| 70 | 63 | |
| 71 | 64 | | | 功能 | 描述 | | ... | ... |
yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/framework/sms/core/client/package-info.java deleted
| 1 | -package cn.iocoder.yudao.adminserver.framework.sms.core.client; |
yudao-framework/yudao-spring-boot-starter-biz-sms/pom.xml
| ... | ... | @@ -27,6 +27,12 @@ |
| 27 | 27 | <artifactId>spring-boot-starter</artifactId> |
| 28 | 28 | </dependency> |
| 29 | 29 | |
| 30 | + <!-- 监控相关 --> | |
| 31 | + <dependency> | |
| 32 | + <groupId>io.opentracing</groupId> | |
| 33 | + <artifactId>opentracing-util</artifactId> <!-- aliyun 短信需要,进行链路追踪 --> | |
| 34 | + </dependency> | |
| 35 | + | |
| 30 | 36 | <!-- Test 测试相关 --> |
| 31 | 37 | <dependency> |
| 32 | 38 | <groupId>cn.iocoder.boot</groupId> | ... | ... |
yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/framework/sms/core/client/impl/aliyun/AliyunSmsClientIntegrationTest.java renamed to yudao-framework/yudao-spring-boot-starter-biz-sms/src/test-integration/java/cn/iocoder/yudao/framework/sms/core/client/impl/aliyun/AliyunSmsClientIntegrationTest.java
yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/framework/sms/core/client/impl/debug/DebugDingTalkSmsClientIntegrationTest.java renamed to yudao-framework/yudao-spring-boot-starter-biz-sms/src/test-integration/java/cn/iocoder/yudao/framework/sms/core/client/impl/debug/DebugDingTalkSmsClientIntegrationTest.java
yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/framework/sms/core/client/impl/yunpian/YunpianSmsClientIntegrationTest.java renamed to yudao-framework/yudao-spring-boot-starter-biz-sms/src/test-integration/java/cn/iocoder/yudao/framework/sms/core/client/impl/yunpian/YunpianSmsClientIntegrationTest.java
yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/config/YudaoTracerAutoConfiguration.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.tracer.core.aop.BizTraceAspect; |
| 4 | 4 | import cn.iocoder.yudao.framework.tracer.core.filter.TraceFilter; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; |
| 6 | 6 | import io.opentracing.Tracer; |
| 7 | +import io.opentracing.util.GlobalTracer; | |
| 7 | 8 | import org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer; |
| 8 | 9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
| 9 | 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
| ... | ... | @@ -25,21 +26,22 @@ import org.springframework.context.annotation.Configuration; |
| 25 | 26 | public class YudaoTracerAutoConfiguration { |
| 26 | 27 | |
| 27 | 28 | @Bean |
| 28 | - @ConditionalOnMissingBean | |
| 29 | 29 | public TracerProperties bizTracerProperties() { |
| 30 | 30 | return new TracerProperties(); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | @Bean |
| 34 | - @ConditionalOnMissingBean | |
| 35 | 34 | public BizTraceAspect bizTracingAop() { |
| 36 | 35 | return new BizTraceAspect(tracer()); |
| 37 | 36 | } |
| 38 | 37 | |
| 39 | 38 | @Bean |
| 40 | - @ConditionalOnMissingBean | |
| 41 | 39 | public Tracer tracer() { |
| 42 | - return new SkywalkingTracer(); | |
| 40 | + // 创建 SkywalkingTracer 对象 | |
| 41 | + SkywalkingTracer tracer = new SkywalkingTracer(); | |
| 42 | + // 设置为 GlobalTracer 的追踪器 | |
| 43 | + GlobalTracer.register(tracer); | |
| 44 | + return tracer; | |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | /** | ... | ... |
yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/core/aop/BizTraceAspect.java
| ... | ... | @@ -4,15 +4,16 @@ import cn.hutool.core.map.MapUtil; |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.tracer.core.annotation.BizTrace; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.sping.SpringExpressionUtils; |
| 7 | +import cn.iocoder.yudao.framework.tracer.core.util.TracerFrameworkUtils; | |
| 7 | 8 | import io.opentracing.Span; |
| 8 | 9 | import io.opentracing.Tracer; |
| 10 | +import io.opentracing.tag.Tags; | |
| 9 | 11 | import lombok.AllArgsConstructor; |
| 10 | 12 | import lombok.extern.slf4j.Slf4j; |
| 11 | 13 | import org.aspectj.lang.ProceedingJoinPoint; |
| 12 | 14 | import org.aspectj.lang.annotation.Around; |
| 13 | 15 | import org.aspectj.lang.annotation.Aspect; |
| 14 | 16 | |
| 15 | -import javax.annotation.Resource; | |
| 16 | 17 | import java.util.Map; |
| 17 | 18 | |
| 18 | 19 | import static java.util.Arrays.asList; |
| ... | ... | @@ -35,10 +36,15 @@ public class BizTraceAspect { |
| 35 | 36 | public Object around(ProceedingJoinPoint joinPoint, BizTrace trace) throws Throwable { |
| 36 | 37 | // 创建 span |
| 37 | 38 | String operationName = getOperationName(joinPoint, trace); |
| 38 | - Span span = tracer.buildSpan(operationName).start(); | |
| 39 | + Span span = tracer.buildSpan(operationName) | |
| 40 | + .withTag(Tags.COMPONENT.getKey(), "biz") | |
| 41 | + .startManual(); | |
| 39 | 42 | try { |
| 40 | 43 | // 执行原有方法 |
| 41 | 44 | return joinPoint.proceed(); |
| 45 | + } catch (Throwable throwable) { | |
| 46 | + TracerFrameworkUtils.onError(throwable, span); | |
| 47 | + throw throwable; | |
| 42 | 48 | } finally { |
| 43 | 49 | // 设置 Span 的 biz 属性 |
| 44 | 50 | setBizTag(span, joinPoint, trace); | ... | ... |
yudao-framework/yudao-spring-boot-starter-monitor/src/main/java/cn/iocoder/yudao/framework/tracer/core/util/TracerFrameworkUtils.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.tracer.core.util; | |
| 2 | + | |
| 3 | +import io.opentracing.Span; | |
| 4 | +import io.opentracing.tag.Tags; | |
| 5 | + | |
| 6 | +import java.io.PrintWriter; | |
| 7 | +import java.io.StringWriter; | |
| 8 | +import java.util.HashMap; | |
| 9 | +import java.util.Map; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * 链路追踪 Util | |
| 13 | + * | |
| 14 | + * @author 芋道源码 | |
| 15 | + */ | |
| 16 | +public class TracerFrameworkUtils { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 将异常记录到 Span 中,参考自 com.aliyuncs.utils.TraceUtils | |
| 20 | + * | |
| 21 | + * @param throwable 异常 | |
| 22 | + * @param span Span | |
| 23 | + */ | |
| 24 | + public static void onError(Throwable throwable, Span span) { | |
| 25 | + Tags.ERROR.set(span, Boolean.TRUE); | |
| 26 | + if (throwable != null) { | |
| 27 | + span.log(errorLogs(throwable)); | |
| 28 | + } | |
| 29 | + } | |
| 30 | + | |
| 31 | + private static Map<String, Object> errorLogs(Throwable throwable) { | |
| 32 | + Map<String, Object> errorLogs = new HashMap<String, Object>(10); | |
| 33 | + errorLogs.put("event", Tags.ERROR.getKey()); | |
| 34 | + errorLogs.put("error.object", throwable); | |
| 35 | + errorLogs.put("error.kind", throwable.getClass().getName()); | |
| 36 | + String message = throwable.getCause() != null ? throwable.getCause().getMessage() : throwable.getMessage(); | |
| 37 | + if (message != null) { | |
| 38 | + errorLogs.put("message", message); | |
| 39 | + } | |
| 40 | + StringWriter sw = new StringWriter(); | |
| 41 | + throwable.printStackTrace(new PrintWriter(sw)); | |
| 42 | + errorLogs.put("stack", sw.toString()); | |
| 43 | + return errorLogs; | |
| 44 | + } | |
| 45 | + | |
| 46 | +} | ... | ... |