You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ta...@apache.org on 2020/04/26 04:50:57 UTC

[skywalking] branch active_span_enhan created (now 6405272)

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

tanjian pushed a change to branch active_span_enhan
in repository https://gitbox.apache.org/repos/asf/skywalking.git.


      at 6405272  add md.

This branch includes the following new commits:

     new 6a399aa  support user to customize an endpoint with toolkit.
     new 6ce5bde  fix code style.
     new 6405272  add md.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking] 01/03: support user to customize an endpoint with toolkit.

Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6a399aa8cb3a4c482dc8688cbb6b3d542c9cd562
Author: JaredTan95 <ji...@daocloud.io>
AuthorDate: Sun Apr 26 11:25:11 2020 +0800

    support user to customize an endpoint with toolkit.
---
 .../skywalking/apm/toolkit/trace/ActiveSpan.java   |  3 ++
 .../activation/trace/ActiveSpanActivation.java     | 19 +++++++
 .../ActiveSpanSetOperationNameInterceptor.java     | 58 ++++++++++++++++++++++
 3 files changed, 80 insertions(+)

diff --git a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java
index 2878905..5281a21 100644
--- a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java
+++ b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java
@@ -43,4 +43,7 @@ public class ActiveSpan {
 
     public static void info(String infoMsg) {
     }
+
+    public static void setOperationName(String operationName){
+    }
 }
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanActivation.java
index 9303969..fa795f5 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanActivation.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanActivation.java
@@ -52,6 +52,9 @@ public class ActiveSpanActivation extends ClassStaticMethodsEnhancePluginDefine
     private static final String INFO_INTERCEPTOR_METHOD_NAME = "info";
     private static final String INFO_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.toolkit.activation.trace.ActiveSpanInfoInterceptor";
 
+    private static final String SET_OPERATION_NAME_METHOD_NAME = "setOperationName";
+    private static final String SET_OPERATION_NAME_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.toolkit.activation.trace.ActiveSpanSetOperationNameInterceptor";
+
     @Override
     public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
         return new ConstructorInterceptPoint[0];
@@ -155,6 +158,22 @@ public class ActiveSpanActivation extends ClassStaticMethodsEnhancePluginDefine
                 public boolean isOverrideArgs() {
                     return false;
                 }
+            },
+            new StaticMethodsInterceptPoint() {
+                @Override
+                public ElementMatcher<MethodDescription> getMethodsMatcher() {
+                    return named(SET_OPERATION_NAME_METHOD_NAME).and(takesArguments(0));
+                }
+
+                @Override
+                public String getMethodsInterceptor() {
+                    return SET_OPERATION_NAME_INTERCEPTOR_CLASS;
+                }
+
+                @Override
+                public boolean isOverrideArgs() {
+                    return false;
+                }
             }
         };
     }
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanSetOperationNameInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanSetOperationNameInterceptor.java
new file mode 100644
index 0000000..b4293f4
--- /dev/null
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanSetOperationNameInterceptor.java
@@ -0,0 +1,58 @@
+/*
+ * 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 java.lang.reflect.Method;
+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.MethodInterceptResult;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
+
+public class ActiveSpanSetOperationNameInterceptor implements StaticMethodsAroundInterceptor {
+    @Override
+    public void beforeMethod(final Class clazz,
+                             final Method method,
+                             final Object[] allArguments,
+                             final Class<?>[] parameterTypes,
+                             final MethodInterceptResult result) {
+        try {
+            AbstractSpan activeSpan = ContextManager.activeSpan();
+            activeSpan.setOperationName(String.valueOf(allArguments[0]));
+        } catch (NullPointerException ignored) {
+        }
+    }
+
+    @Override
+    public Object afterMethod(final Class clazz,
+                              final Method method,
+                              final Object[] allArguments,
+                              final Class<?>[] parameterTypes,
+                              final Object ret) {
+        return null;
+    }
+
+    @Override
+    public void handleMethodException(final Class clazz,
+                                      final Method method,
+                                      final Object[] allArguments,
+                                      final Class<?>[] parameterTypes,
+                                      final Throwable t) {
+
+    }
+}


[skywalking] 02/03: fix code style.

Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6ce5bde9de7b1c2a8eef0bc1693634703c8a63cf
Author: JaredTan95 <ji...@daocloud.io>
AuthorDate: Sun Apr 26 11:30:43 2020 +0800

    fix code style.
---
 .../main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java
index 5281a21..6954a40 100644
--- a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java
+++ b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/ActiveSpan.java
@@ -44,6 +44,6 @@ public class ActiveSpan {
     public static void info(String infoMsg) {
     }
 
-    public static void setOperationName(String operationName){
+    public static void setOperationName(String operationName) {
     }
 }


[skywalking] 03/03: add md.

Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6405272b0808163105a8f953bdc6d6d2d07f4066
Author: JaredTan95 <ji...@daocloud.io>
AuthorDate: Sun Apr 26 12:50:24 2020 +0800

    add md.
---
 .../apm/toolkit/activation/trace/ActiveSpanActivation.java          | 6 +++---
 docs/en/setup/service-agent/java-agent/Application-toolkit-trace.md | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanActivation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanActivation.java
index fa795f5..b4f9b1e 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanActivation.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/ActiveSpanActivation.java
@@ -20,11 +20,11 @@ package org.apache.skywalking.apm.toolkit.activation.trace;
 
 import net.bytebuddy.description.method.MethodDescription;
 import net.bytebuddy.matcher.ElementMatcher;
-import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine;
-import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassStaticMethodsEnhancePluginDefine;
 import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
 
 import static net.bytebuddy.matcher.ElementMatchers.named;
 import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
@@ -162,7 +162,7 @@ public class ActiveSpanActivation extends ClassStaticMethodsEnhancePluginDefine
             new StaticMethodsInterceptPoint() {
                 @Override
                 public ElementMatcher<MethodDescription> getMethodsMatcher() {
-                    return named(SET_OPERATION_NAME_METHOD_NAME).and(takesArguments(0));
+                    return named(SET_OPERATION_NAME_METHOD_NAME).and(takesArgumentWithType(0, "java.lang.String"));
                 }
 
                 @Override
diff --git a/docs/en/setup/service-agent/java-agent/Application-toolkit-trace.md b/docs/en/setup/service-agent/java-agent/Application-toolkit-trace.md
index 3586367..3f28662 100644
--- a/docs/en/setup/service-agent/java-agent/Application-toolkit-trace.md
+++ b/docs/en/setup/service-agent/java-agent/Application-toolkit-trace.md
@@ -27,6 +27,7 @@ The `value` of `Tag` is the same as what are supported in [Customize Enhance Tra
 * `ActiveSpan.error(Throwable throwable)` Mark the current span as error status with a Throwable.
 * `ActiveSpan.debug(String debugMsg)` Add a debug level log message in the current span.
 * `ActiveSpan.info(String infoMsg)` Add an info level log message in the current span.
+* `ActiveSpan.setOperationName(String operationName)` Customize an operation name. 
 
 ```java
 ActiveSpan.tag("my_tag", "my_value");
@@ -49,6 +50,7 @@ ActiveSpan.debug("Test-debug-Msg");
 @Tag(key = "username", value = "returnedObj.username")
 @Tag(key = "age", value = "returnedObj.age")
 public User methodYouWantToTrace(String param1, String param2) {
+    // ActiveSpan.setOperationName("Customize your own methodYouWantToTrace");
     // ...
 }
 ```