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 2022/02/19 08:39:37 UTC

[GitHub] [skywalking] creeew opened a new issue #8561: [Bug] SkyWalking Java agent plugin InstanceMethodsInterceptPoint method match failed

creeew opened a new issue #8561:
URL: https://github.com/apache/skywalking/issues/8561


   ### Search before asking
   
   - [X] I had searched in the [issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no similar issues.
   
   
   ### Apache SkyWalking Component
   
   Java Agent (apache/skywalking-java)
   
   ### What happened
   
   I following the doc to build my SkyWalking plugin in Java agent, unfortunately there are some ElementMatchers match way cannot work correctly.
   In InstanceMethodsInterceptPoint#getMethodsMatcher everything is alright if you using ElementMatchers.named to match a method. But in nameContains/nameEndsWith/nameMatches cannot match the method which should be match.
   
   ### What you expected to happen
   
   InstanceMethodsInterceptPoint match method correctlly
   
   ### How to reproduce
   
   `
   public class TestInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
   
       private static final String ENHANCE_CLASS = "test.plugin.TestService";
       private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.test.TestInterceptor";
   
       @Override
       protected ClassMatch enhanceClass() {
           return NameMatch.byName(ENHANCE_CLASS);
       }
   
       @Override
       public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
           return null;
       }
   
       @Override
       public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
           return new InstanceMethodsInterceptPoint[] {
               new InstanceMethodsInterceptPoint() {
                   @Override
                   public ElementMatcher<MethodDescription> getMethodsMatcher() {
                       // success
                       //  return named("testPublicMethod");
                       // return ElementMatchers.nameStartsWith("t");
                       // return ElementMatchers.nameMatches("testPublicMethod");
   
                       // fail
                       return ElementMatchers.nameContains("t");
                      // return ElementMatchers.nameEndsWith("d");
                      // return ElementMatchers.nameMatches("[a-zA-Z0-9_$]+");
                   }
   
                   @Override
                   public String getMethodsInterceptor() {
                       return INTERCEPT_CLASS;
                   }
   
                   @Override
                   public boolean isOverrideArgs() {
                       return false;
                   }
               }
           };
       }
   }
   `
   my method name is "testPublicMethod", those failed code like nameContain and endsWith should be match my method.
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org