Merge branch 'master' into feature/208-collectorside
This commit is contained in:
commit
fd5cb5e080
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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._
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
* <p>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue