提交 706debcb 编写于 作者: A ascrutae

Merge remote-tracking branch 'origin/master'

......@@ -5,31 +5,42 @@ import static com.ai.cloud.skywalking.conf.Config.BuriedPoint.EXCLUSIVE_EXCEPTIO
import java.util.HashSet;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.ai.cloud.skywalking.api.IExceptionHandler;
import com.ai.cloud.skywalking.conf.Config;
import com.ai.cloud.skywalking.context.Context;
import com.ai.cloud.skywalking.protocol.Span;
public class ApplicationExceptionHandler implements IExceptionHandler {
private static Logger logger = LogManager
.getLogger(ApplicationExceptionHandler.class);
private static String EXCEPTION_SPLIT = ",";
private static Set<String> exclusiveExceptionSet = null;
@Override
public void handleException(Throwable th) {
if (exclusiveExceptionSet == null) {
Set<String> exclusiveExceptions = new HashSet<String>();
String[] exceptions = EXCLUSIVE_EXCEPTIONS.split(EXCEPTION_SPLIT);
for(String exception : exceptions){
exclusiveExceptions.add(exception);
try {
if (exclusiveExceptionSet == null) {
Set<String> exclusiveExceptions = new HashSet<String>();
String[] exceptions = EXCLUSIVE_EXCEPTIONS
.split(EXCEPTION_SPLIT);
for (String exception : exceptions) {
exclusiveExceptions.add(exception);
}
exclusiveExceptionSet = exclusiveExceptions;
}
exclusiveExceptionSet = exclusiveExceptions;
}
Span span = Context.getLastSpan();
span.handleException(th, exclusiveExceptionSet,
Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH);
Span span = Context.getLastSpan();
span.handleException(th, exclusiveExceptionSet,
Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH);
} catch (Throwable t) {
logger.error(t.getMessage(), t);
}
}
}
......@@ -14,42 +14,57 @@ 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 ApplicationExceptionHandler implements IBuriedPointSender {
private static Logger logger = LogManager.getLogger(LocalBuriedPointSender.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() {
if (!AuthDesc.isAuth())
return;
// 弹出上下文的栈顶中的元素
Span spanData = Context.removeLastSpan();
if (spanData == null) {
return;
}
// 加上花费时间
spanData.setCost(System.currentTimeMillis() - spanData.getStartDate());
if (Config.BuriedPoint.PRINTF) {
logger.debug("TraceId:" + spanData.getTraceId() + "\tviewpointId:" + spanData.getViewPointId() + "\tParentLevelId:" + spanData.
getParentLevel() + "\tLevelId:" + spanData.getLevelId() + "\tbusinessKey:" + spanData.getBusinessKey());
}
// 存放到本地发送进程中
if (!Config.Sender.IS_OFF) {
ContextBuffer.save(spanData);
}
}
public class LocalBuriedPointSender extends ApplicationExceptionHandler
implements IBuriedPointSender {
private static Logger logger = LogManager
.getLogger(LocalBuriedPointSender.class);
public ContextData beforeSend(Identification id) {
try {
if (!AuthDesc.isAuth())
return new EmptyContextData();
Span spanData = ContextGenerator.generateSpanFromThreadLocal(id);
// 将新创建的Context存放到ThreadLocal栈中。
Context.append(spanData);
// 并将当前的Context返回回去
return new ContextData(spanData);
} catch (Throwable t) {
logger.error(t.getMessage(), t);
return new EmptyContextData();
}
}
public void afterSend() {
try {
if (!AuthDesc.isAuth())
return;
// 弹出上下文的栈顶中的元素
Span spanData = Context.removeLastSpan();
if (spanData == null) {
return;
}
// 加上花费时间
spanData.setCost(System.currentTimeMillis()
- spanData.getStartDate());
if (Config.BuriedPoint.PRINTF) {
logger.debug("TraceId:" + spanData.getTraceId()
+ "\tviewpointId:" + spanData.getViewPointId()
+ "\tParentLevelId:" + spanData.getParentLevel()
+ "\tLevelId:" + spanData.getLevelId()
+ "\tbusinessKey:" + spanData.getBusinessKey());
}
// 存放到本地发送进程中
if (!Config.Sender.IS_OFF) {
ContextBuffer.save(spanData);
}
} catch (Throwable t) {
logger.error(t.getMessage(), t);
}
}
}
......@@ -13,35 +13,49 @@ import com.ai.cloud.skywalking.model.Identification;
import com.ai.cloud.skywalking.protocol.Span;
import com.ai.cloud.skywalking.util.ContextGenerator;
public class RPCBuriedPointReceiver extends ApplicationExceptionHandler implements IBuriedPointReceiver {
private static Logger logger = LogManager.getLogger(RPCBuriedPointReceiver.class);
public void afterReceived() {
if (!AuthDesc.isAuth())
return;
// 获取上下文的栈顶中的元素
Span spanData = Context.removeLastSpan();
// 填上必要信息
spanData.setCost(System.currentTimeMillis() - spanData.getStartDate());
// 存放到本地发送进程中
ContextBuffer.save(spanData);
}
public void beforeReceived(ContextData context, Identification id) {
if (!AuthDesc.isAuth())
return;
Span spanData = ContextGenerator.generateSpanFromContextData(context, id);
//设置是否为接收端
spanData.setReceiver(true);
if (Config.BuriedPoint.PRINTF) {
logger.debug("TraceId:" + spanData.getTraceId() + "\tviewpointId:" + spanData.getViewPointId() + "\tParentLevelId:" + spanData.
getParentLevel() + "\tLevelId:" + spanData.getLevelId());
}
Context.append(spanData);
}
public class RPCBuriedPointReceiver extends ApplicationExceptionHandler
implements IBuriedPointReceiver {
private static Logger logger = LogManager
.getLogger(RPCBuriedPointReceiver.class);
public void afterReceived() {
try {
if (!AuthDesc.isAuth())
return;
// 获取上下文的栈顶中的元素
Span spanData = Context.removeLastSpan();
// 填上必要信息
spanData.setCost(System.currentTimeMillis()
- spanData.getStartDate());
// 存放到本地发送进程中
ContextBuffer.save(spanData);
} catch (Throwable t) {
logger.error(t.getMessage(), t);
}
}
public void beforeReceived(ContextData context, Identification id) {
try {
if (!AuthDesc.isAuth())
return;
Span spanData = ContextGenerator.generateSpanFromContextData(
context, id);
// 设置是否为接收端
spanData.setReceiver(true);
if (Config.BuriedPoint.PRINTF) {
logger.debug("TraceId:" + spanData.getTraceId()
+ "\tviewpointId:" + spanData.getViewPointId()
+ "\tParentLevelId:" + spanData.getParentLevel()
+ "\tLevelId:" + spanData.getLevelId());
}
Context.append(spanData);
} catch (Throwable t) {
logger.error(t.getMessage(), t);
}
}
}
......@@ -15,7 +15,13 @@ 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 ApplicationExceptionHandler implements IBuriedPointSender {
private static Logger logger = LogManager.getLogger(ThreadBuriedPointSender.class);
......
......@@ -14,6 +14,13 @@ 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 ApplicationExceptionHandler implements IBuriedPointSender {
private static Logger logger = LogManager.getLogger(ThreadBuriedPointSender.class);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册