You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/04/06 01:06:05 UTC

[skywalking] branch master updated: Support @Trace, @Tag and @Tags work for static methods (#6685)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 411bcf2  Support @Trace, @Tag and @Tags work for static methods (#6685)
411bcf2 is described below

commit 411bcf230d3624029ff5daf33edbade91bebff26
Author: liqiangz <li...@gmail.com>
AuthorDate: Tue Apr 6 09:04:38 2021 +0800

    Support @Trace, @Tag and @Tags work for static methods (#6685)
---
 CHANGES.md                                         |  1 +
 ...ptor.java => BaseTagAnnotationInterceptor.java} | 33 +++--------
 ...or.java => BaseTraceAnnotationInterceptor.java} | 36 ++++--------
 .../activation/trace/TagAnnotationActivation.java  | 28 ++++++++-
 .../trace/TagAnnotationMethodInterceptor.java      | 67 ++++------------------
 .../TagAnnotationStaticMethodInterceptor.java      | 45 +++++++++++++++
 .../trace/TraceAnnotationActivation.java           | 28 ++++++++-
 .../trace/TraceAnnotationMethodInterceptor.java    | 60 ++-----------------
 .../TraceAnnotationStaticMethodInterceptor.java    | 45 +++++++++++++++
 .../config/expectedData.yaml                       | 15 +++++
 .../toolkit/controller/TestController.java         |  1 +
 .../testcase/toolkit/controller/TestService.java   |  8 +++
 12 files changed, 203 insertions(+), 164 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index b4b12e4..c1e5075 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -32,6 +32,7 @@ Release Notes.
 * Fix springmvc reactive api can't collect HTTP statusCode.
 * Fix bug that asynchttpclient plugin does not record the response status code.
 * Fix spanLayer is null in optional plugin(gateway-2.0.x-plugin gateway-2.1.x-plugin).
+* Support @Trace, @Tag and @Tags work for static methods.
 
 #### OAP-Backend
 * Allow user-defined `JAVA_OPTS` in the startup script.
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/BaseTagAnnotationInterceptor.java
similarity index 73%
copy from apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationMethodInterceptor.java
copy to apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/BaseTagAnnotationInterceptor.java
index 50ef219..fa123a0 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationMethodInterceptor.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/BaseTagAnnotationInterceptor.java
@@ -18,28 +18,21 @@
 
 package org.apache.skywalking.apm.toolkit.activation.trace;
 
-import java.lang.reflect.Method;
-import java.util.Map;
-
 import org.apache.skywalking.apm.agent.core.context.ContextManager;
 import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
-import org.apache.skywalking.apm.toolkit.activation.util.TagUtil;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
 import org.apache.skywalking.apm.agent.core.util.CustomizeExpression;
+import org.apache.skywalking.apm.toolkit.activation.util.TagUtil;
 import org.apache.skywalking.apm.toolkit.trace.Tag;
 import org.apache.skywalking.apm.toolkit.trace.Tags;
 
-public class TagAnnotationMethodInterceptor implements InstanceMethodsAroundInterceptor {
-    @Override
-    public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
-        final Class<?>[] argumentsTypes, final MethodInterceptResult result) {
+import java.lang.reflect.Method;
+import java.util.Map;
 
+public class BaseTagAnnotationInterceptor {
+    void beforeMethod(Method method, Object[] allArguments) {
         if (!ContextManager.isActive()) {
             return;
         }
-
         final AbstractSpan activeSpan = ContextManager.activeSpan();
         final Map<String, Object> context = CustomizeExpression.evaluationContext(allArguments);
 
@@ -51,22 +44,15 @@ public class TagAnnotationMethodInterceptor implements InstanceMethodsAroundInte
                 }
             }
         }
-
         final Tag tag = method.getAnnotation(Tag.class);
         if (tag != null && !TagUtil.isReturnTag(tag.value())) {
             TagUtil.tagParamsSpan(activeSpan, context, tag);
         }
     }
 
-    @Override
-    public Object afterMethod(
-        final EnhancedInstance objInst,
-        final Method method,
-        final Object[] allArguments,
-        final Class<?>[] argumentsTypes,
-        final Object ret) {
+    void afterMethod(Method method, Object ret) {
         if (ret == null || !ContextManager.isActive()) {
-            return ret;
+            return;
         }
         final AbstractSpan localSpan = ContextManager.activeSpan();
         final Map<String, Object> context = CustomizeExpression.evaluationReturnContext(ret);
@@ -82,12 +68,9 @@ public class TagAnnotationMethodInterceptor implements InstanceMethodsAroundInte
         if (tag != null && TagUtil.isReturnTag(tag.value())) {
             TagUtil.tagReturnSpanSpan(localSpan, context, tag);
         }
-        return ret;
     }
 
-    @Override
-    public void handleMethodException(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
-        final Class<?>[] argumentsTypes, final Throwable t) {
+    void handleMethodException(Throwable t) {
         if (ContextManager.isActive()) {
             ContextManager.activeSpan().log(t);
         }
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/BaseTraceAnnotationInterceptor.java
similarity index 70%
copy from apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java
copy to apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/BaseTraceAnnotationInterceptor.java
index e11a1f7..08f47e5 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/BaseTraceAnnotationInterceptor.java
@@ -18,13 +18,8 @@
 
 package org.apache.skywalking.apm.toolkit.activation.trace;
 
-import java.lang.reflect.Method;
-import java.util.Map;
 import org.apache.skywalking.apm.agent.core.context.ContextManager;
 import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
 import org.apache.skywalking.apm.agent.core.util.CustomizeExpression;
 import org.apache.skywalking.apm.agent.core.util.MethodUtil;
 import org.apache.skywalking.apm.toolkit.activation.ToolkitPluginConfig;
@@ -33,15 +28,11 @@ import org.apache.skywalking.apm.toolkit.trace.Tag;
 import org.apache.skywalking.apm.toolkit.trace.Tags;
 import org.apache.skywalking.apm.toolkit.trace.Trace;
 
-/**
- * {@link TraceAnnotationMethodInterceptor} create a local span and set the operation name which fetch from
- * <code>org.apache.skywalking.apm.toolkit.trace.annotation.Trace.operationName</code>. if the fetch value is blank
- * string, and the operation name will be the method name.
- */
-public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundInterceptor {
-    @Override
-    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
-                             MethodInterceptResult result) throws Throwable {
+import java.lang.reflect.Method;
+import java.util.Map;
+
+public class BaseTraceAnnotationInterceptor {
+    void beforeMethod(Method method, Object[] allArguments) {
         Trace trace = method.getAnnotation(Trace.class);
         String operationName = trace.operationName();
         if (operationName.length() == 0 || ToolkitPluginConfig.Plugin.Toolkit.USE_QUALIFIED_NAME_AS_OPERATION_NAME) {
@@ -52,7 +43,7 @@ public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundIn
 
         final Map<String, Object> context = CustomizeExpression.evaluationContext(allArguments);
 
-        final Tags tags = method.getAnnotation(Tags.class);
+        final org.apache.skywalking.apm.toolkit.trace.Tags tags = method.getAnnotation(Tags.class);
         if (tags != null && tags.value().length > 0) {
             for (final Tag tag : tags.value()) {
                 if (!TagUtil.isReturnTag(tag.value())) {
@@ -66,12 +57,10 @@ public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundIn
         }
     }
 
-    @Override
-    public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
-                              Object ret) throws Throwable {
+    void afterMethod(Method method, Object ret) {
         try {
             if (ret == null) {
-                return ret;
+                return;
             }
             final AbstractSpan localSpan = ContextManager.activeSpan();
             final Map<String, Object> context = CustomizeExpression.evaluationReturnContext(ret);
@@ -90,12 +79,11 @@ public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundIn
         } finally {
             ContextManager.stopSpan();
         }
-        return ret;
     }
 
-    @Override
-    public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
-                                      Class<?>[] argumentsTypes, Throwable t) {
-        ContextManager.activeSpan().log(t);
+    void handleMethodException(Throwable t) {
+        if (ContextManager.isActive()) {
+            ContextManager.activeSpan().log(t);
+        }
     }
 }
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationActivation.java
index fcab17b..b6b952a 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationActivation.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationActivation.java
@@ -23,7 +23,8 @@ import net.bytebuddy.matcher.ElementMatcher;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.DeclaredInstanceMethodsInterceptPoint;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine;
 import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
 
 import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith;
@@ -36,9 +37,10 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.logical.LogicalM
 /**
  * Intercepts all methods annotated with {@link org.apache.skywalking.apm.toolkit.trace.Tag}
  */
-public class TagAnnotationActivation extends ClassInstanceMethodsEnhancePluginDefine {
+public class TagAnnotationActivation extends ClassEnhancePluginDefine {
 
     public static final String TAG_ANNOTATION_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.toolkit.activation.trace.TagAnnotationMethodInterceptor";
+    public static final String TAG_ANNOTATION_STATIC_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.toolkit.activation.trace.TagAnnotationStaticMethodInterceptor";
     public static final String TAG_ANNOTATION = "org.apache.skywalking.apm.toolkit.trace.Tag";
     public static final String TAGS_ANNOTATION = "org.apache.skywalking.apm.toolkit.trace.Tags";
     public static final String TRACE_ANNOTATION = "org.apache.skywalking.apm.toolkit.trace.Trace";
@@ -71,6 +73,28 @@ public class TagAnnotationActivation extends ClassInstanceMethodsEnhancePluginDe
     }
 
     @Override
+    public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
+        return new StaticMethodsInterceptPoint[]{
+                new StaticMethodsInterceptPoint() {
+                    @Override
+                    public ElementMatcher<MethodDescription> getMethodsMatcher() {
+                        return isAnnotatedWith(named(TAG_ANNOTATION));
+                    }
+
+                    @Override
+                    public String getMethodsInterceptor() {
+                        return TAG_ANNOTATION_STATIC_METHOD_INTERCEPTOR;
+                    }
+
+                    @Override
+                    public boolean isOverrideArgs() {
+                        return false;
+                    }
+                }
+        };
+    }
+
+    @Override
     protected ClassMatch enhanceClass() {
         return and(not(byMethodAnnotationMatch(TRACE_ANNOTATION)),
 
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationMethodInterceptor.java
index 50ef219..07b025b 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationMethodInterceptor.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationMethodInterceptor.java
@@ -19,77 +19,32 @@
 package org.apache.skywalking.apm.toolkit.activation.trace;
 
 import java.lang.reflect.Method;
-import java.util.Map;
 
-import org.apache.skywalking.apm.agent.core.context.ContextManager;
-import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
-import org.apache.skywalking.apm.toolkit.activation.util.TagUtil;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
-import org.apache.skywalking.apm.agent.core.util.CustomizeExpression;
-import org.apache.skywalking.apm.toolkit.trace.Tag;
-import org.apache.skywalking.apm.toolkit.trace.Tags;
 
-public class TagAnnotationMethodInterceptor implements InstanceMethodsAroundInterceptor {
+public class TagAnnotationMethodInterceptor extends BaseTagAnnotationInterceptor implements InstanceMethodsAroundInterceptor {
     @Override
     public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
-        final Class<?>[] argumentsTypes, final MethodInterceptResult result) {
-
-        if (!ContextManager.isActive()) {
-            return;
-        }
-
-        final AbstractSpan activeSpan = ContextManager.activeSpan();
-        final Map<String, Object> context = CustomizeExpression.evaluationContext(allArguments);
-
-        final Tags tags = method.getAnnotation(Tags.class);
-        if (tags != null && tags.value().length > 0) {
-            for (final Tag tag : tags.value()) {
-                if (!TagUtil.isReturnTag(tag.value())) {
-                    TagUtil.tagParamsSpan(activeSpan, context, tag);
-                }
-            }
-        }
-
-        final Tag tag = method.getAnnotation(Tag.class);
-        if (tag != null && !TagUtil.isReturnTag(tag.value())) {
-            TagUtil.tagParamsSpan(activeSpan, context, tag);
-        }
+                             final Class<?>[] argumentsTypes, final MethodInterceptResult result) {
+        super.beforeMethod(method, allArguments);
     }
 
     @Override
     public Object afterMethod(
-        final EnhancedInstance objInst,
-        final Method method,
-        final Object[] allArguments,
-        final Class<?>[] argumentsTypes,
-        final Object ret) {
-        if (ret == null || !ContextManager.isActive()) {
-            return ret;
-        }
-        final AbstractSpan localSpan = ContextManager.activeSpan();
-        final Map<String, Object> context = CustomizeExpression.evaluationReturnContext(ret);
-        final Tags tags = method.getAnnotation(Tags.class);
-        if (tags != null && tags.value().length > 0) {
-            for (final Tag tag : tags.value()) {
-                if (TagUtil.isReturnTag(tag.value())) {
-                    TagUtil.tagReturnSpanSpan(localSpan, context, tag);
-                }
-            }
-        }
-        final Tag tag = method.getAnnotation(Tag.class);
-        if (tag != null && TagUtil.isReturnTag(tag.value())) {
-            TagUtil.tagReturnSpanSpan(localSpan, context, tag);
-        }
+            final EnhancedInstance objInst,
+            final Method method,
+            final Object[] allArguments,
+            final Class<?>[] argumentsTypes,
+            final Object ret) {
+        super.afterMethod(method, ret);
         return ret;
     }
 
     @Override
     public void handleMethodException(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
-        final Class<?>[] argumentsTypes, final Throwable t) {
-        if (ContextManager.isActive()) {
-            ContextManager.activeSpan().log(t);
-        }
+                                      final Class<?>[] argumentsTypes, final Throwable t) {
+        super.handleMethodException(t);
     }
 }
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationStaticMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationStaticMethodInterceptor.java
new file mode 100644
index 0000000..9764067
--- /dev/null
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TagAnnotationStaticMethodInterceptor.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.toolkit.activation.trace;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
+
+import java.lang.reflect.Method;
+
+public class TagAnnotationStaticMethodInterceptor extends BaseTagAnnotationInterceptor implements StaticMethodsAroundInterceptor {
+    @Override
+    public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
+                             MethodInterceptResult result) {
+        super.beforeMethod(method, allArguments);
+    }
+
+    @Override
+    public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
+                              Object ret) {
+        super.afterMethod(method, ret);
+        return ret;
+    }
+
+    @Override
+    public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
+                                      Throwable t) {
+        super.handleMethodException(t);
+    }
+}
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java
index fa70702..dc426c5 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationActivation.java
@@ -22,7 +22,8 @@ import net.bytebuddy.description.method.MethodDescription;
 import net.bytebuddy.matcher.ElementMatcher;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.DeclaredInstanceMethodsInterceptPoint;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine;
 import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
 import org.apache.skywalking.apm.agent.core.plugin.match.MethodAnnotationMatch;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
@@ -34,9 +35,10 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
  * {@link TraceAnnotationActivation} enhance all method that annotated with <code>org.apache.skywalking.apm.toolkit.trace.annotation.Trace</code>
  * by <code>TraceAnnotationMethodInterceptor</code>.
  */
-public class TraceAnnotationActivation extends ClassInstanceMethodsEnhancePluginDefine {
+public class TraceAnnotationActivation extends ClassEnhancePluginDefine {
 
     public static final String TRACE_ANNOTATION_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.toolkit.activation.trace.TraceAnnotationMethodInterceptor";
+    public static final String TRACE_ANNOTATION_STATIC_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.toolkit.activation.trace.TraceAnnotationStaticMethodInterceptor";
     public static final String TRACE_ANNOTATION = "org.apache.skywalking.apm.toolkit.trace.Trace";
 
     @Override
@@ -67,6 +69,28 @@ public class TraceAnnotationActivation extends ClassInstanceMethodsEnhancePlugin
     }
 
     @Override
+    public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
+        return new StaticMethodsInterceptPoint[]{
+                new StaticMethodsInterceptPoint() {
+                    @Override
+                    public ElementMatcher<MethodDescription> getMethodsMatcher() {
+                        return isAnnotatedWith(named(TRACE_ANNOTATION));
+                    }
+
+                    @Override
+                    public String getMethodsInterceptor() {
+                        return TRACE_ANNOTATION_STATIC_METHOD_INTERCEPTOR;
+                    }
+
+                    @Override
+                    public boolean isOverrideArgs() {
+                        return false;
+                    }
+                }
+        };
+    }
+
+    @Override
     protected ClassMatch enhanceClass() {
         return MethodAnnotationMatch.byMethodAnnotationMatch(TRACE_ANNOTATION);
     }
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java
index e11a1f7..ffc51f4 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java
@@ -19,83 +19,33 @@
 package org.apache.skywalking.apm.toolkit.activation.trace;
 
 import java.lang.reflect.Method;
-import java.util.Map;
-import org.apache.skywalking.apm.agent.core.context.ContextManager;
-import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
+
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
-import org.apache.skywalking.apm.agent.core.util.CustomizeExpression;
-import org.apache.skywalking.apm.agent.core.util.MethodUtil;
-import org.apache.skywalking.apm.toolkit.activation.ToolkitPluginConfig;
-import org.apache.skywalking.apm.toolkit.activation.util.TagUtil;
-import org.apache.skywalking.apm.toolkit.trace.Tag;
-import org.apache.skywalking.apm.toolkit.trace.Tags;
-import org.apache.skywalking.apm.toolkit.trace.Trace;
 
 /**
  * {@link TraceAnnotationMethodInterceptor} create a local span and set the operation name which fetch from
  * <code>org.apache.skywalking.apm.toolkit.trace.annotation.Trace.operationName</code>. if the fetch value is blank
  * string, and the operation name will be the method name.
  */
-public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundInterceptor {
+public class TraceAnnotationMethodInterceptor extends BaseTraceAnnotationInterceptor implements InstanceMethodsAroundInterceptor {
     @Override
     public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                              MethodInterceptResult result) throws Throwable {
-        Trace trace = method.getAnnotation(Trace.class);
-        String operationName = trace.operationName();
-        if (operationName.length() == 0 || ToolkitPluginConfig.Plugin.Toolkit.USE_QUALIFIED_NAME_AS_OPERATION_NAME) {
-            operationName = MethodUtil.generateOperationName(method);
-        }
-
-        final AbstractSpan localSpan = ContextManager.createLocalSpan(operationName);
-
-        final Map<String, Object> context = CustomizeExpression.evaluationContext(allArguments);
-
-        final Tags tags = method.getAnnotation(Tags.class);
-        if (tags != null && tags.value().length > 0) {
-            for (final Tag tag : tags.value()) {
-                if (!TagUtil.isReturnTag(tag.value())) {
-                    TagUtil.tagParamsSpan(localSpan, context, tag);
-                }
-            }
-        }
-        final Tag tag = method.getAnnotation(Tag.class);
-        if (tag != null && !TagUtil.isReturnTag(tag.value())) {
-            TagUtil.tagParamsSpan(localSpan, context, tag);
-        }
+        super.beforeMethod(method, allArguments);
     }
 
     @Override
     public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                               Object ret) throws Throwable {
-        try {
-            if (ret == null) {
-                return ret;
-            }
-            final AbstractSpan localSpan = ContextManager.activeSpan();
-            final Map<String, Object> context = CustomizeExpression.evaluationReturnContext(ret);
-            final Tags tags = method.getAnnotation(Tags.class);
-            if (tags != null && tags.value().length > 0) {
-                for (final Tag tag : tags.value()) {
-                    if (TagUtil.isReturnTag(tag.value())) {
-                        TagUtil.tagReturnSpanSpan(localSpan, context, tag);
-                    }
-                }
-            }
-            final Tag tag = method.getAnnotation(Tag.class);
-            if (tag != null && TagUtil.isReturnTag(tag.value())) {
-                TagUtil.tagReturnSpanSpan(localSpan, context, tag);
-            }
-        } finally {
-            ContextManager.stopSpan();
-        }
+        super.afterMethod(method, ret);
         return ret;
     }
 
     @Override
     public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
                                       Class<?>[] argumentsTypes, Throwable t) {
-        ContextManager.activeSpan().log(t);
+        super.handleMethodException(t);
     }
 }
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationStaticMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationStaticMethodInterceptor.java
new file mode 100644
index 0000000..f08c61b
--- /dev/null
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationStaticMethodInterceptor.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.apm.toolkit.activation.trace;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
+
+import java.lang.reflect.Method;
+
+public class TraceAnnotationStaticMethodInterceptor extends BaseTraceAnnotationInterceptor implements StaticMethodsAroundInterceptor {
+    @Override
+    public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
+                             MethodInterceptResult result) {
+        super.beforeMethod(method, allArguments);
+    }
+
+    @Override
+    public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
+                              Object ret) {
+        super.afterMethod(method, ret);
+        return ret;
+    }
+
+    @Override
+    public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
+                                      Throwable t) {
+        super.handleMethodException(t);
+    }
+}
diff --git a/test/plugin/scenarios/apm-toolkit-trace-scenario/config/expectedData.yaml b/test/plugin/scenarios/apm-toolkit-trace-scenario/config/expectedData.yaml
index 2bcc1cd..fc5dfe1 100644
--- a/test/plugin/scenarios/apm-toolkit-trace-scenario/config/expectedData.yaml
+++ b/test/plugin/scenarios/apm-toolkit-trace-scenario/config/expectedData.yaml
@@ -130,6 +130,21 @@ segmentItems:
       tags:
       - {key: username, value: zhangsan}
       skipAnalysis: 'true'
+    - operationName: test.apache.skywalking.apm.testcase.toolkit.controller.TestService.testStatic(java.lang.String,java.lang.Integer)
+      parentSpanId: 0
+      spanId: 10
+      spanLayer: Unknown
+      startTime: nq 0
+      endTime: nq 0
+      componentId: 0
+      isError: false
+      spanType: Local
+      peer: ''
+      tags:
+      - {key: p1, value: lisi}
+      - {key: p2, value: '16'}
+      - {key: username, value: lisi}
+      skipAnalysis: 'true'
     - operationName: /case/tool-kit
       parentSpanId: -1
       spanId: 0
diff --git a/test/plugin/scenarios/apm-toolkit-trace-scenario/src/main/java/test/apache/skywalking/apm/testcase/toolkit/controller/TestController.java b/test/plugin/scenarios/apm-toolkit-trace-scenario/src/main/java/test/apache/skywalking/apm/testcase/toolkit/controller/TestController.java
index 1755eea..8f3d221 100644
--- a/test/plugin/scenarios/apm-toolkit-trace-scenario/src/main/java/test/apache/skywalking/apm/testcase/toolkit/controller/TestController.java
+++ b/test/plugin/scenarios/apm-toolkit-trace-scenario/src/main/java/test/apache/skywalking/apm/testcase/toolkit/controller/TestController.java
@@ -58,6 +58,7 @@ public class TestController {
         testService.testErrorThrowable();
         testService.testTagAnnotation("testTagAnnotationParam1", "testTagAnnotationParam2");
         testService.testTagAnnotationReturnInfo("zhangsan", 15);
+        TestService.testStatic("lisi", 16);
         TraceContext.putCorrelation(CORRELATION_CONTEXT_KEY, CORRELATION_CONTEXT_VALUE);
         ActiveSpan.tag("traceID", TraceContext.traceId());
         ActiveSpan.tag("segmentID", TraceContext.segmentId());
diff --git a/test/plugin/scenarios/apm-toolkit-trace-scenario/src/main/java/test/apache/skywalking/apm/testcase/toolkit/controller/TestService.java b/test/plugin/scenarios/apm-toolkit-trace-scenario/src/main/java/test/apache/skywalking/apm/testcase/toolkit/controller/TestService.java
index f37ac97..ac21326 100644
--- a/test/plugin/scenarios/apm-toolkit-trace-scenario/src/main/java/test/apache/skywalking/apm/testcase/toolkit/controller/TestService.java
+++ b/test/plugin/scenarios/apm-toolkit-trace-scenario/src/main/java/test/apache/skywalking/apm/testcase/toolkit/controller/TestService.java
@@ -42,6 +42,14 @@ public class TestService {
     });
 
     @Trace
+    @Tag(key = "p1", value = "arg[0]")
+    @Tag(key = "p2", value = "arg[1]")
+    @Tag(key = "username", value = "returnedObj.username")
+    public static User testStatic(final String username, final Integer age) {
+        return new User(username, age);
+    }
+
+    @Trace
     public void testTag() {
         ActiveSpan.tag("key", "value");
     }