diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index 1c12100b1..9efab982b 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -88,6 +88,11 @@ public class Config { * The identify of the instance */ public static String INSTANCE_UUID = ""; + + /** + * How depth the agent goes, when log cause exceptions. + */ + public static int CAUSE_EXCEPTION_DEPTH = 5; } public static class Collector { diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java index b5f4ef179..ea02f45cb 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/util/ThrowableTransformer.java @@ -19,6 +19,8 @@ package org.apache.skywalking.apm.agent.core.context.util; +import static org.apache.skywalking.apm.agent.core.conf.Config.Agent.CAUSE_EXCEPTION_DEPTH; + /** * {@link ThrowableTransformer} is responsible for transferring stack trace of throwable. */ @@ -30,10 +32,12 @@ public enum ThrowableTransformer { public String convert2String(Throwable throwable, final int maxLength) { final StringBuilder stackMessage = new StringBuilder(); Throwable causeException = throwable; - while (causeException != null) { + + int depth = CAUSE_EXCEPTION_DEPTH; + while (causeException != null && depth != 0) { stackMessage.append(printExceptionInfo(causeException)); - boolean overMaxLength = printStackElement(throwable.getStackTrace(), new AppendListener() { + boolean isLookDeeper = printStackElement(causeException.getStackTrace(), new AppendListener() { public void append(String value) { stackMessage.append(value); } @@ -43,11 +47,12 @@ public enum ThrowableTransformer { } }); - if (overMaxLength) { + if (isLookDeeper) { break; } - causeException = throwable.getCause(); + causeException = causeException.getCause(); + depth--; } return stackMessage.toString(); @@ -58,6 +63,14 @@ public enum ThrowableTransformer { } private boolean printStackElement(StackTraceElement[] stackTrace, AppendListener printListener) { + if (stackTrace.length == 0) { + /** + * In some cases, people would fill empty stackTrace intentionally. + * This is a quick stop. + */ + return true; + } + for (StackTraceElement traceElement : stackTrace) { printListener.append("at " + traceElement + LINE_SEPARATOR); if (printListener.overMaxLength()) { diff --git a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java index 516c1cdf2..39c396d96 100644 --- a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java +++ b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java @@ -18,6 +18,8 @@ package org.apache.skywalking.apm.agent; +import java.lang.instrument.Instrumentation; +import java.util.List; import net.bytebuddy.ByteBuddy; import net.bytebuddy.agent.builder.AgentBuilder; import net.bytebuddy.description.NamedElement; @@ -34,12 +36,15 @@ import org.apache.skywalking.apm.agent.core.conf.ConfigNotFoundException; import org.apache.skywalking.apm.agent.core.conf.SnifferConfigInitializer; import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.LogManager; -import org.apache.skywalking.apm.agent.core.plugin.*; +import org.apache.skywalking.apm.agent.core.plugin.AbstractClassEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.EnhanceContext; +import org.apache.skywalking.apm.agent.core.plugin.PluginBootstrap; +import org.apache.skywalking.apm.agent.core.plugin.PluginException; +import org.apache.skywalking.apm.agent.core.plugin.PluginFinder; -import java.lang.instrument.Instrumentation; -import java.util.List; - -import static net.bytebuddy.matcher.ElementMatchers.*; +import static net.bytebuddy.matcher.ElementMatchers.nameContains; +import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; +import static net.bytebuddy.matcher.ElementMatchers.not; /** * The main entrance of sky-walking agent, based on javaagent mechanism. @@ -80,14 +85,14 @@ public class SkyWalkingAgent { new AgentBuilder.Default(byteBuddy) .ignore( nameStartsWith("net.bytebuddy.") - .or(nameStartsWith("org.slf4j.")) - .or(nameStartsWith("org.apache.logging.")) - .or(nameStartsWith("org.groovy.")) - .or(nameContains("javassist")) - .or(nameContains(".asm.")) - .or(nameStartsWith("sun.reflect")) - .or(allSkyWalkingAgentExcludeToolkit()) - .or(ElementMatchers.isSynthetic())) + .or(nameStartsWith("org.slf4j.")) + .or(nameStartsWith("org.apache.logging.")) + .or(nameStartsWith("org.groovy.")) + .or(nameContains("javassist")) + .or(nameContains(".asm.")) + .or(nameStartsWith("sun.reflect")) + .or(allSkyWalkingAgentExcludeToolkit()) + .or(ElementMatchers.isSynthetic())) .type(pluginFinder.buildMatch()) .transform(new Transformer(pluginFinder)) .with(new Listener()) diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md index 2d18851c3..247dd4384 100644 --- a/docs/en/setup/service-agent/java-agent/README.md +++ b/docs/en/setup/service-agent/java-agent/README.md @@ -65,6 +65,7 @@ property key | Description | Default | `agent.is_open_debugging_class`|If true, skywalking agent will save all instrumented classes files in `/debugging` folder.Skywalking team may ask for these files in order to resolve compatible problem.|Not set| `agent.active_v2_header`|Active V2 header in default.|`true`| `agent.instance_uuid` |Instance uuid is the identity of an instance, skywalking treat same instance uuid as one instance.if empty, skywalking agent will generate an 32-bit uuid. |`""`| +`agent.cause_exception_depth`|How depth the agent goes, when log all cause exceptions.|5| `agent.active_v1_header `|Deactive V1 header in default.|`false`| `collector.grpc_channel_check_interval`|grpc channel status check interval.|`30`| `collector.app_and_service_register_check_interval`|application and service registry check interval.|`3`|