* 修改部分不规范的代码。@ascrutae,请移除BaseInvokeMonitor中的spanData.isValidate()相关逻辑,以及RPCServerInvokeMonitor的invalidateAllSpanIfIsNotFirstSpan的相关逻辑。
* 同时调整generateSpanFromContextData,保证如果上下文中有,则以JVM上下文的traceId和LevelId为主,Identification注意保留。 * 修改RPCServerInvokeMonitor和RPCClientInvokeMonitor的方法名beforeInvoke
This commit is contained in:
parent
4bbda533c1
commit
9ec5a46425
|
|
@ -25,18 +25,18 @@ public abstract class BaseInvokeMonitor {
|
|||
|
||||
private static Set<String> exclusiveExceptionSet = null;
|
||||
|
||||
|
||||
protected ContextData beforeInvoke(Span spanData, Identification id) {
|
||||
if (Config.BuriedPoint.PRINTF) {
|
||||
logger.debug("TraceId:" + spanData.getTraceId() + "\tviewpointId:" + id.getViewPoint() + "\tParentLevelId:" + spanData.getParentLevel() + "\tLevelId:" + spanData
|
||||
.getLevelId());
|
||||
logger.debug("TraceId:" + spanData.getTraceId() + "\tviewpointId:" + id.getViewPoint() + "\tParentLevelId:"
|
||||
+ spanData.getParentLevel() + "\tLevelId:" + spanData.getLevelId());
|
||||
}
|
||||
|
||||
|
||||
if (!spanData.isValidate()) {
|
||||
// 根据SpanData生成RequestSpan,并保存
|
||||
ContextBuffer.save(RequestSpan.RequestSpanBuilder.
|
||||
newBuilder(spanData).callType(id.getCallType()).viewPoint(id.getViewPoint()).spanTypeDesc(id.getSpanTypeDesc()).build());
|
||||
newBuilder(spanData).callType(id.getCallType()).viewPoint(id.getViewPoint())
|
||||
.spanTypeDesc(id.getSpanTypeDesc()).build());
|
||||
}
|
||||
|
||||
// 将新创建的Context存放到ThreadLocal栈中。
|
||||
|
|
@ -46,10 +46,10 @@ public abstract class BaseInvokeMonitor {
|
|||
}
|
||||
|
||||
protected void afterInvoke() {
|
||||
afterInvoke(null);
|
||||
afterInvoke(null);
|
||||
}
|
||||
|
||||
protected void afterInvoke(String resultJson) {
|
||||
protected void afterInvoke(String invokeResult) {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return;
|
||||
|
|
@ -60,15 +60,11 @@ public abstract class BaseInvokeMonitor {
|
|||
return;
|
||||
}
|
||||
|
||||
// 追加Result JSon
|
||||
if (resultJson != null){
|
||||
spanData.appendParameter("Result", resultJson);
|
||||
}
|
||||
spanData.setInvokeResult(invokeResult);
|
||||
|
||||
if (Config.BuriedPoint.PRINTF) {
|
||||
logger.debug(
|
||||
"TraceId-ACK:" + spanData.getTraceId() + "\tParentLevelId:" + spanData.getParentLevel() + "\tLevelId:" + spanData
|
||||
.getLevelId() + "\tbusinessKey:" + spanData.getParameters());
|
||||
logger.debug("TraceId-ACK:" + spanData.getTraceId() + "\tParentLevelId:" + spanData.getParentLevel()
|
||||
+ "\tLevelId:" + spanData.getLevelId() + "\tbusinessKey:" + spanData.getParameters());
|
||||
}
|
||||
// 生成并保存到缓存
|
||||
ContextBuffer.save(new AckSpan(spanData));
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ public class LocalMethodInvokeMonitor extends BaseInvokeMonitor {
|
|||
super.afterInvoke();
|
||||
}
|
||||
|
||||
public void afterInvoke(String resultJsonStr){
|
||||
super.afterInvoke(resultJsonStr);
|
||||
public void afterInvoke(String invokeResult){
|
||||
super.afterInvoke(invokeResult);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class RPCClientInvokeMonitor extends BaseInvokeMonitor {
|
|||
private static Logger logger = LogManager
|
||||
.getLogger(RPCClientInvokeMonitor.class);
|
||||
|
||||
public ContextData traceBeforeInvoke(Identification id) {
|
||||
public ContextData beforeInvoke(Identification id) {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return new EmptyContextData();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class RPCServerInvokeMonitor extends BaseInvokeMonitor {
|
|||
private static Logger logger = LogManager
|
||||
.getLogger(RPCServerInvokeMonitor.class);
|
||||
|
||||
public void traceBeforeInvoke(ContextData context, Identification id) {
|
||||
public void beforeInvoke(ContextData context, Identification id) {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public class Identification {
|
|||
|
||||
public static class IdentificationBuilder {
|
||||
private Identification sendData;
|
||||
private int parameterIdx = 0;
|
||||
|
||||
IdentificationBuilder() {
|
||||
sendData = new Identification();
|
||||
|
|
@ -59,11 +60,18 @@ public class Identification {
|
|||
return this;
|
||||
}
|
||||
|
||||
public IdentificationBuilder appendParameter(String key, String value) {
|
||||
public IdentificationBuilder setParameter(String key, String value) {
|
||||
sendData.parameters.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IdentificationBuilder addParameter(String value){
|
||||
parameterIdx++;
|
||||
sendData.parameters.put("_" + parameterIdx, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public IdentificationBuilder businessKey(String businessKey) {
|
||||
sendData.businessKey = businessKey;
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import java.security.ProtectionDomain;
|
|||
|
||||
public class ClassTransformer implements ClassFileTransformer {
|
||||
|
||||
private Logger logger = LogManager.getLogger(ClassTransformer.class);
|
||||
private static Logger logger = LogManager.getLogger(ClassTransformer.class);
|
||||
|
||||
private String interceptorPackage;
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ public class ClassTransformer implements ClassFileTransformer {
|
|||
}
|
||||
return ctClass.toBytecode();
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to transform class" + className, e);
|
||||
logger.error("Failed to transform class " + className, e);
|
||||
return classfileBuffer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,17 @@ import com.ai.cloud.skywalking.protocol.common.CallType;
|
|||
import com.google.gson.Gson;
|
||||
|
||||
public class MethodInterceptor {
|
||||
public static IBuriedPointType METHOD_INVOKE_BURIEDPOINT = new IBuriedPointType() {
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "LOCAL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return CallType.SYNC;
|
||||
}
|
||||
};
|
||||
|
||||
public void before(Class originClass, Class[] parametersType, Object[] allArgument, Object superCall,
|
||||
String methodName) {
|
||||
|
|
@ -15,28 +25,19 @@ public class MethodInterceptor {
|
|||
Identification.IdentificationBuilder identificationBuilder = Identification.newBuilder();
|
||||
identificationBuilder.viewPoint(generateViewPoint(originClass, parametersType, methodName));
|
||||
appendingParameters(allArgument, identificationBuilder);
|
||||
identificationBuilder.spanType(new IBuriedPointType() {
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "LOCAL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return CallType.SYNC;
|
||||
}
|
||||
});
|
||||
identificationBuilder.spanType(METHOD_INVOKE_BURIEDPOINT);
|
||||
|
||||
localMethodInvokeMonitor.beforeInvoke(identificationBuilder.build());
|
||||
|
||||
}
|
||||
|
||||
private void appendingParameters(Object[] allArgument, Identification.IdentificationBuilder identificationBuilder) {
|
||||
Gson gson = new Gson();
|
||||
for (int i = 0; i < allArgument.length; i++) {
|
||||
try {
|
||||
identificationBuilder.appendParameter("P" + i, new Gson().toJson(allArgument[i]));
|
||||
identificationBuilder.addParameter(gson.toJson(allArgument[i]));
|
||||
} catch (Exception e) {
|
||||
identificationBuilder.appendParameter("P" + i, "Cannot convert parameter");
|
||||
identificationBuilder.addParameter("N/A");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -62,7 +63,7 @@ public class MethodInterceptor {
|
|||
try {
|
||||
resultJson = new Gson().toJson(result);
|
||||
} catch (Exception e) {
|
||||
resultJson = "Can not convert result";
|
||||
resultJson = "N/A";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class TimeTest {
|
|||
IdentificationBuilder builder = Identification
|
||||
.newBuilder()
|
||||
.viewPoint("1111");
|
||||
sender.traceBeforeInvoke(builder.build());
|
||||
sender.beforeInvoke(builder.build());
|
||||
sender.afterInvoke();
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
public class Span {
|
||||
private final static String INVOKE_RESULT_PARAMETER_KEY = "_ret";
|
||||
|
||||
private Logger logger = Logger.getLogger(Span.class.getName());
|
||||
/**
|
||||
* tid,调用链的全局唯一标识
|
||||
|
|
@ -229,4 +231,8 @@ public class Span {
|
|||
public void appendParameter(String key, String value) {
|
||||
this.parameters.put(key, value);
|
||||
}
|
||||
|
||||
public void setInvokeResult(String result){
|
||||
this.parameters.put(INVOKE_RESULT_PARAMETER_KEY, result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class SWDubboEnhanceFilter implements Filter {
|
|||
if (isConsumer) {
|
||||
RPCClientInvokeMonitor rpcClientInvokeMonitor = new RPCClientInvokeMonitor();
|
||||
|
||||
ContextData contextData = rpcClientInvokeMonitor.traceBeforeInvoke(createIdentification(invoker, invocation));
|
||||
ContextData contextData = rpcClientInvokeMonitor.beforeInvoke(createIdentification(invoker, invocation));
|
||||
String contextDataStr = contextData.toString();
|
||||
|
||||
//追加参数
|
||||
|
|
@ -78,7 +78,7 @@ public class SWDubboEnhanceFilter implements Filter {
|
|||
contextData = new ContextData(contextDataStr);
|
||||
}
|
||||
|
||||
rpcServerInvokeMonitor.traceBeforeInvoke(contextData, createIdentification(invoker, invocation));
|
||||
rpcServerInvokeMonitor.beforeInvoke(contextData, createIdentification(invoker, invocation));
|
||||
|
||||
try {
|
||||
//执行结果
|
||||
|
|
@ -138,4 +138,4 @@ public class SWDubboEnhanceFilter implements Filter {
|
|||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class HttpClientExecuteInterceptor implements IntanceMethodsAroundInterce
|
|||
.setHeader(
|
||||
TRACE_HEAD_NAME,
|
||||
"ContextData="
|
||||
+ rpcClientInvokeMonitor.traceBeforeInvoke(
|
||||
+ rpcClientInvokeMonitor.beforeInvoke(
|
||||
Identification
|
||||
.newBuilder()
|
||||
.viewPoint(
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class CallableStatementTracing {
|
|||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
rpcClientInvokeMonitor.traceBeforeInvoke(Identification
|
||||
rpcClientInvokeMonitor.beforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class ConnectionTracing {
|
|||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
rpcClientInvokeMonitor.traceBeforeInvoke(Identification
|
||||
rpcClientInvokeMonitor.beforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class PreparedStatementTracing {
|
|||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
rpcClientInvokeMonitor.traceBeforeInvoke(Identification
|
||||
rpcClientInvokeMonitor.beforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class StatementTracing {
|
|||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
rpcClientInvokeMonitor.traceBeforeInvoke(Identification
|
||||
rpcClientInvokeMonitor.beforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public abstract class JedisBaseInterceptor extends SimpleObjectFirstInvokeInterc
|
|||
builder.businessKey("key="
|
||||
+ interceptorContext.allArguments()[0]);
|
||||
}
|
||||
rpcClientInvokeMonitor.traceBeforeInvoke(builder.build());
|
||||
rpcClientInvokeMonitor.beforeInvoke(builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class SkyWalkingFilter implements Filter {
|
|||
}
|
||||
}
|
||||
rpcServerInvokeMonitor = new RPCServerInvokeMonitor();
|
||||
rpcServerInvokeMonitor.traceBeforeInvoke(contextData, generateIdentification(request));
|
||||
rpcServerInvokeMonitor.beforeInvoke(contextData, generateIdentification(request));
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
|
||||
|
|
|
|||
Loading…
Reference in New Issue