diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE index 66d96ec47..79a3bb232 100644 --- a/.github/ISSUE_TEMPLATE +++ b/.github/ISSUE_TEMPLATE @@ -9,5 +9,8 @@ Please answer these questions before submitting your issue. ### What version of your JRE? +### What company or project? + + ### What did you do? If possible, provide a way for reproducing the error. e.g. demo application, component version. diff --git a/README.md b/README.md index b8c36dca7..f02b99e96 100644 --- a/README.md +++ b/README.md @@ -55,5 +55,3 @@ _In chronological order_ * [WIKI](https://github.com/wu-sheng/sky-walking/wiki) _Chat with us on gitter, in English. As a Chinese Developer, you can join QQ Group: 392443393, by **tagging** Sky-Walking._ - -_sky-walking 1.x and 2.x provide features about tracing only, did not include any analysis abilities._ diff --git a/apm-commons/apm-trace/src/main/java/org/skywalking/apm/trace/Span.java b/apm-commons/apm-trace/src/main/java/org/skywalking/apm/trace/Span.java index e256f73f3..7dbda233a 100644 --- a/apm-commons/apm-trace/src/main/java/org/skywalking/apm/trace/Span.java +++ b/apm-commons/apm-trace/src/main/java/org/skywalking/apm/trace/Span.java @@ -3,9 +3,8 @@ package org.skywalking.apm.trace; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.util.*; +import org.skywalking.apm.trace.util.ThrowableTransformer; /** * Span is a concept from OpenTracing Spec, also from Google Dapper Paper. @@ -290,32 +289,6 @@ public class Span { return log(exceptionFields); } - private enum ThrowableTransformer { - INSTANCE; - - private String convert2String(Throwable e, int maxLength) { - ByteArrayOutputStream buf = null; - StringBuilder expMessage = new StringBuilder(); - try { - buf = new ByteArrayOutputStream(); - Throwable causeException = e; - while (expMessage.length() < maxLength && causeException != null) { - causeException.printStackTrace(new java.io.PrintWriter(buf, true)); - expMessage.append(buf.toString()); - causeException = causeException.getCause(); - } - - } finally { - try { - buf.close(); - } catch (IOException ioe) { - } - } - - return (maxLength > expMessage.length() ? expMessage : expMessage.substring(0, maxLength)).toString(); - } - } - /** * This method is from opentracing-java. {@see https://github.com/opentracing/opentracing-java/blob/release-0.20.9/opentracing-api/src/main/java/io/opentracing/Span.java#L120} *
diff --git a/apm-commons/apm-trace/src/main/java/org/skywalking/apm/trace/util/ThrowableTransformer.java b/apm-commons/apm-trace/src/main/java/org/skywalking/apm/trace/util/ThrowableTransformer.java new file mode 100644 index 000000000..707d9263f --- /dev/null +++ b/apm-commons/apm-trace/src/main/java/org/skywalking/apm/trace/util/ThrowableTransformer.java @@ -0,0 +1,56 @@ +package org.skywalking.apm.trace.util; + +/** + * {@link ThrowableTransformer} is responsible for transferring stack trace of throwable. + */ +public enum ThrowableTransformer { + INSTANCE; + + private static final String LINE_SEPARATOR = System.getProperty("line.separator"); + + public String convert2String(Throwable throwable, final int maxLength) { + final StringBuilder stackMessage = new StringBuilder(); + Throwable causeException = throwable; + while (causeException != null) { + stackMessage.append(printExceptionInfo(causeException)); + + boolean overMaxLength = printStackElement(throwable.getStackTrace(), new AppendListener() { + public void append(String value) { + stackMessage.append(value); + } + + public boolean overMaxLength() { + return stackMessage.length() > maxLength; + } + }); + + if (overMaxLength) { + break; + } + + causeException = throwable.getCause(); + } + + return stackMessage.toString(); + } + + private String printExceptionInfo(Throwable causeException) { + return causeException.toString() + LINE_SEPARATOR; + } + + private boolean printStackElement(StackTraceElement[] stackTrace, AppendListener printListener) { + for (StackTraceElement traceElement : stackTrace) { + printListener.append("at " + traceElement + LINE_SEPARATOR); + if (printListener.overMaxLength()) { + return true; + } + } + return false; + } + + private interface AppendListener { + void append(String value); + + boolean overMaxLength(); + } +}