项目结构调整 x 22 : 优化 trace;将 sms 的集成测试,移到 biz-sms 下
parent
ab4e6d0819
commit
99feec4535
|
@ -40,10 +40,6 @@
|
||||||
| 🚀 | 错误码管理 | 系统所有错误码的管理,可在线修改错误提示,无需重启服务 |
|
| 🚀 | 错误码管理 | 系统所有错误码的管理,可在线修改错误提示,无需重启服务 |
|
||||||
| | 通知公告 | 系统通知公告信息发布维护 |
|
| | 通知公告 | 系统通知公告信息发布维护 |
|
||||||
|
|
||||||
计划新增功能:
|
|
||||||
* 邮件
|
|
||||||
* 钉钉、飞书等通知
|
|
||||||
|
|
||||||
### 基础设施
|
### 基础设施
|
||||||
|
|
||||||
| | 功能 | 描述 |
|
| | 功能 | 描述 |
|
||||||
|
@ -63,9 +59,6 @@
|
||||||
| 🚀 | 日志服务 | 轻量级日志中心,查看远程服务器的日志 |
|
| 🚀 | 日志服务 | 轻量级日志中心,查看远程服务器的日志 |
|
||||||
| 🚀 | 单元测试 |基于 JUnit + Mockito 实现单元测试,保证功能的正确性、代码的质量等 |
|
| 🚀 | 单元测试 |基于 JUnit + Mockito 实现单元测试,保证功能的正确性、代码的质量等 |
|
||||||
|
|
||||||
计划新增:
|
|
||||||
* 工作流
|
|
||||||
|
|
||||||
### 研发工具
|
### 研发工具
|
||||||
|
|
||||||
| | 功能 | 描述 |
|
| | 功能 | 描述 |
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
package cn.iocoder.yudao.adminserver.framework.sms.core.client;
|
|
|
@ -27,6 +27,12 @@
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 监控相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.opentracing</groupId>
|
||||||
|
<artifactId>opentracing-util</artifactId> <!-- aliyun 短信需要,进行链路追踪 -->
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Test 测试相关 -->
|
<!-- Test 测试相关 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.iocoder.boot</groupId>
|
<groupId>cn.iocoder.boot</groupId>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package cn.iocoder.yudao.adminserver.framework.sms.core.client.impl.aliyun;
|
package cn.iocoder.yudao.framework.sms.core.client.impl.aliyun;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||||
import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult;
|
import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult;
|
|
@ -1,4 +1,4 @@
|
||||||
package cn.iocoder.yudao.adminserver.framework.sms.core.client.impl.debug;
|
package cn.iocoder.yudao.framework.sms.core.client.impl.debug;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||||
import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult;
|
import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult;
|
|
@ -1,4 +1,4 @@
|
||||||
package cn.iocoder.yudao.adminserver.framework.sms.core.client.impl.yunpian;
|
package cn.iocoder.yudao.framework.sms.core.client.impl.yunpian;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||||
import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult;
|
import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult;
|
|
@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.tracer.core.aop.BizTraceAspect;
|
||||||
import cn.iocoder.yudao.framework.tracer.core.filter.TraceFilter;
|
import cn.iocoder.yudao.framework.tracer.core.filter.TraceFilter;
|
||||||
import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
|
import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
|
||||||
import io.opentracing.Tracer;
|
import io.opentracing.Tracer;
|
||||||
|
import io.opentracing.util.GlobalTracer;
|
||||||
import org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer;
|
import org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
@ -25,21 +26,22 @@ import org.springframework.context.annotation.Configuration;
|
||||||
public class YudaoTracerAutoConfiguration {
|
public class YudaoTracerAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public TracerProperties bizTracerProperties() {
|
public TracerProperties bizTracerProperties() {
|
||||||
return new TracerProperties();
|
return new TracerProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public BizTraceAspect bizTracingAop() {
|
public BizTraceAspect bizTracingAop() {
|
||||||
return new BizTraceAspect(tracer());
|
return new BizTraceAspect(tracer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public Tracer tracer() {
|
public Tracer tracer() {
|
||||||
return new SkywalkingTracer();
|
// 创建 SkywalkingTracer 对象
|
||||||
|
SkywalkingTracer tracer = new SkywalkingTracer();
|
||||||
|
// 设置为 GlobalTracer 的追踪器
|
||||||
|
GlobalTracer.register(tracer);
|
||||||
|
return tracer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,15 +4,16 @@ import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.tracer.core.annotation.BizTrace;
|
import cn.iocoder.yudao.framework.tracer.core.annotation.BizTrace;
|
||||||
import cn.iocoder.yudao.framework.common.util.sping.SpringExpressionUtils;
|
import cn.iocoder.yudao.framework.common.util.sping.SpringExpressionUtils;
|
||||||
|
import cn.iocoder.yudao.framework.tracer.core.util.TracerFrameworkUtils;
|
||||||
import io.opentracing.Span;
|
import io.opentracing.Span;
|
||||||
import io.opentracing.Tracer;
|
import io.opentracing.Tracer;
|
||||||
|
import io.opentracing.tag.Tags;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
@ -35,10 +36,15 @@ public class BizTraceAspect {
|
||||||
public Object around(ProceedingJoinPoint joinPoint, BizTrace trace) throws Throwable {
|
public Object around(ProceedingJoinPoint joinPoint, BizTrace trace) throws Throwable {
|
||||||
// 创建 span
|
// 创建 span
|
||||||
String operationName = getOperationName(joinPoint, trace);
|
String operationName = getOperationName(joinPoint, trace);
|
||||||
Span span = tracer.buildSpan(operationName).start();
|
Span span = tracer.buildSpan(operationName)
|
||||||
|
.withTag(Tags.COMPONENT.getKey(), "biz")
|
||||||
|
.startManual();
|
||||||
try {
|
try {
|
||||||
// 执行原有方法
|
// 执行原有方法
|
||||||
return joinPoint.proceed();
|
return joinPoint.proceed();
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
TracerFrameworkUtils.onError(throwable, span);
|
||||||
|
throw throwable;
|
||||||
} finally {
|
} finally {
|
||||||
// 设置 Span 的 biz 属性
|
// 设置 Span 的 biz 属性
|
||||||
setBizTag(span, joinPoint, trace);
|
setBizTag(span, joinPoint, trace);
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package cn.iocoder.yudao.framework.tracer.core.util;
|
||||||
|
|
||||||
|
import io.opentracing.Span;
|
||||||
|
import io.opentracing.tag.Tags;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链路追踪 Util
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public class TracerFrameworkUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将异常记录到 Span 中,参考自 com.aliyuncs.utils.TraceUtils
|
||||||
|
*
|
||||||
|
* @param throwable 异常
|
||||||
|
* @param span Span
|
||||||
|
*/
|
||||||
|
public static void onError(Throwable throwable, Span span) {
|
||||||
|
Tags.ERROR.set(span, Boolean.TRUE);
|
||||||
|
if (throwable != null) {
|
||||||
|
span.log(errorLogs(throwable));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, Object> errorLogs(Throwable throwable) {
|
||||||
|
Map<String, Object> errorLogs = new HashMap<String, Object>(10);
|
||||||
|
errorLogs.put("event", Tags.ERROR.getKey());
|
||||||
|
errorLogs.put("error.object", throwable);
|
||||||
|
errorLogs.put("error.kind", throwable.getClass().getName());
|
||||||
|
String message = throwable.getCause() != null ? throwable.getCause().getMessage() : throwable.getMessage();
|
||||||
|
if (message != null) {
|
||||||
|
errorLogs.put("message", message);
|
||||||
|
}
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
throwable.printStackTrace(new PrintWriter(sw));
|
||||||
|
errorLogs.put("stack", sw.toString());
|
||||||
|
return errorLogs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue