项目结构调整 x 22 : 优化 trace;将 sms 的集成测试,移到 biz-sms 下

This commit is contained in:
YunaiV 2021-05-03 11:52:53 +08:00
parent ab4e6d0819
commit 99feec4535
10 changed files with 88 additions and 17 deletions

View File

@ -40,10 +40,6 @@
| 🚀 | 错误码管理 | 系统所有错误码的管理,可在线修改错误提示,无需重启服务 |
| | 通知公告 | 系统通知公告信息发布维护 |
计划新增功能:
* 邮件
* 钉钉、飞书等通知
### 基础设施
| | 功能 | 描述 |
@ -63,9 +59,6 @@
| 🚀 | 日志服务 | 轻量级日志中心,查看远程服务器的日志 |
| 🚀 | 单元测试 |基于 JUnit + Mockito 实现单元测试,保证功能的正确性、代码的质量等 |
计划新增:
* 工作流
### 研发工具
| | 功能 | 描述 |

View File

@ -1 +0,0 @@
package cn.iocoder.yudao.adminserver.framework.sms.core.client;

View File

@ -27,6 +27,12 @@
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- 监控相关 -->
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-util</artifactId> <!-- aliyun 短信需要,进行链路追踪 -->
</dependency>
<!-- Test 测试相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>

View File

@ -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.sms.core.client.SmsCommonResult;

View File

@ -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.sms.core.client.SmsCommonResult;

View File

@ -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.sms.core.client.SmsCommonResult;

View File

@ -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.common.enums.WebFilterOrderEnum;
import io.opentracing.Tracer;
import io.opentracing.util.GlobalTracer;
import org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@ -25,21 +26,22 @@ import org.springframework.context.annotation.Configuration;
public class YudaoTracerAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public TracerProperties bizTracerProperties() {
return new TracerProperties();
}
@Bean
@ConditionalOnMissingBean
public BizTraceAspect bizTracingAop() {
return new BizTraceAspect(tracer());
}
@Bean
@ConditionalOnMissingBean
public Tracer tracer() {
return new SkywalkingTracer();
// 创建 SkywalkingTracer 对象
SkywalkingTracer tracer = new SkywalkingTracer();
// 设置为 GlobalTracer 的追踪器
GlobalTracer.register(tracer);
return tracer;
}
/**

View File

@ -4,15 +4,16 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.tracer.core.annotation.BizTrace;
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.Tracer;
import io.opentracing.tag.Tags;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import javax.annotation.Resource;
import java.util.Map;
import static java.util.Arrays.asList;
@ -35,10 +36,15 @@ public class BizTraceAspect {
public Object around(ProceedingJoinPoint joinPoint, BizTrace trace) throws Throwable {
// 创建 span
String operationName = getOperationName(joinPoint, trace);
Span span = tracer.buildSpan(operationName).start();
Span span = tracer.buildSpan(operationName)
.withTag(Tags.COMPONENT.getKey(), "biz")
.startManual();
try {
// 执行原有方法
return joinPoint.proceed();
} catch (Throwable throwable) {
TracerFrameworkUtils.onError(throwable, span);
throw throwable;
} finally {
// 设置 Span biz 属性
setBizTag(span, joinPoint, trace);

View File

@ -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;
}
}

19
更新日志.md Normal file
View File

@ -0,0 +1,19 @@
## 计划中
* 邮件
* 钉钉、飞书等通知
* 工作流
* 支付
* 三方平台接入
## [v1.0.0] 2021.05.03
### ⭐ New Features
### ⚡️ Optimization
### 🐞 Bug Fixes
### 📔 Documentation
### 🔨 Dependency Upgrades