重构大量方法,修改原有的大量基础类名称和方法名。
This commit is contained in:
parent
e1455e4467
commit
b69e61a659
|
|
@ -1,6 +1,6 @@
|
|||
package com.ai.cloud.skywalking.example.account.dubbo.impl;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.tracer.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.example.account.dubbo.interfaces.IAccountMaintain;
|
||||
import com.ai.cloud.skywalking.example.account.dubbo.interfaces.param.AccountInfo;
|
||||
import com.ai.cloud.skywalking.example.account.exception.BusinessException;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.ai.cloud.skywalking.api;
|
|||
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
|
||||
public final class BusinessKeyAppender {
|
||||
|
|
@ -20,7 +20,7 @@ public final class BusinessKeyAppender {
|
|||
if (!AuthDesc.isAuth())
|
||||
return;
|
||||
|
||||
Span spanData = Context.getLastSpan();
|
||||
Span spanData = CurrentThreadSpanStack.peek();
|
||||
if (spanData == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
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, Identification id);
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package com.ai.cloud.skywalking.api;
|
||||
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
|
||||
public interface IBuriedPointSender extends IExceptionHandler {
|
||||
ContextData beforeSend(Identification id);
|
||||
|
||||
void afterSend();
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package com.ai.cloud.skywalking.api;
|
||||
|
||||
public interface IExceptionHandler {
|
||||
void handleException(Throwable th);
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.ai.cloud.skywalking.api;
|
||||
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ public class Tracing {
|
|||
if (!AuthDesc.isAuth())
|
||||
return "";
|
||||
|
||||
Span spanData = Context.getLastSpan();
|
||||
Span spanData = CurrentThreadSpanStack.peek();
|
||||
if (spanData == null) {
|
||||
return "";
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ public class Tracing {
|
|||
if (!AuthDesc.isAuth())
|
||||
return null;
|
||||
|
||||
Span spanData = Context.getLastSpan();
|
||||
Span spanData = CurrentThreadSpanStack.peek();
|
||||
if (spanData == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +0,0 @@
|
|||
package com.ai.cloud.skywalking.buriedpoint;
|
||||
|
||||
import com.ai.cloud.skywalking.api.IBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.EmptyContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
import com.ai.cloud.skywalking.util.BuriedPointMachineUtil;
|
||||
import com.ai.cloud.skywalking.util.TraceIdGenerator;
|
||||
|
||||
/**
|
||||
* 暂不确定多线程的实现方式
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
@Deprecated
|
||||
public class ThreadBuriedPointSender extends BuriedPointInvoker
|
||||
implements IBuriedPointSender {
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(ThreadBuriedPointSender.class);
|
||||
|
||||
private Span span;
|
||||
|
||||
public ThreadBuriedPointSender(int threadSeqId) {
|
||||
if (!AuthDesc.isAuth())
|
||||
return;
|
||||
Span spanData;
|
||||
// 从ThreadLocal中取出上下文
|
||||
final Span parentSpanData = Context.getLastSpan();
|
||||
if (parentSpanData == null) {
|
||||
spanData = new Span(TraceIdGenerator.generate(),
|
||||
Config.SkyWalking.APPLICATION_CODE,
|
||||
Config.SkyWalking.USER_ID);
|
||||
} else {
|
||||
// 如果不为空,则将当前的Context存放到上下文
|
||||
spanData = new Span(parentSpanData.getTraceId(),
|
||||
Config.SkyWalking.APPLICATION_CODE,
|
||||
Config.SkyWalking.USER_ID);
|
||||
spanData.setParentLevel(parentSpanData.getParentLevel() + "."
|
||||
+ parentSpanData.getLevelId());
|
||||
spanData.setLevelId(threadSeqId);
|
||||
}
|
||||
this.span = spanData;
|
||||
}
|
||||
|
||||
public ContextData beforeSend(Identification id) {
|
||||
if (!AuthDesc.isAuth())
|
||||
return new EmptyContextData();
|
||||
|
||||
if (this.span == null) {
|
||||
return null;
|
||||
}
|
||||
span.setStartDate(System.currentTimeMillis());
|
||||
span.setViewPointId(id.getViewPoint());
|
||||
span.setProcessNo(BuriedPointMachineUtil.getProcessNo());
|
||||
Context.append(span);
|
||||
return new ContextData(span);
|
||||
}
|
||||
|
||||
public void afterSend() {
|
||||
super.afterInvoker();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package com.ai.cloud.skywalking.buriedpoint;
|
||||
|
||||
import com.ai.cloud.skywalking.api.IBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.EmptyContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
import com.ai.cloud.skywalking.util.ContextGenerator;
|
||||
|
||||
/**
|
||||
* 暂不确定多线程的实现方式
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
@Deprecated
|
||||
public class ThreadFactoryBuriedPointSender extends BuriedPointInvoker
|
||||
implements IBuriedPointSender {
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(ThreadBuriedPointSender.class);
|
||||
|
||||
public ContextData beforeSend(Identification id) {
|
||||
if (!AuthDesc.isAuth())
|
||||
return new EmptyContextData();
|
||||
|
||||
Span spanData = ContextGenerator.generateSpanFromThreadLocal(id);
|
||||
// 将新创建的Context存放到ThreadLocal栈中。
|
||||
Context.append(spanData);
|
||||
// 并将当前的Context返回回去
|
||||
return new ContextData(spanData);
|
||||
}
|
||||
|
||||
public void afterSend() {
|
||||
super.afterInvoker();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,56 +5,60 @@ import com.ai.cloud.skywalking.protocol.Span;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Context {
|
||||
public class CurrentThreadSpanStack {
|
||||
private static ThreadLocal<SpanNodeStack> nodes = new ThreadLocal<SpanNodeStack>();
|
||||
|
||||
private Context() {
|
||||
private CurrentThreadSpanStack() {
|
||||
|
||||
}
|
||||
|
||||
public static void append(Span span) {
|
||||
public static void push(Span span) {
|
||||
if (nodes.get() == null) {
|
||||
nodes.set(new SpanNodeStack());
|
||||
}
|
||||
nodes.get().push(span);
|
||||
}
|
||||
|
||||
public static Span getLastSpan() {
|
||||
public static Span peek() {
|
||||
if (nodes.get() == null) {
|
||||
return null;
|
||||
}
|
||||
return nodes.get().peek();
|
||||
}
|
||||
|
||||
public static Span removeLastSpan() {
|
||||
public static Span pop() {
|
||||
if (nodes.get() == null) {
|
||||
return null;
|
||||
}
|
||||
return nodes.get().pop();
|
||||
}
|
||||
|
||||
public static void invalidateAllSpan() {
|
||||
public static void invalidatePresentSpans() {
|
||||
if (nodes.get() == null) {
|
||||
nodes.set(new SpanNodeStack());
|
||||
}
|
||||
|
||||
nodes.get().invalidateAllCurrentSpan();
|
||||
nodes.get().invalidatePresentSpans();
|
||||
}
|
||||
|
||||
static class SpanNodeStack {
|
||||
private List<SpanNode> spans = new ArrayList<SpanNode>();
|
||||
/**
|
||||
* 单JVM的单线程,埋点数量一般不会超过20.
|
||||
* 超过20会影响性能,不推荐使用
|
||||
*/
|
||||
private List<SpanNode> spans = new ArrayList<SpanNode>(20);
|
||||
|
||||
public Span pop() {
|
||||
Span span = listPop();
|
||||
Span span = spans.remove(getTopElementIdx()).getData();
|
||||
if (!isEmpty()) {
|
||||
listPeek().incrementNextSubSpanLevelId();
|
||||
spans.get(getTopElementIdx()).incrementNextSubSpanLevelId();
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
public void push(Span span) {
|
||||
if (!isEmpty()) {
|
||||
listPush(new SpanNode(span, listPeek().getNextSubSpanLevelId()));
|
||||
listPush(new SpanNode(span, spans.get(getTopElementIdx()).getNextSubSpanLevelId()));
|
||||
} else {
|
||||
listPush(new SpanNode(span));
|
||||
}
|
||||
|
|
@ -65,26 +69,22 @@ public class Context {
|
|||
if (spans.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return listPeek().getData();
|
||||
return spans.get(getTopElementIdx()).getData();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
private int getTopElementIdx() {
|
||||
return spans.size() - 1;
|
||||
}
|
||||
|
||||
private boolean isEmpty() {
|
||||
return spans.isEmpty();
|
||||
}
|
||||
|
||||
private Span listPop() {
|
||||
return spans.remove(spans.size() - 1).getData();
|
||||
}
|
||||
|
||||
private SpanNode listPeek() {
|
||||
return spans.get(spans.size() - 1);
|
||||
}
|
||||
|
||||
private void listPush(SpanNode spanNode) {
|
||||
spans.add(spans.size(), spanNode);
|
||||
}
|
||||
|
||||
public void invalidateAllCurrentSpan() {
|
||||
public void invalidatePresentSpans() {
|
||||
for (SpanNode spanNode : spans) {
|
||||
spanNode.getData().setIsInvalidate(true);
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ public class Context {
|
|||
|
||||
static class SpanNode {
|
||||
private Span data;
|
||||
//
|
||||
|
||||
private int nextSubSpanLevelId = 0;
|
||||
|
||||
public SpanNode(Span data) {
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package com.ai.cloud.skywalking.buriedpoint;
|
||||
package com.ai.cloud.skywalking.tracer;
|
||||
|
||||
import com.ai.cloud.skywalking.buffer.ContextBuffer;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
|
|
@ -14,17 +14,17 @@ import java.util.Set;
|
|||
|
||||
import static com.ai.cloud.skywalking.conf.Config.BuriedPoint.EXCLUSIVE_EXCEPTIONS;
|
||||
|
||||
public class BuriedPointInvoker {
|
||||
public abstract class BaseTracer {
|
||||
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(BuriedPointInvoker.class);
|
||||
.getLogger(BaseTracer.class);
|
||||
|
||||
private static String EXCEPTION_SPLIT = ",";
|
||||
|
||||
private static Set<String> exclusiveExceptionSet = null;
|
||||
|
||||
|
||||
public ContextData beforeInvoker(Span spanData) {
|
||||
protected ContextData traceBeforeInvoke(Span spanData) {
|
||||
if (Config.BuriedPoint.PRINTF) {
|
||||
logger.debug("TraceId:" + spanData.getTraceId()
|
||||
+ "\tviewpointId:" + spanData.getViewPointId()
|
||||
|
|
@ -33,18 +33,18 @@ public class BuriedPointInvoker {
|
|||
}
|
||||
|
||||
// 将新创建的Context存放到ThreadLocal栈中。
|
||||
Context.append(spanData);
|
||||
CurrentThreadSpanStack.push(spanData);
|
||||
// 并将当前的Context返回回去
|
||||
return new ContextData(spanData);
|
||||
}
|
||||
|
||||
public void afterInvoker() {
|
||||
protected void traceAfterInvoke() {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return;
|
||||
|
||||
// 弹出上下文的栈顶中的元素
|
||||
Span spanData = Context.removeLastSpan();
|
||||
Span spanData = CurrentThreadSpanStack.pop();
|
||||
if (spanData == null || spanData.isInvalidate()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ public class BuriedPointInvoker {
|
|||
}
|
||||
}
|
||||
|
||||
public void handleException(Throwable th) {
|
||||
protected void occurException(Throwable th) {
|
||||
try {
|
||||
if (exclusiveExceptionSet == null) {
|
||||
Set<String> exclusiveExceptions = new HashSet<String>();
|
||||
|
|
@ -80,7 +80,7 @@ public class BuriedPointInvoker {
|
|||
exclusiveExceptionSet = exclusiveExceptions;
|
||||
}
|
||||
|
||||
Span span = Context.getLastSpan();
|
||||
Span span = CurrentThreadSpanStack.peek();
|
||||
span.handleException(th, exclusiveExceptionSet,
|
||||
Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH);
|
||||
} catch (Throwable t) {
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package com.ai.cloud.skywalking.buriedpoint;
|
||||
package com.ai.cloud.skywalking.tracer;
|
||||
|
||||
import com.ai.cloud.skywalking.api.IBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
|
|
@ -10,27 +9,32 @@ import com.ai.cloud.skywalking.model.Identification;
|
|||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
import com.ai.cloud.skywalking.util.ContextGenerator;
|
||||
|
||||
public class LocalBuriedPointSender extends BuriedPointInvoker
|
||||
implements IBuriedPointSender {
|
||||
public class LocalMethodTracer extends BaseTracer {
|
||||
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(LocalBuriedPointSender.class);
|
||||
.getLogger(LocalMethodTracer.class);
|
||||
|
||||
public ContextData beforeSend(Identification id) {
|
||||
public ContextData traceBeforeInvoke(Identification id) {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return new EmptyContextData();
|
||||
|
||||
Span spanData = ContextGenerator.generateSpanFromThreadLocal(id);
|
||||
|
||||
return super.beforeInvoker(spanData);
|
||||
return super.traceBeforeInvoke(spanData);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t.getMessage(), t);
|
||||
return new EmptyContextData();
|
||||
}
|
||||
}
|
||||
|
||||
public void afterSend() {
|
||||
super.afterInvoker();
|
||||
public void traceAfterInvoke(){
|
||||
super.traceAfterInvoke();
|
||||
}
|
||||
|
||||
|
||||
public void occurException(Throwable th){
|
||||
super.occurException(th);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
package com.ai.cloud.skywalking.buriedpoint;
|
||||
package com.ai.cloud.skywalking.tracer;
|
||||
|
||||
import com.ai.cloud.skywalking.api.IBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
|
|
@ -12,13 +11,12 @@ import com.ai.cloud.skywalking.protocol.Span;
|
|||
import com.ai.cloud.skywalking.protocol.SpanType;
|
||||
import com.ai.cloud.skywalking.util.ContextGenerator;
|
||||
|
||||
public class RPCBuriedPointSender extends BuriedPointInvoker implements IBuriedPointSender {
|
||||
public class RPCClientTracer extends BaseTracer{
|
||||
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(RPCBuriedPointSender.class);
|
||||
.getLogger(RPCClientTracer.class);
|
||||
|
||||
@Override
|
||||
public ContextData beforeSend(Identification id) {
|
||||
public ContextData traceBeforeInvoke(Identification id) {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return new EmptyContextData();
|
||||
|
|
@ -27,7 +25,7 @@ public class RPCBuriedPointSender extends BuriedPointInvoker implements IBuriedP
|
|||
//设置SpanType的类型
|
||||
spanData.setSpanType(SpanType.RPC_CLIENT);
|
||||
|
||||
Context.append(spanData);
|
||||
CurrentThreadSpanStack.push(spanData);
|
||||
|
||||
return new ContextData(spanData.getTraceId(), generateSubParentLevelId(spanData), spanData.getCallType());
|
||||
} catch (Throwable t) {
|
||||
|
|
@ -36,6 +34,15 @@ public class RPCBuriedPointSender extends BuriedPointInvoker implements IBuriedP
|
|||
}
|
||||
}
|
||||
|
||||
public void traceAfterInvoke(){
|
||||
super.traceAfterInvoke();
|
||||
}
|
||||
|
||||
|
||||
public void occurException(Throwable th){
|
||||
super.occurException(th);
|
||||
}
|
||||
|
||||
private String generateSubParentLevelId(Span spanData) {
|
||||
if (spanData.getParentLevel() == null) {
|
||||
return spanData.getLevelId() + "";
|
||||
|
|
@ -44,8 +51,4 @@ public class RPCBuriedPointSender extends BuriedPointInvoker implements IBuriedP
|
|||
return spanData.getParentLevel() + "." + spanData.getLevelId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSend() {
|
||||
super.afterInvoker();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
package com.ai.cloud.skywalking.buriedpoint;
|
||||
package com.ai.cloud.skywalking.tracer;
|
||||
|
||||
import com.ai.cloud.skywalking.api.IBuriedPointReceiver;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
|
|
@ -11,17 +10,12 @@ import com.ai.cloud.skywalking.protocol.Span;
|
|||
import com.ai.cloud.skywalking.protocol.SpanType;
|
||||
import com.ai.cloud.skywalking.util.ContextGenerator;
|
||||
|
||||
public class RPCBuriedPointReceiver extends BuriedPointInvoker
|
||||
implements IBuriedPointReceiver {
|
||||
public class RPCServerTracer extends BaseTracer{
|
||||
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(RPCBuriedPointReceiver.class);
|
||||
.getLogger(RPCServerTracer.class);
|
||||
|
||||
public void afterReceived() {
|
||||
super.afterInvoker();
|
||||
}
|
||||
|
||||
public void beforeReceived(ContextData context, Identification id) {
|
||||
public void traceBeforeInvoke(ContextData context, Identification id) {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return;
|
||||
|
|
@ -33,15 +27,24 @@ public class RPCBuriedPointReceiver extends BuriedPointInvoker
|
|||
|
||||
invalidateAllSpanIfIsNotFirstSpan(spanData);
|
||||
|
||||
super.beforeInvoker(spanData);
|
||||
super.traceBeforeInvoke(spanData);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t.getMessage(), t);
|
||||
}
|
||||
}
|
||||
|
||||
public void traceAfterInvoke(){
|
||||
super.traceAfterInvoke();
|
||||
}
|
||||
|
||||
|
||||
public void occurException(Throwable th){
|
||||
super.occurException(th);
|
||||
}
|
||||
|
||||
private void invalidateAllSpanIfIsNotFirstSpan(Span spanData) {
|
||||
if (!Context.getLastSpan().getTraceId().equals(spanData.getTraceId())) {
|
||||
Context.invalidateAllSpan();
|
||||
if (!CurrentThreadSpanStack.peek().getTraceId().equals(spanData.getTraceId())) {
|
||||
CurrentThreadSpanStack.invalidatePresentSpans();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.ai.cloud.skywalking.util;
|
||||
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.context.Context;
|
||||
import com.ai.cloud.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.protocol.Span;
|
||||
|
|
@ -57,7 +57,7 @@ public final class ContextGenerator {
|
|||
private static Span getSpanFromThreadLocal() {
|
||||
Span span;
|
||||
// 1.获取Context,从ThreadLocal栈中获取中
|
||||
final Span parentSpan = Context.getLastSpan();
|
||||
final Span parentSpan = CurrentThreadSpanStack.peek();
|
||||
// 2 校验Context,Context是否存在
|
||||
if (parentSpan == null) {
|
||||
// 不存在,新创建一个Context
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@ package test.ai.cloud.api;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.tracer.RPCClientTracer;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.model.Identification.IdentificationBuilder;
|
||||
|
||||
public class TimeTest {
|
||||
@Test
|
||||
public void test(){
|
||||
RPCBuriedPointSender sender = new RPCBuriedPointSender();
|
||||
RPCClientTracer sender = new RPCClientTracer();
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
IdentificationBuilder builder = Identification
|
||||
.newBuilder()
|
||||
.viewPoint("1111");
|
||||
sender.beforeSend(builder.build());
|
||||
sender.afterSend();
|
||||
sender.traceBeforeInvoke(builder.build());
|
||||
sender.traceAfterInvoke();
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println(end - start + "ms");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.ai.cloud.skywalking.plugin.dubbo;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointReceiver;
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.tracer.RPCServerTracer;
|
||||
import com.ai.cloud.skywalking.tracer.RPCClientTracer;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
|
@ -22,9 +22,9 @@ public class SWDubboEnhanceFilter implements Filter {
|
|||
boolean isConsumer = context.isConsumerSide();
|
||||
Result result = null;
|
||||
if (isConsumer) {
|
||||
RPCBuriedPointSender sender = new RPCBuriedPointSender();
|
||||
RPCClientTracer clientTracer = new RPCClientTracer();
|
||||
|
||||
ContextData contextData = sender.beforeSend(createIdentification(invoker, invocation));
|
||||
ContextData contextData = clientTracer.traceBeforeInvoke(createIdentification(invoker, invocation));
|
||||
String contextDataStr = contextData.toString();
|
||||
|
||||
//追加参数
|
||||
|
|
@ -53,18 +53,18 @@ public class SWDubboEnhanceFilter implements Filter {
|
|||
result = invoker.invoke(invocation);
|
||||
//结果是否包含异常
|
||||
if (result.getException() != null) {
|
||||
sender.handleException(result.getException());
|
||||
clientTracer.occurException(result.getException());
|
||||
}
|
||||
} catch (RpcException e) {
|
||||
// 自身异常
|
||||
sender.handleException(e);
|
||||
clientTracer.occurException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
sender.afterSend();
|
||||
clientTracer.traceAfterInvoke();
|
||||
}
|
||||
} else {
|
||||
// 读取参数
|
||||
RPCBuriedPointReceiver rpcBuriedPointReceiver = new RPCBuriedPointReceiver();
|
||||
RPCServerTracer serverTracer = new RPCServerTracer();
|
||||
String contextDataStr;
|
||||
|
||||
if (!BugFixAcitve.isActive) {
|
||||
|
|
@ -78,21 +78,21 @@ public class SWDubboEnhanceFilter implements Filter {
|
|||
contextData = new ContextData(contextDataStr);
|
||||
}
|
||||
|
||||
rpcBuriedPointReceiver.beforeReceived(contextData, createIdentification(invoker, invocation));
|
||||
serverTracer.traceBeforeInvoke(contextData, createIdentification(invoker, invocation));
|
||||
|
||||
try {
|
||||
//执行结果
|
||||
result = invoker.invoke(invocation);
|
||||
//结果是否包含异常
|
||||
if (result.getException() != null) {
|
||||
rpcBuriedPointReceiver.handleException(result.getException());
|
||||
serverTracer.occurException(result.getException());
|
||||
}
|
||||
} catch (RpcException e) {
|
||||
// 自身异常
|
||||
rpcBuriedPointReceiver.handleException(e);
|
||||
serverTracer.occurException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
rpcBuriedPointReceiver.afterReceived();
|
||||
serverTracer.traceAfterInvoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package org.skywalking.httpClient.v4.plugin;
|
|||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.tracer.RPCClientTracer;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
|
|
@ -17,7 +17,7 @@ public class HttpClientExecuteInterceptor implements IntanceMethodsAroundInterce
|
|||
*/
|
||||
public static String TRACE_HEAD_NAME = "SkyWalking-TRACING-NAME";
|
||||
|
||||
private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
|
||||
private static RPCClientTracer clientTracer = new RPCClientTracer();
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context,
|
||||
|
|
@ -38,7 +38,7 @@ public class HttpClientExecuteInterceptor implements IntanceMethodsAroundInterce
|
|||
.setHeader(
|
||||
TRACE_HEAD_NAME,
|
||||
"ContextData="
|
||||
+ sender.beforeSend(
|
||||
+ clientTracer.traceBeforeInvoke(
|
||||
Identification
|
||||
.newBuilder()
|
||||
.viewPoint(
|
||||
|
|
@ -58,7 +58,7 @@ public class HttpClientExecuteInterceptor implements IntanceMethodsAroundInterce
|
|||
// illegal args, can't trace. ignore.
|
||||
return ret;
|
||||
}
|
||||
sender.afterSend();
|
||||
clientTracer.traceAfterInvoke();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ public class HttpClientExecuteInterceptor implements IntanceMethodsAroundInterce
|
|||
// illegal args, can't trace. ignore.
|
||||
return;
|
||||
}
|
||||
sender.handleException(t);
|
||||
clientTracer.occurException(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.ai.cloud.skywalking.plugin.jdbc;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.tracer.RPCClientTracer;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
|
@ -11,13 +11,13 @@ import java.sql.SQLException;
|
|||
* @author wusheng
|
||||
*/
|
||||
public class CallableStatementTracing {
|
||||
private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
|
||||
private static RPCClientTracer clientTracer = new RPCClientTracer();
|
||||
|
||||
public static <R> R execute(java.sql.CallableStatement realStatement,
|
||||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
sender.beforeSend(Identification
|
||||
clientTracer.traceBeforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
|
|
@ -27,10 +27,10 @@ public class CallableStatementTracing {
|
|||
: ":" + sql)).spanType(JDBCBuriedPointType.instance()).build());
|
||||
return exec.exe(realStatement, sql);
|
||||
} catch (SQLException e) {
|
||||
sender.handleException(e);
|
||||
clientTracer.occurException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
sender.afterSend();
|
||||
clientTracer.traceAfterInvoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.ai.cloud.skywalking.plugin.jdbc;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.tracer.RPCClientTracer;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
|
@ -11,13 +11,13 @@ import java.sql.SQLException;
|
|||
* @author wusheng
|
||||
*/
|
||||
public class ConnectionTracing {
|
||||
private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
|
||||
private static RPCClientTracer clientTracer = new RPCClientTracer();
|
||||
|
||||
public static <R> R execute(java.sql.Connection realConnection,
|
||||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
sender.beforeSend(Identification
|
||||
clientTracer.traceBeforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
|
|
@ -27,10 +27,10 @@ public class ConnectionTracing {
|
|||
: ":" + sql)).spanType(JDBCBuriedPointType.instance()).build());
|
||||
return exec.exe(realConnection, sql);
|
||||
} catch (SQLException e) {
|
||||
sender.handleException(e);
|
||||
clientTracer.occurException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
sender.afterSend();
|
||||
clientTracer.traceAfterInvoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.ai.cloud.skywalking.plugin.jdbc;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.tracer.RPCClientTracer;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
|
@ -12,13 +12,13 @@ import java.sql.SQLException;
|
|||
*
|
||||
*/
|
||||
public class PreparedStatementTracing {
|
||||
private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
|
||||
private static RPCClientTracer clientTracer = new RPCClientTracer();
|
||||
|
||||
public static <R> R execute(java.sql.PreparedStatement realStatement,
|
||||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
sender.beforeSend(Identification
|
||||
clientTracer.traceBeforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
|
|
@ -28,10 +28,10 @@ public class PreparedStatementTracing {
|
|||
: ":" + sql)).spanType(JDBCBuriedPointType.instance()).build());
|
||||
return exec.exe(realStatement, sql);
|
||||
} catch (SQLException e) {
|
||||
sender.handleException(e);
|
||||
clientTracer.occurException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
sender.afterSend();
|
||||
clientTracer.traceAfterInvoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.ai.cloud.skywalking.plugin.jdbc;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.tracer.RPCClientTracer;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
|
@ -11,13 +11,13 @@ import java.sql.SQLException;
|
|||
* @author wusheng
|
||||
*/
|
||||
public class StatementTracing {
|
||||
private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
|
||||
private static RPCClientTracer clientTracer = new RPCClientTracer();
|
||||
|
||||
public static <R> R execute(java.sql.Statement realStatement,
|
||||
String connectInfo, String method, String sql, Executable<R> exec)
|
||||
throws SQLException {
|
||||
try {
|
||||
sender.beforeSend(Identification
|
||||
clientTracer.traceBeforeInvoke(Identification
|
||||
.newBuilder()
|
||||
.viewPoint(connectInfo)
|
||||
.businessKey(
|
||||
|
|
@ -27,10 +27,10 @@ public class StatementTracing {
|
|||
: ":" + sql)).spanType(JDBCBuriedPointType.instance()).build());
|
||||
return exec.exe(realStatement, sql);
|
||||
} catch (SQLException e) {
|
||||
sender.handleException(e);
|
||||
clientTracer.occurException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
sender.afterSend();
|
||||
clientTracer.traceAfterInvoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.ai.cloud.skywalking.jedis.v2.plugin;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.tracer.RPCClientTracer;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.assist.SimpleObjectFirstInvokeInterceptor;
|
||||
|
|
@ -10,7 +10,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.enhance.MethodInterceptResult;
|
|||
public abstract class JedisBaseInterceptor extends SimpleObjectFirstInvokeInterceptor {
|
||||
protected static final String REDIS_CONN_INFO_KEY = "redisClusterConnInfo";
|
||||
|
||||
private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
|
||||
private static RPCClientTracer clientTracer = new RPCClientTracer();
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
|
|
@ -30,20 +30,20 @@ public abstract class JedisBaseInterceptor extends SimpleObjectFirstInvokeInterc
|
|||
builder.businessKey("key="
|
||||
+ interceptorContext.allArguments()[0]);
|
||||
}
|
||||
sender.beforeSend(builder.build());
|
||||
clientTracer.traceBeforeInvoke(builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
if (this.isLastAfterMethod(context)) {
|
||||
sender.afterSend();
|
||||
clientTracer.traceAfterInvoke();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) {
|
||||
sender.handleException(t);
|
||||
clientTracer.occurException(t);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
package com.ai.cloud.skywalking.plugin.spring;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.LocalBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.tracer.LocalMethodTracer;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
|
||||
public class TracingAspect {
|
||||
|
||||
public Object doTracing(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
|
||||
LocalBuriedPointSender _sender = new LocalBuriedPointSender();
|
||||
LocalMethodTracer localMethodTracer = new LocalMethodTracer();
|
||||
try {
|
||||
_sender.beforeSend(Identification.newBuilder().viewPoint(proceedingJoinPoint.getSignature().toString()).spanType(SpringBuriedPointType.instance()).build());
|
||||
localMethodTracer.traceBeforeInvoke(Identification.newBuilder().viewPoint(proceedingJoinPoint.getSignature().toString()).spanType(SpringBuriedPointType.instance()).build());
|
||||
return proceedingJoinPoint.proceed();
|
||||
} catch (Throwable e) {
|
||||
_sender.handleException(e);
|
||||
localMethodTracer.occurException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
_sender.afterSend();
|
||||
localMethodTracer.traceAfterInvoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.ai.cloud.skywalking.plugin.web;
|
|||
|
||||
|
||||
import com.ai.cloud.skywalking.api.Tracing;
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointReceiver;
|
||||
import com.ai.cloud.skywalking.tracer.RPCServerTracer;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.model.ContextData;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
|
|
@ -32,7 +32,7 @@ public class SkyWalkingFilter implements Filter {
|
|||
return;
|
||||
}
|
||||
|
||||
RPCBuriedPointReceiver receiver = null;
|
||||
RPCServerTracer tracer = null;
|
||||
try {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
String tracingHeaderValue = request.getHeader(tracingName);
|
||||
|
|
@ -51,17 +51,17 @@ public class SkyWalkingFilter implements Filter {
|
|||
contextData = new ContextData(contextDataStr);
|
||||
}
|
||||
}
|
||||
receiver = new RPCBuriedPointReceiver();
|
||||
receiver.beforeReceived(contextData, generateIdentification(request));
|
||||
tracer = new RPCServerTracer();
|
||||
tracer.traceBeforeInvoke(contextData, generateIdentification(request));
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
|
||||
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
|
||||
httpServletResponse.addHeader(TRACE_ID_HEADER_NAME, Tracing.getTraceId());
|
||||
} catch (Throwable e) {
|
||||
receiver.handleException(e);
|
||||
tracer.occurException(e);
|
||||
throw new ServletException(e);
|
||||
} finally {
|
||||
receiver.afterReceived();
|
||||
tracer.traceAfterInvoke();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue