diff --git a/samples/skywalking-auth/src/main/resources/sky-walking.auth b/samples/skywalking-auth/src/main/resources/sky-walking.auth index d53f3c163..4722c7c39 100644 --- a/samples/skywalking-auth/src/main/resources/sky-walking.auth +++ b/samples/skywalking-auth/src/main/resources/sky-walking.auth @@ -1,7 +1,7 @@ -#skyWalking用户ID +++++ +#skyWalking用户ID skywalking.user_id=123 -#skyWalking应用ID +++++ -skywalking.application_id=test +#skyWalking应用ID +skywalking.application_code=test #是否打印数据 buriedpoint.printf=false @@ -18,7 +18,7 @@ sender.servers_addr=127.0.0.1:34000 sender.max_copy_num=2 #发送的最大长度 sender.max_send_length=20000 -#当没有Sender时,尝试获取sender的等待周期 +++++ +#当没有Sender时,尝试获取sender的等待周期 sender.retry_get_sender_wait_interval=2000 #是否开启发送消息 sender.is_off=false @@ -28,7 +28,7 @@ sender.is_off=false consumer.max_consumer=2 #消费者最大等待时间 consumer.max_wait_time=5 -#发送失败等待时间 +++++++ +#发送失败等待时间 consumer.consumer_fail_retry_wait_interval=50 #每个Buffer的最大个数 @@ -36,6 +36,6 @@ buffer.buffer_max_size=18000 #Buffer池的最大长度 buffer.pool_size=5 -#发送检查线程检查周期 ++++++++ +#发送检查线程检查周期 senderchecker.check_polling_time=200 diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ApplicationExceptionHandler.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ApplicationExceptionHandler.java new file mode 100644 index 000000000..60e361129 --- /dev/null +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ApplicationExceptionHandler.java @@ -0,0 +1,35 @@ +package com.ai.cloud.skywalking.buriedpoint; + +import static com.ai.cloud.skywalking.conf.Config.BuriedPoint.EXCLUSIVE_EXCEPTIONS; + +import java.util.HashSet; +import java.util.Set; + +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 String EXCEPTION_SPLIT = ","; + + private static Set exclusiveExceptionSet = null; + + @Override + public void handleException(Throwable th) { + if (exclusiveExceptionSet == null) { + Set exclusiveExceptions = new HashSet(); + + String[] exceptions = EXCLUSIVE_EXCEPTIONS.split(EXCEPTION_SPLIT); + for(String exception : exceptions){ + exclusiveExceptions.add(exception); + } + exclusiveExceptionSet = exclusiveExceptions; + } + + Span span = Context.getLastSpan(); + span.handleException(th, exclusiveExceptionSet, + Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH); + } + +} diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/LocalBuriedPointSender.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/LocalBuriedPointSender.java index 472af2d44..f08af0a57 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/LocalBuriedPointSender.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/LocalBuriedPointSender.java @@ -14,7 +14,7 @@ import com.ai.cloud.skywalking.util.ContextGenerator; import java.util.logging.Level; import java.util.logging.Logger; -public class LocalBuriedPointSender implements IBuriedPointSender { +public class LocalBuriedPointSender extends ApplicationExceptionHandler implements IBuriedPointSender { private static Logger logger = Logger.getLogger(IBuriedPointSender.class.getName()); @@ -53,8 +53,5 @@ public class LocalBuriedPointSender implements IBuriedPointSender { } } - public void handleException(Throwable e) { - Span span = Context.getLastSpan(); - span.handleException(e, Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH); - } + public void handleException(Throwable e) {} } diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/RPCBuriedPointReceiver.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/RPCBuriedPointReceiver.java index 698fa342e..9d329f1c9 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/RPCBuriedPointReceiver.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/RPCBuriedPointReceiver.java @@ -1,5 +1,8 @@ package com.ai.cloud.skywalking.buriedpoint; +import java.util.logging.Level; +import java.util.logging.Logger; + import com.ai.cloud.skywalking.api.IBuriedPointReceiver; import com.ai.cloud.skywalking.buffer.ContextBuffer; import com.ai.cloud.skywalking.conf.AuthDesc; @@ -10,10 +13,7 @@ import com.ai.cloud.skywalking.model.Identification; import com.ai.cloud.skywalking.protocol.Span; import com.ai.cloud.skywalking.util.ContextGenerator; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class RPCBuriedPointReceiver implements IBuriedPointReceiver { +public class RPCBuriedPointReceiver extends ApplicationExceptionHandler implements IBuriedPointReceiver { private static Logger logger = Logger.getLogger(LocalBuriedPointSender.class.getName()); @@ -44,9 +44,4 @@ public class RPCBuriedPointReceiver implements IBuriedPointReceiver { Context.append(spanData); } - - public void handleException(Throwable e) { - Span span = Context.getLastSpan(); - span.handleException(e, Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH); - } } diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadBuriedPointSender.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadBuriedPointSender.java index 11562187a..2dda3ec1a 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadBuriedPointSender.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadBuriedPointSender.java @@ -15,7 +15,7 @@ import com.ai.cloud.skywalking.util.TraceIdGenerator; import java.util.logging.Level; import java.util.logging.Logger; -public class ThreadBuriedPointSender implements IBuriedPointSender { +public class ThreadBuriedPointSender extends ApplicationExceptionHandler implements IBuriedPointSender { private static Logger logger = Logger.getLogger(ThreadBuriedPointSender.class.getName()); @@ -71,8 +71,4 @@ public class ThreadBuriedPointSender implements IBuriedPointSender { } } - public void handleException(Throwable e) { - Span span = Context.getLastSpan(); - span.handleException(e, Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH); - } } diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadFactoryBuriedPointSender.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadFactoryBuriedPointSender.java index 8d22ed8e9..e3ef377ec 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadFactoryBuriedPointSender.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/buriedpoint/ThreadFactoryBuriedPointSender.java @@ -14,7 +14,7 @@ import com.ai.cloud.skywalking.util.ContextGenerator; import java.util.logging.Level; import java.util.logging.Logger; -public class ThreadFactoryBuriedPointSender implements IBuriedPointSender { +public class ThreadFactoryBuriedPointSender extends ApplicationExceptionHandler implements IBuriedPointSender { private static Logger logger = Logger.getLogger(ThreadBuriedPointSender.class.getName()); @@ -49,10 +49,4 @@ public class ThreadFactoryBuriedPointSender implements IBuriedPointSender { ContextBuffer.save(spanData); } } - - public void handleException(Throwable e) { - Span span = Context.getLastSpan(); - span.handleException(e, Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH); - - } } diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Config.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Config.java index c8d8b6efc..e87054aaa 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Config.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Config.java @@ -3,9 +3,9 @@ package com.ai.cloud.skywalking.conf; public class Config { public static class SkyWalking { - public static String USER_ID; + public static String USER_ID = ""; - public static String APPLICATION_CODE; + public static String APPLICATION_CODE = ""; } public static class BuriedPoint { @@ -16,6 +16,9 @@ public class Config { // Business Key 最大长度 public static int BUSINESSKEY_MAX_LENGTH = 300; + + // 使用逗号分离 + public static String EXCLUSIVE_EXCEPTIONS = ""; } public static class Consumer { diff --git a/skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java b/skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java index 32a752b60..72c859b70 100644 --- a/skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java +++ b/skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java @@ -1,156 +1,170 @@ package com.ai.cloud.skywalking.protocol; - import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; public class Span extends SpanData { - private Logger logger = Logger.getLogger(Span.class.getName()); + private Logger logger = Logger.getLogger(Span.class.getName()); - public Span() { - } + public Span() { + } - public Span(String traceId, String applicationID, String userId) { - this.traceId = traceId; - this.applicationId = applicationID; - this.userId = userId; - } + public Span(String traceId, String applicationID, String userId) { + this.traceId = traceId; + this.applicationId = applicationID; + this.userId = userId; + } - public Span(String traceId, String parentLevelId, int levelId, String applicationID, String userId) { - this.traceId = traceId; - this.applicationId = applicationID; - this.parentLevel = parentLevelId; - this.userId = userId; - this.levelId = levelId; - } + public Span(String traceId, String parentLevelId, int levelId, + String applicationID, String userId) { + this.traceId = traceId; + this.applicationId = applicationID; + this.parentLevel = parentLevelId; + this.userId = userId; + this.levelId = levelId; + } - public Span(String originData) { - String[] fieldValues = originData.split(SPAN_FIELD_SPILT_PATTERN); - traceId = fieldValues[0].trim(); - parentLevel = fieldValues[1].trim(); - levelId = Integer.valueOf(fieldValues[2]); - viewPointId = fieldValues[3].trim(); - startDate = Long.valueOf(fieldValues[4]); - cost = Long.parseLong(fieldValues[5]); - address = fieldValues[6].trim(); - statusCode = Byte.valueOf(fieldValues[7].trim()); - //异常情况才会存在exceptionStack - if (statusCode == 1) { - exceptionStack = fieldValues[8].trim().replaceAll(SPAN_ATTR_SPILT_CHARACTER, - NEW_LINE_CHARACTER_PATTERN); - } - spanType = fieldValues[9]; - isReceiver = Boolean.valueOf(fieldValues[10]); + public Span(String originData) { + String[] fieldValues = originData.split(SPAN_FIELD_SPILT_PATTERN); + traceId = fieldValues[0].trim(); + parentLevel = fieldValues[1].trim(); + levelId = Integer.valueOf(fieldValues[2]); + viewPointId = fieldValues[3].trim(); + startDate = Long.valueOf(fieldValues[4]); + cost = Long.parseLong(fieldValues[5]); + address = fieldValues[6].trim(); + statusCode = Byte.valueOf(fieldValues[7].trim()); + // 异常情况才会存在exceptionStack + if (statusCode == 1) { + exceptionStack = fieldValues[8].trim().replaceAll( + SPAN_ATTR_SPILT_CHARACTER, NEW_LINE_CHARACTER_PATTERN); + } + spanType = fieldValues[9]; + isReceiver = Boolean.valueOf(fieldValues[10]); - businessKey = fieldValues[11].trim().replaceAll(SPAN_ATTR_SPILT_CHARACTER, - NEW_LINE_CHARACTER_PATTERN); - processNo = fieldValues[12].trim(); - applicationId = fieldValues[13].trim(); - userId = fieldValues[14].trim(); - this.originData = originData; - } + businessKey = fieldValues[11].trim().replaceAll( + SPAN_ATTR_SPILT_CHARACTER, NEW_LINE_CHARACTER_PATTERN); + processNo = fieldValues[12].trim(); + applicationId = fieldValues[13].trim(); + userId = fieldValues[14].trim(); + this.originData = originData; + } + @Override + public String toString() { + StringBuilder toStringValue = new StringBuilder(); + toStringValue.append(traceId + SPAN_FIELD_SPILT_PATTERN); - @Override - public String toString() { - StringBuilder toStringValue = new StringBuilder(); - toStringValue.append(traceId + SPAN_FIELD_SPILT_PATTERN); + if (isNonBlank(parentLevel)) { + toStringValue.append(parentLevel + SPAN_FIELD_SPILT_PATTERN); + } else { + toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); + } - if (isNonBlank(parentLevel)) { - toStringValue.append(parentLevel + SPAN_FIELD_SPILT_PATTERN); - } else { - toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); - } + toStringValue.append(levelId + SPAN_FIELD_SPILT_PATTERN); - toStringValue.append(levelId + SPAN_FIELD_SPILT_PATTERN); + if (isNonBlank(viewPointId)) { + toStringValue.append(viewPointId + SPAN_FIELD_SPILT_PATTERN); + } else { + toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); + } - if (isNonBlank(viewPointId)) { - toStringValue.append(viewPointId + SPAN_FIELD_SPILT_PATTERN); - } else { - toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); - } + toStringValue.append(startDate + SPAN_FIELD_SPILT_PATTERN); + toStringValue.append(cost + SPAN_FIELD_SPILT_PATTERN); - toStringValue.append(startDate + SPAN_FIELD_SPILT_PATTERN); - toStringValue.append(cost + SPAN_FIELD_SPILT_PATTERN); + if (isNonBlank(address)) { + toStringValue.append(address + SPAN_FIELD_SPILT_PATTERN); + } else { + toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); + } - if (isNonBlank(address)) { - toStringValue.append(address + SPAN_FIELD_SPILT_PATTERN); - } else { - toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); - } + toStringValue.append(statusCode + SPAN_FIELD_SPILT_PATTERN); - toStringValue.append(statusCode + SPAN_FIELD_SPILT_PATTERN); + if (isNonBlank(exceptionStack)) { + // 换行符在各个系统中表现不一致, + // windows平台的换行符为/r/n + // linux平台的换行符为/n + toStringValue.append(exceptionStack.replaceAll( + CARRIAGE_RETURN_CHARACTER_PATTERN, "").replaceAll( + NEW_LINE_CHARACTER_PATTERN, SPAN_ATTR_SPILT_CHARACTER) + + SPAN_FIELD_SPILT_PATTERN); + } else { + toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); + } - if (isNonBlank(exceptionStack)) { - //换行符在各个系统中表现不一致, - //windows平台的换行符为/r/n - //linux平台的换行符为/n - toStringValue.append(exceptionStack.replaceAll(CARRIAGE_RETURN_CHARACTER_PATTERN, "") - .replaceAll(NEW_LINE_CHARACTER_PATTERN, SPAN_ATTR_SPILT_CHARACTER) - + SPAN_FIELD_SPILT_PATTERN); - } else { - toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); - } + toStringValue.append(spanType + SPAN_FIELD_SPILT_PATTERN); + toStringValue.append(isReceiver + SPAN_FIELD_SPILT_PATTERN); - toStringValue.append(spanType + SPAN_FIELD_SPILT_PATTERN); - toStringValue.append(isReceiver + SPAN_FIELD_SPILT_PATTERN); + if (isNonBlank(businessKey)) { + // 换行符在各个系统中表现不一致, + // windows平台的换行符为/r/n + // linux平台的换行符为/n + toStringValue.append(businessKey.replaceAll( + CARRIAGE_RETURN_CHARACTER_PATTERN, "").replaceAll( + NEW_LINE_CHARACTER_PATTERN, SPAN_ATTR_SPILT_CHARACTER) + + SPAN_FIELD_SPILT_PATTERN); + } else { + toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); + } + if (isNonBlank(processNo)) { + toStringValue.append(processNo + SPAN_FIELD_SPILT_PATTERN); + } else { + toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); + } - if (isNonBlank(businessKey)) { - //换行符在各个系统中表现不一致, - //windows平台的换行符为/r/n - //linux平台的换行符为/n - toStringValue.append(businessKey.replaceAll(CARRIAGE_RETURN_CHARACTER_PATTERN, "") - .replaceAll(NEW_LINE_CHARACTER_PATTERN, SPAN_ATTR_SPILT_CHARACTER) - + SPAN_FIELD_SPILT_PATTERN); - } else { - toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); - } + if (isNonBlank(applicationId)) { + toStringValue.append(applicationId + SPAN_FIELD_SPILT_PATTERN); + } else { + toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); + } - if (isNonBlank(processNo)) { - toStringValue.append(processNo + SPAN_FIELD_SPILT_PATTERN); - } else { - toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); - } + if (isNonBlank(userId)) { + toStringValue.append(userId); + } else { + toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); + } - if (isNonBlank(applicationId)) { - toStringValue.append(applicationId + SPAN_FIELD_SPILT_PATTERN); - } else { - toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); - } + return toStringValue.toString(); + } - if (isNonBlank(userId)) { - toStringValue.append(userId); - } else { - toStringValue.append(" " + SPAN_FIELD_SPILT_PATTERN); - } + protected boolean isNonBlank(String str) { + return str != null && str.length() > 0; + } - return toStringValue.toString(); - } + public void handleException(Throwable e, Set exclusiveExceptionSet, + int maxExceptionStackLength) { + ByteArrayOutputStream buf = null; + StringBuilder expMessage = new StringBuilder(); + try { + buf = new ByteArrayOutputStream(); + Throwable causeException = e; + while (causeException != null + && (causeException.getCause() != null || expMessage + .length() < maxExceptionStackLength)) { + causeException.printStackTrace(new java.io.PrintWriter(buf, + true)); + expMessage.append(buf.toString()); + causeException = causeException.getCause(); + } - protected boolean isNonBlank(String str) { - return str != null && str.length() > 0; - } + } finally { + try { + buf.close(); + } catch (IOException ioe) { + logger.log(Level.ALL, + "Close exception stack input stream failed", ioe); + } + } + this.exceptionStack = expMessage.toString(); - public void handleException(Throwable e, int maxExceptionStackLength) { - this.statusCode = 1; - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - StringBuilder expMessage = new StringBuilder(); - Throwable causeException = e; - while (causeException != null && (causeException.getCause() != null || expMessage.length() < maxExceptionStackLength)) { - causeException.printStackTrace(new java.io.PrintWriter(buf, true)); - expMessage.append(buf.toString()); - causeException = causeException.getCause(); - } - try { - buf.close(); - } catch (IOException e1) { - logger.log(Level.ALL, "Close exception stack input stream failed"); - } - this.exceptionStack = expMessage.toString(); - } + if (!exclusiveExceptionSet.contains(e.getClass().getName())) { + this.statusCode = 1; + } + } }