Merge branch 'master' into feature/sampling
* master: add message/stack length check when skywalking convert throwable stack to string. Delete _config.yml # Conflicts: # apm-commons/apm-trace/src/main/java/org/skywalking/apm/trace/Span.java
This commit is contained in:
commit
b8e1bd32c9
|
|
@ -1 +0,0 @@
|
|||
theme: jekyll-theme-tactile
|
||||
|
|
@ -7,7 +7,6 @@ import com.google.gson.TypeAdapter;
|
|||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -17,6 +16,7 @@ import java.util.Map;
|
|||
import org.skywalking.apm.trace.tag.BooleanTagItem;
|
||||
import org.skywalking.apm.trace.tag.IntTagItem;
|
||||
import org.skywalking.apm.trace.tag.StringTagItem;
|
||||
import org.skywalking.apm.trace.util.ThrowableTransformer;
|
||||
import org.skywalking.apm.util.StringUtil;
|
||||
|
||||
/**
|
||||
|
|
@ -269,32 +269,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> Record an event at the current walltime timestamp. <p> Shorthand for <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