wu-sheng opened a new issue #6915:
URL: https://github.com/apache/skywalking/issues/6915


   Hi @apache/skywalking-committers 
   
   We have a very stable and powerful plugin for 4 years, all of our plugins 
are being built on top of it. With more scenarios reported, I noticed there is 
a small gap we should fill.
   In `InstanceMethodsAroundInterceptor` and `StaticMethodsAroundInterceptor` 
have `before` and `after` methods, if we want to propagate information between 
them in one intercepting operation, we right now have
   1. Dynamic field
   2. RunnintContext
   3. Enhanced parameter
   
   But when we face concurrency calling of one instance, highly 
performance-sensitive, and only have `primitive data types` and `string` as 
parameter, all above three are not good options.
   
   So, we should consider to provide a new instance/static method interceptor 
API(v2) like this.
   ```java
   /**
    * A interceptor, which intercept method's invocation. The target methods 
will be defined in {@link
    * ClassEnhancePluginDefine}'s subclass, most likely in {@link 
ClassInstanceMethodsEnhancePluginDefine}
    */
   public interface InstanceMethodsAroundInterceptorV2 {
       /**
        * called before target method invocation.
        *
        * @param result change this result, if you want to truncate the method.
        */
       void beforeMethod(EnhancedInstance objInst, Method method, Object[] 
allArguments, Class<?>[] argumentsTypes,
           MethodInterceptResult result, MethodInvocationContext mic) throws 
Throwable;
   
       /**
        * called after target method invocation. Even method's invocation 
triggers an exception.
        *
        * @param ret the method's original return value. May be null if the 
method triggers an exception.
        * @return the method's actual return value.
        */
       Object afterMethod(EnhancedInstance objInst, Method method, Object[] 
allArguments, Class<?>[] argumentsTypes,
           Object ret, MethodInvocationContext mic) throws Throwable;
   
       /**
        * called when occur exception.
        *
        * @param t the exception occur.
        */
       void handleMethodException(EnhancedInstance objInst, Method method, 
Object[] allArguments,
           Class<?>[] argumentsTypes, Throwable t, MethodInvocationContext mic);
   }
   ```
   
   A new object of `class MethodInvocationContext` is shared per method 
invocation, which should be created and managed by core inter(s), such as 
`InstMethodsInter`.
   
   With this, we could share status in the method static and 100% isolation 
with other methods and static. When we use this with RuntimeContext, in 
`afterMethod` and `handleMethodException`, we could be easy to know whether 
some variable in the RunningContext is put or updated by `beforeMethod`.
   
   Notice, this change also affects the bootstrap instrumentation, so, we need 
the v2 inter templates too.
   
   ___
   To anyone who wants to handle this, you should know, this is a very core 
level API enhancement. We expect 100% forward compatibility and recommend the 
new plugin implementing new APIs. v1 may not be removed ever.
   
   This task only recommends to SkyWalking committer or you are confident you 
have already known SkyWalking's agent core very well. Newcomers, please don't 
try this.


-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to