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 <jian....@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) { + + } +}