You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2018/11/15 04:25:13 UTC

[GitHub] honganan opened a new issue #1912: multi ignore() calls in AgentBuilder.Default would be overrided by the last one

honganan opened a new issue #1912: multi ignore() calls in AgentBuilder.Default would be overrided by the last one
URL: https://github.com/apache/incubator-skywalking/issues/1912
 
 
   In class SkyWalkingAgent, there is a code fragment like this:
   `new AgentBuilder.Default(byteBuddy)
               .ignore(nameStartsWith("net.bytebuddy."))
               .ignore(nameStartsWith("org.slf4j."))
               .ignore(nameStartsWith("org.apache.logging."))
               .ignore(nameStartsWith("org.groovy."))
               .ignore(nameContains("javassist"))
               .ignore(nameContains(".asm."))
               .ignore(allSkyWalkingAgentExcludeToolkit())
               .type(pluginFinder.buildMatch())
               .transform(new Transformer(pluginFinder))
               .with(new Listener())
               .installOn(instrumentation);`
   I read the Bytebuddy source code and found every ignore() from the second invoke like above would create a new AgentBuilder.Default object, and the ElementMatcher does not merge with the previous one. Then only the last ignore ElementMatcher is worked, and the previous calls was overrided.
   Here is what I read from Bytebuddy's logic:
   1. AgentBuilder.Default(byteBuddy).ignore(...), returns a new Ignoring Object which  extends Delegator
   2. the second ignore(...) calls in Delegator likes
   `return materialize().ignore(ignoredTypes) `
   the meterialize(implements in Ignoring class) returns a new Default object, and then the ignore(...) calls the new Default's ignore method, the overriding occurs.
   
   We use skywalking's enhance model indirectly in our apm system in an attach agent way, and caught exception here. After read the source code, We resolve it by use one ignore(...) with Disjunctions like the under fragment:
   `new AgentBuilder.Default()
               .ignore(nameStartsWith("net.bytebuddy.")
                   .or(nameStartsWith("org.slf4j."))
                   .or(nameStartsWith("ch.qos.logback."))
                   .or(nameStartsWith("org.apache.logging."))
                   .or(nameStartsWith("org.groovy."))
                   .or(nameContains("javassist"))
                   .or(nameContains(".asm."))
                   .or(allSkyWalkingAgentExcludeToolkit())
                   .or(nameStartsWith("sun.reflect."))
                   .or(isSynthetic())
               )
               .type(pluginFinder.buildMatch())
               .transform(new Transformer(pluginFinder))
               .with(new Listener())
               .installOnByteBuddyAgent();`
   The key fragment caught this is `.or(nameStartsWith("sun.reflect."))` which cause the `java.lang.NoClassDefFoundError: java/lang/Throwable$WrappedPrintWriter`. Also Bytebuddy adds `isBootstrapClassLoader()` in the ignore. I am not sure how to use this in my code yet.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services