1. LocalMethodInvokeMonitor重载afterInvoke,支持传入返回值. 2. 修复部分问题

This commit is contained in:
ascrutae 2016-07-21 18:53:25 +08:00
parent f9fe2d4d18
commit 4bbda533c1
7 changed files with 41 additions and 9 deletions

View File

@ -11,8 +11,10 @@ public class SkywalkingAgent {
public static void premain(String agentArgs, Instrumentation inst) {
ConfigInitializer.initialize();
if (Config.SkyWalking.ALL_METHOD_MONITOR){
inst.addTransformer(new ClassTransformer());
if (Config.SkyWalking.ALL_METHOD_MONITOR) {
String interceptorPackage = System.getProperty("interceptor.package", "");
inst.addTransformer(new ClassTransformer(interceptorPackage));
}
PluginBootstrap bootstrap = new PluginBootstrap();

View File

@ -46,6 +46,10 @@ public abstract class BaseInvokeMonitor {
}
protected void afterInvoke() {
afterInvoke(null);
}
protected void afterInvoke(String resultJson) {
try {
if (!AuthDesc.isAuth())
return;
@ -56,6 +60,11 @@ public abstract class BaseInvokeMonitor {
return;
}
// 追加Result JSon
if (resultJson != null){
spanData.appendParameter("Result", resultJson);
}
if (Config.BuriedPoint.PRINTF) {
logger.debug(
"TraceId-ACK:" + spanData.getTraceId() + "\tParentLevelId:" + spanData.getParentLevel() + "\tLevelId:" + spanData

View File

@ -32,6 +32,10 @@ public class LocalMethodInvokeMonitor extends BaseInvokeMonitor {
super.afterInvoke();
}
public void afterInvoke(String resultJsonStr){
super.afterInvoke(resultJsonStr);
}
public void occurException(Throwable th){
super.occurException(th);

View File

@ -15,9 +15,15 @@ public class ClassTransformer implements ClassFileTransformer {
private Logger logger = LogManager.getLogger(ClassTransformer.class);
private String interceptorPackage;
public ClassTransformer(String interceptorPackage){
this.interceptorPackage = interceptorPackage;
}
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
String interceptorPackage = System.getProperty("interceptor.package", "");
if (interceptorPackage == null || interceptorPackage.length() == 0) {
return classfileBuffer;
}

View File

@ -9,7 +9,8 @@ import com.google.gson.Gson;
public class MethodInterceptor {
public void before(Class originClass, Class[] parametersType, Object[] allArgument, Object superCall, String methodName) {
public void before(Class originClass, Class[] parametersType, Object[] allArgument, Object superCall,
String methodName) {
LocalMethodInvokeMonitor localMethodInvokeMonitor = new LocalMethodInvokeMonitor();
Identification.IdentificationBuilder identificationBuilder = Identification.newBuilder();
identificationBuilder.viewPoint(generateViewPoint(originClass, parametersType, methodName));
@ -35,8 +36,6 @@ public class MethodInterceptor {
try {
identificationBuilder.appendParameter("P" + i, new Gson().toJson(allArgument[i]));
} catch (Exception e) {
// Do nothing
} finally {
identificationBuilder.appendParameter("P" + i, "Cannot convert parameter");
}
}
@ -58,8 +57,16 @@ public class MethodInterceptor {
public void after(Class originClass, Class resultType, Object result) {
//TODO 需要把参数累加上去
new LocalMethodInvokeMonitor().afterInvoke();
String resultJson = null;
if (!void.class.getName().equals(resultType.getName())) {
try {
resultJson = new Gson().toJson(result);
} catch (Exception e) {
resultJson = "Can not convert result";
}
}
new LocalMethodInvokeMonitor().afterInvoke(resultJson);
}

View File

@ -64,7 +64,7 @@ public class AckSpan extends AbstractDataSerializable {
this.exceptionStack = spanData.getExceptionStack();
this.userId = spanData.getUserId();
this.applicationId = spanData.getApplicationId();
this.paramters.putAll(spanData.getParameters());
}
public AckSpan() {

View File

@ -225,4 +225,8 @@ public class Span {
public void setViewPointId(String viewPointId) {
this.viewPointId = viewPointId;
}
public void appendParameter(String key, String value) {
this.parameters.put(key, value);
}
}