1.较大规模修复api接口,加入关键业务字段,调用类型等信息
2.Spring方法埋点增加类型参数。类型为M,标记为本地方法 3.增加埋点类型描述说明文件(供参考)
This commit is contained in:
parent
443fecb321
commit
d9fec09599
|
|
@ -1,9 +1,10 @@
|
|||
package com.ai.cloud.skywalking.api;
|
||||
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
||||
public interface IBuriedPointReceiver extends IExceptionHandler {
|
||||
void afterReceived();
|
||||
|
||||
void beforeReceived(ContextData contextData);
|
||||
void beforeReceived(ContextData contextData, Identification id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import com.ai.cloud.skywalking.util.ExceptionHandleUtil;
|
|||
public class LocalBuriedPointSender implements IBuriedPointSender {
|
||||
|
||||
public ContextData beforeSend(Identification id) {
|
||||
Span spanData = ContextGenerator.generateContextFromThreadLocal(id);
|
||||
Span spanData = ContextGenerator.generateSpanFromThreadLocal(id);
|
||||
// 3.将新创建的Context存放到ThreadLocal栈中。
|
||||
Context.append(spanData);
|
||||
// 4 并将当前的Context返回回去
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.ai.cloud.skywalking.conf.Config;
|
|||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.context.Span;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.util.ContextGenerator;
|
||||
import com.ai.cloud.skywalking.util.ExceptionHandleUtil;
|
||||
|
||||
|
|
@ -20,8 +21,8 @@ public class RPCBuriedPointReceiver implements IBuriedPointReceiver {
|
|||
ContextBuffer.save(spanData);
|
||||
}
|
||||
|
||||
public void beforeReceived(ContextData context) {
|
||||
Span spanData = ContextGenerator.generateContextFromContextData(context);
|
||||
public void beforeReceived(ContextData context, Identification id) {
|
||||
Span spanData = ContextGenerator.generateSpanFromContextData(context, id);
|
||||
spanData.setReceiver(true);
|
||||
// 存放到上下文
|
||||
if (Config.BuriedPoint.PRINTF) {
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ import com.ai.cloud.skywalking.util.ExceptionHandleUtil;
|
|||
public class RPCBuriedPointSender implements IBuriedPointSender {
|
||||
|
||||
public ContextData beforeSend(Identification id) {
|
||||
Span spanData = ContextGenerator.generateContextFromThreadLocal(id);
|
||||
Span spanData = ContextGenerator.generateSpanFromThreadLocal(id);
|
||||
// 3.将新创建的Context存放到ThreadLocal栈中。
|
||||
Context.append(spanData);
|
||||
// 4 并将当前的Context返回回去
|
||||
return new ContextData(new Span(spanData.getTraceId(), spanData.getParentLevel()));
|
||||
return new ContextData(spanData);
|
||||
}
|
||||
|
||||
public void afterSend() {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import com.ai.cloud.skywalking.util.ExceptionHandleUtil;
|
|||
public class ThreadFactoryBuriedPointSender implements IBuriedPointSender {
|
||||
|
||||
public ContextData beforeSend(Identification id) {
|
||||
Span spanData = ContextGenerator.generateContextFromThreadLocal(id);
|
||||
Span spanData = ContextGenerator.generateSpanFromThreadLocal(id);
|
||||
// 3.将新创建的Context存放到ThreadLocal栈中。
|
||||
Context.append(spanData);
|
||||
// 4 并将当前的Context返回回去
|
||||
|
|
|
|||
|
|
@ -10,23 +10,16 @@ public class Span {
|
|||
private long startDate;
|
||||
private long cost;
|
||||
private String address;
|
||||
private byte statueCode = 0;
|
||||
private byte statusCode = 0;
|
||||
private String exceptionStack;
|
||||
private byte spanType;
|
||||
private char spanType;
|
||||
private boolean isReceiver = false;
|
||||
|
||||
public Span() {
|
||||
}
|
||||
private String businessKey;
|
||||
|
||||
public Span(String traceId) {
|
||||
this.traceId = traceId;
|
||||
}
|
||||
|
||||
public Span(String traceId, String parentLevel) {
|
||||
this.traceId = traceId;
|
||||
this.parentLevel = parentLevel;
|
||||
}
|
||||
|
||||
public String getProcessNo() {
|
||||
return processNo;
|
||||
}
|
||||
|
|
@ -97,15 +90,15 @@ public class Span {
|
|||
this.address = address;
|
||||
}
|
||||
|
||||
public byte getStatueCode() {
|
||||
return statueCode;
|
||||
}
|
||||
public byte getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatueCode(byte statueCode) {
|
||||
this.statueCode = statueCode;
|
||||
}
|
||||
public void setStatusCode(byte statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public String getExceptionStack() {
|
||||
public String getExceptionStack() {
|
||||
return exceptionStack;
|
||||
}
|
||||
|
||||
|
|
@ -113,11 +106,11 @@ public class Span {
|
|||
this.exceptionStack = exceptionStack;
|
||||
}
|
||||
|
||||
public byte getSpanType() {
|
||||
public char getSpanType() {
|
||||
return spanType;
|
||||
}
|
||||
|
||||
public void setSpanType(byte spanType) {
|
||||
public void setSpanType(char spanType) {
|
||||
this.spanType = spanType;
|
||||
}
|
||||
|
||||
|
|
@ -129,13 +122,21 @@ public class Span {
|
|||
isReceiver = receiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBusinessKey() {
|
||||
return businessKey;
|
||||
}
|
||||
|
||||
public void setBusinessKey(String businessKey) {
|
||||
this.businessKey = businessKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer stringBuffer = new StringBuffer(traceId + "-" + parentLevel + "-"
|
||||
+ levelId + "-" + viewPointId + "-" + startDate + "-" + cost +
|
||||
"-" + address +
|
||||
"-" + statueCode +
|
||||
"-" + processNo + "-" + spanType + "-" + isReceiver);
|
||||
"-" + statusCode +
|
||||
"-" + processNo + "-" + spanType + "-" + isReceiver + "-" + businessKey);
|
||||
|
||||
|
||||
if (!StringUtil.isEmpty(exceptionStack)) {
|
||||
|
|
|
|||
|
|
@ -6,34 +6,29 @@ public class ContextData {
|
|||
private String traceId;
|
||||
private String parentLevel;
|
||||
private long levelId;
|
||||
private char spanType;
|
||||
|
||||
public ContextData(Span span) {
|
||||
this.traceId = span.getTraceId();
|
||||
this.parentLevel = span.getParentLevel();
|
||||
this.levelId = span.getLevelId();
|
||||
this.spanType = span.getSpanType();
|
||||
}
|
||||
|
||||
public String getTraceId() {
|
||||
return traceId;
|
||||
}
|
||||
|
||||
public void setTraceId(String traceId) {
|
||||
this.traceId = traceId;
|
||||
}
|
||||
|
||||
public String getParentLevel() {
|
||||
return parentLevel;
|
||||
}
|
||||
|
||||
public void setParentLevel(String parentLevel) {
|
||||
this.parentLevel = parentLevel;
|
||||
}
|
||||
|
||||
public long getLevelId() {
|
||||
return levelId;
|
||||
}
|
||||
|
||||
public void setLevelId(long levelId) {
|
||||
this.levelId = levelId;
|
||||
}
|
||||
public char getSpanType() {
|
||||
return spanType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.ai.cloud.skywalking.model;
|
|||
public class Identification {
|
||||
private String viewPoint;
|
||||
private String businessKey;
|
||||
private char spanType;
|
||||
|
||||
public Identification() {
|
||||
//Non
|
||||
|
|
@ -15,6 +16,10 @@ public class Identification {
|
|||
public String getBusinessKey() {
|
||||
return businessKey;
|
||||
}
|
||||
|
||||
public char getSpanType(){
|
||||
return spanType;
|
||||
}
|
||||
|
||||
public static IdentificationBuilder newBuilder() {
|
||||
return new IdentificationBuilder();
|
||||
|
|
@ -40,6 +45,11 @@ public class Identification {
|
|||
sendData.businessKey = businessKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IdentificationBuilder spanType(char spanType) {
|
||||
sendData.spanType = spanType;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,9 @@ public final class ContextGenerator {
|
|||
* @param sendData 视点,业务数据等信息
|
||||
* @return
|
||||
*/
|
||||
public static Span generateContextFromThreadLocal(Identification sendData) {
|
||||
Span spanData = getContextFromThreadLocal();
|
||||
// 设置基本属性
|
||||
spanData.setStartDate(System.currentTimeMillis());
|
||||
spanData.setProcessNo(BuriedPointMachineUtil.getProcessNo());
|
||||
spanData.setAddress(BuriedPointMachineUtil.getHostName() + "/" + BuriedPointMachineUtil.getHostIp());
|
||||
spanData.setViewPointId(sendData.getViewPoint());
|
||||
public static Span generateSpanFromThreadLocal(Identification id) {
|
||||
Span spanData = getSpanFromThreadLocal();
|
||||
initNewSpanData(spanData, id);
|
||||
return spanData;
|
||||
}
|
||||
|
||||
|
|
@ -29,26 +25,33 @@ public final class ContextGenerator {
|
|||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static Span generateContextFromContextData(ContextData context) {
|
||||
public static Span generateSpanFromContextData(ContextData context, Identification id) {
|
||||
Span spanData;
|
||||
// 校验传入的参数是否为空,如果为空,则新创建一个
|
||||
if (context == null || StringUtil.isEmpty(context.getTraceId())) {
|
||||
// 不存在,新创建一个Context
|
||||
spanData = new Span(TraceIdGenerator.generate());
|
||||
// spanData.setLevelId(0L);
|
||||
} else {
|
||||
// 如果不为空,则将当前的Context存放到上下文
|
||||
spanData = new Span(context.getTraceId());
|
||||
spanData.setParentLevel(context.getParentLevel());
|
||||
}
|
||||
// 设置基本信息
|
||||
initNewSpanData(spanData, id);
|
||||
|
||||
return spanData;
|
||||
}
|
||||
|
||||
private static void initNewSpanData(Span spanData,Identification id){
|
||||
spanData.setSpanType(id.getSpanType());
|
||||
spanData.setViewPointId(id.getViewPoint());
|
||||
spanData.setBusinessKey(id.getBusinessKey());
|
||||
// 设置基本信息
|
||||
spanData.setStartDate(System.currentTimeMillis());
|
||||
spanData.setProcessNo(BuriedPointMachineUtil.getProcessNo());
|
||||
spanData.setAddress(BuriedPointMachineUtil.getHostName() + "/" + BuriedPointMachineUtil.getHostIp());
|
||||
return spanData;
|
||||
}
|
||||
|
||||
private static Span getContextFromThreadLocal() {
|
||||
private static Span getSpanFromThreadLocal() {
|
||||
Span span;
|
||||
// 1.获取Context,从ThreadLocal栈中获取中
|
||||
final Span parentSpan = Context.getLastSpan();
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public final class ExceptionHandleUtil {
|
|||
Span spanData = Context.getLastSpan();
|
||||
// 设置错误信息
|
||||
byte errorCode = 1;
|
||||
spanData.setStatueCode(errorCode);
|
||||
spanData.setStatusCode(errorCode);
|
||||
spanData.setExceptionStack(extractExceptionStackMessage(e));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
|
|||
builder = builder.delete(builder.length() - 1, builder.length());
|
||||
}
|
||||
builder.append(")");
|
||||
builder.append("\").build());");
|
||||
builder.append("\").spanType('M').build());");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
#默认埋点类型对照信息
|
||||
M:本地JAVA方法
|
||||
J:JDBC
|
||||
W:web servlet调用
|
||||
D:dubbo/dubbox调用
|
||||
Loading…
Reference in New Issue