1.修改埋点标识类名称
2.移除埋点标识类中无用的uri属性,在RPC调用时,使用viewpoint字段存储uri 3.TracingEnhanceProcessor中的代理类构造函数名称错误的隐藏问题(不影响使用) 4. TracingEnhanceProcessor生成代理类名称规则改变,更便于断点识别
This commit is contained in:
parent
6370126b4b
commit
71063f084b
|
|
@ -1,10 +1,10 @@
|
|||
package com.ai.cloud.skywalking.api;
|
||||
|
||||
import com.ai.cloud.skywalking.model.SendData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
|
||||
public interface IBuriedPointSender extends IExceptionHandler {
|
||||
ContextData beforeSend(SendData data);
|
||||
ContextData beforeSend(Identification id);
|
||||
|
||||
void afterSend();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ import com.ai.cloud.skywalking.buffer.ContextBuffer;
|
|||
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.SendData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.util.ContextGenerator;
|
||||
import com.ai.cloud.skywalking.util.ExceptionHandleUtil;
|
||||
|
||||
public class LocalBuriedPointSender implements IBuriedPointSender {
|
||||
|
||||
public ContextData beforeSend(SendData sendData) {
|
||||
Span spanData = ContextGenerator.generateContextFromThreadLocal(sendData);
|
||||
public ContextData beforeSend(Identification id) {
|
||||
Span spanData = ContextGenerator.generateContextFromThreadLocal(id);
|
||||
// 3.将新创建的Context存放到ThreadLocal栈中。
|
||||
Context.getOrCreate().append(spanData);
|
||||
// 4 并将当前的Context返回回去
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ import com.ai.cloud.skywalking.buffer.ContextBuffer;
|
|||
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.SendData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.util.ContextGenerator;
|
||||
import com.ai.cloud.skywalking.util.ExceptionHandleUtil;
|
||||
|
||||
public class RPCBuriedPointSender implements IBuriedPointSender {
|
||||
|
||||
public ContextData beforeSend(SendData sendData) {
|
||||
Span spanData = ContextGenerator.generateContextFromThreadLocal(sendData);
|
||||
public ContextData beforeSend(Identification id) {
|
||||
Span spanData = ContextGenerator.generateContextFromThreadLocal(id);
|
||||
// 3.将新创建的Context存放到ThreadLocal栈中。
|
||||
Context.getOrCreate().append(spanData);
|
||||
// 4 并将当前的Context返回回去
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import com.ai.cloud.skywalking.buffer.ContextBuffer;
|
|||
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.SendData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.util.BuriedPointMachineUtil;
|
||||
import com.ai.cloud.skywalking.util.ExceptionHandleUtil;
|
||||
import com.ai.cloud.skywalking.util.TraceIdGenerator;
|
||||
|
|
@ -29,12 +29,12 @@ public class ThreadBuriedPointSender implements IBuriedPointSender {
|
|||
this.span = spanData;
|
||||
}
|
||||
|
||||
public ContextData beforeSend(SendData sendData) {
|
||||
public ContextData beforeSend(Identification id) {
|
||||
if (this.span == null) {
|
||||
return null;
|
||||
}
|
||||
span.setStartDate(System.currentTimeMillis());
|
||||
span.setViewPointId(sendData.getViewPoint());
|
||||
span.setViewPointId(id.getViewPoint());
|
||||
span.setProcessNo(BuriedPointMachineUtil.getProcessNo());
|
||||
Context.getOrCreate().append(span);
|
||||
return new ContextData(span);
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ import com.ai.cloud.skywalking.buffer.ContextBuffer;
|
|||
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.SendData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.util.ContextGenerator;
|
||||
import com.ai.cloud.skywalking.util.ExceptionHandleUtil;
|
||||
|
||||
public class ThreadFactoryBuriedPointSender implements IBuriedPointSender {
|
||||
|
||||
public ContextData beforeSend(SendData sendData) {
|
||||
Span spanData = ContextGenerator.generateContextFromThreadLocal(sendData);
|
||||
public ContextData beforeSend(Identification id) {
|
||||
Span spanData = ContextGenerator.generateContextFromThreadLocal(id);
|
||||
// 3.将新创建的Context存放到ThreadLocal栈中。
|
||||
Context.getOrCreate().append(spanData);
|
||||
// 4 并将当前的Context返回回去
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package com.ai.cloud.skywalking.model;
|
||||
|
||||
public class Identification {
|
||||
private String viewPoint;
|
||||
private String businessKey;
|
||||
|
||||
public Identification() {
|
||||
//Non
|
||||
}
|
||||
|
||||
public String getViewPoint() {
|
||||
return viewPoint;
|
||||
}
|
||||
|
||||
public String getBusinessKey() {
|
||||
return businessKey;
|
||||
}
|
||||
|
||||
public static IdentificationBuilder newBuilder() {
|
||||
return new IdentificationBuilder();
|
||||
}
|
||||
|
||||
public static class IdentificationBuilder {
|
||||
private Identification sendData;
|
||||
|
||||
IdentificationBuilder() {
|
||||
sendData = new Identification();
|
||||
}
|
||||
|
||||
public Identification build() {
|
||||
return sendData;
|
||||
}
|
||||
|
||||
public IdentificationBuilder viewPoint(String viewPoint) {
|
||||
sendData.viewPoint = viewPoint;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IdentificationBuilder businessKey(String businessKey) {
|
||||
sendData.businessKey = businessKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
package com.ai.cloud.skywalking.model;
|
||||
|
||||
public class SendData {
|
||||
private String viewPoint;
|
||||
private String URI;
|
||||
private String businessKey;
|
||||
|
||||
public SendData() {
|
||||
//Non
|
||||
}
|
||||
|
||||
public String getViewPoint() {
|
||||
return viewPoint;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return URI;
|
||||
}
|
||||
|
||||
public String getBusinessKey() {
|
||||
return businessKey;
|
||||
}
|
||||
|
||||
public static SendDataBuilder newBuilder() {
|
||||
return new SendDataBuilder();
|
||||
}
|
||||
|
||||
public static class SendDataBuilder {
|
||||
private SendData sendData;
|
||||
|
||||
SendDataBuilder() {
|
||||
sendData = new SendData();
|
||||
}
|
||||
|
||||
public SendData build() {
|
||||
return sendData;
|
||||
}
|
||||
|
||||
public SendDataBuilder viewPoint(String viewPoint) {
|
||||
sendData.viewPoint = viewPoint;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendDataBuilder URI(String uri) {
|
||||
sendData.URI = uri;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendDataBuilder businessKey(String businessKey) {
|
||||
sendData.businessKey = businessKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ package com.ai.cloud.skywalking.util;
|
|||
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.SendData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
||||
public final class ContextGenerator {
|
||||
/**
|
||||
|
|
@ -12,7 +12,7 @@ public final class ContextGenerator {
|
|||
* @param sendData 视点,业务数据等信息
|
||||
* @return
|
||||
*/
|
||||
public static Span generateContextFromThreadLocal(SendData sendData) {
|
||||
public static Span generateContextFromThreadLocal(Identification sendData) {
|
||||
Span spanData = getContextFromThreadLocal();
|
||||
// 设置基本属性
|
||||
spanData.setStartDate(System.currentTimeMillis());
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.ai.cloud.skywalking.plugin.spring;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.LocalBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.model.SendData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import javassist.*;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
|
|
@ -49,12 +49,12 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
|
|||
// TODO 参数注解
|
||||
mCtc.addMethod(CtMethod.make(result.toString(), mCtc));
|
||||
}
|
||||
mCtc.addConstructor(CtNewConstructor.make("public " + bean.getClass().getSimpleName() + "Proxy(" + LocalBuriedPointSender.class
|
||||
mCtc.addConstructor(CtNewConstructor.make("public " + mCtc.getSimpleName() + "(" + LocalBuriedPointSender.class
|
||||
.getName() + " buriedPoint, " + bean.getClass().getName() + " realBean){" +
|
||||
"this.buriedPoint = buriedPoint;this.realBean = realBean;}", mCtc));
|
||||
mCtc.addConstructor(CtNewConstructor.defaultConstructor(mCtc));
|
||||
Class classes = mCtc.toClass();
|
||||
Constructor constructor = classes.getConstructor(LocalBuriedPointSender.class, bean.getClass());
|
||||
Class<?> classes = mCtc.toClass();
|
||||
Constructor<?> constructor = classes.getConstructor(LocalBuriedPointSender.class, bean.getClass());
|
||||
return constructor.newInstance(new LocalBuriedPointSender(), bean);
|
||||
} catch (CannotCompileException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -94,10 +94,10 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
|
|||
}
|
||||
|
||||
private String generateBeforeSendParamter(Object bean, Method method) {
|
||||
StringBuilder builder = new StringBuilder("(" + SendData.class.getName() + ".newBuilder().viewPoint(\""
|
||||
StringBuilder builder = new StringBuilder("(" + Identification.class.getName() + ".newBuilder().viewPoint(\""
|
||||
+ bean.getClass().getName() + "." + method.getName());
|
||||
builder.append("(");
|
||||
for (Class param : method.getParameterTypes()) {
|
||||
for (Class<?> param : method.getParameterTypes()) {
|
||||
builder.append(param.getSimpleName() + ",");
|
||||
}
|
||||
if (method.getGenericParameterTypes().length > 0) {
|
||||
|
|
@ -113,7 +113,7 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
|
|||
int index;
|
||||
result.append("(");
|
||||
index = 0;
|
||||
for (Class parameter : method.getParameterTypes()) {
|
||||
for (Class<?> parameter : method.getParameterTypes()) {
|
||||
result.append(parameter.getSimpleName().toLowerCase() + "$" + (index++) + ",");
|
||||
}
|
||||
if (method.getParameterTypes().length > 0) {
|
||||
|
|
@ -129,7 +129,7 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
|
|||
|
||||
private String generateException(Method method) {
|
||||
StringBuilder resultB = new StringBuilder(" throws ");
|
||||
for (Class exceptionClasses : method.getExceptionTypes()) {
|
||||
for (Class<?> exceptionClasses : method.getExceptionTypes()) {
|
||||
resultB.append(exceptionClasses.getName() + ",");
|
||||
}
|
||||
if (method.getExceptionTypes().length > 0) {
|
||||
|
|
@ -144,7 +144,7 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
|
|||
StringBuilder result = new StringBuilder();
|
||||
result.append("(");
|
||||
int index = 0;
|
||||
for (Class param : method.getParameterTypes()) {
|
||||
for (Class<?> param : method.getParameterTypes()) {
|
||||
result.append(param.getName() + " " + param.getSimpleName().
|
||||
toLowerCase() + "$" + (index++) + ",");
|
||||
}
|
||||
|
|
@ -160,11 +160,11 @@ public class TracingEnhanceProcessor implements BeanPostProcessor {
|
|||
}
|
||||
|
||||
private CtClass createProxyClass(Object bean, ClassPool mPool) {
|
||||
return mPool.makeClass(bean.getClass().getSimpleName() + "Proxy$" + ThreadLocalRandom.current().nextInt(100));
|
||||
return mPool.makeClass(bean.getClass().getSimpleName() + "$EnhanceBySWTracing$" + ThreadLocalRandom.current().nextInt(100));
|
||||
}
|
||||
|
||||
private void inheritanceAllInterfaces(Object bean, ClassPool mPool, CtClass mCtc) throws NotFoundException {
|
||||
for (Class classes : bean.getClass().getInterfaces()) {
|
||||
for (Class<?> classes : bean.getClass().getInterfaces()) {
|
||||
mCtc.addInterface(mPool.get(classes.getClass().getName()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue