交易链路流水号为空时打印错误日志,且不记录链路至skywalking

This commit is contained in:
dark 2021-03-18 22:56:35 +08:00
parent fe956b71f6
commit 7f84e44e94
2 changed files with 11 additions and 6 deletions

View File

@ -13,11 +13,11 @@ import java.lang.annotation.*;
*/ */
public @interface BizTracing { public @interface BizTracing {
String BIZ_ID = "bizId"; String BIZ_ID_TAG = "bizId";
String BIZ_TYPE = "bizType"; String BIZ_TYPE_TAG = "bizType";
String bizId() default "NULL_ID"; String bizId();
String bizType() default "NULL_TYPE"; String bizType();
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.dashboard.common.annotation; package cn.iocoder.dashboard.common.annotation;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.dashboard.util.sping.SpElUtil; import cn.iocoder.dashboard.util.sping.SpElUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.toolkit.trace.ActiveSpan; import org.apache.skywalking.apm.toolkit.trace.ActiveSpan;
@ -22,8 +23,12 @@ public class BizTracingAop {
public void tagBizInfo(ProceedingJoinPoint joinPoint, BizTracing bizTracing) { public void tagBizInfo(ProceedingJoinPoint joinPoint, BizTracing bizTracing) {
String bizId = SpElUtil.analysisSpEl(bizTracing.bizId(), joinPoint); String bizId = SpElUtil.analysisSpEl(bizTracing.bizId(), joinPoint);
String bizType = SpElUtil.analysisSpEl(bizTracing.bizType(), joinPoint); String bizType = SpElUtil.analysisSpEl(bizTracing.bizType(), joinPoint);
if (StrUtil.isBlankIfStr(bizId)) {
log.error("empty biz: bizId[{}], bizType[{}].", bizId, bizType);
return;
}
log.info("accept biz: bizId[{}], bizType[{}].", bizId, bizType); log.info("accept biz: bizId[{}], bizType[{}].", bizId, bizType);
ActiveSpan.tag(BizTracing.BIZ_ID, bizId); ActiveSpan.tag(BizTracing.BIZ_ID_TAG, bizId);
ActiveSpan.tag(BizTracing.BIZ_TYPE, bizType); ActiveSpan.tag(BizTracing.BIZ_TYPE_TAG, bizType);
} }
} }