wu-sheng commented on a change in pull request #73: URL: https://github.com/apache/skywalking-java/pull/73#discussion_r766300784
########## File path: apm-sniffer/apm-sdk-plugin/dubbo-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/asf/dubbo3/DubboInterceptor.java ########## @@ -0,0 +1,211 @@ +/* + * 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.plugin.asf.dubbo3; + +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.rpc.RpcContextAttachment; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.RpcServiceContext; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +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.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.util.StringUtil; + +import java.lang.reflect.Method; + +/** + * {@link DubboInterceptor} define how to enhance class {@link org.apache.dubbo.monitor.support.MonitorFilter#invoke(Invoker, + * Invocation)}. the trace context transport to the provider side by {@link RpcContext#getServerAttachment}.but all the version + * of dubbo framework below 3.0.0 don't support {@link RpcContext#getClientAttachment}, we support another way to support it. + */ +public class DubboInterceptor implements InstanceMethodsAroundInterceptor { + + public static final String ARGUMENTS = "arguments"; + + /** + * <h2>Consumer:</h2> The serialized trace context data will + * inject to the {@link RpcContext#getClientAttachment} for transport to provider side. + * <p> + * <h2>Provider:</h2> The serialized trace context data will extract from + * {@link RpcContext#getServerAttachment}. current trace segment will ref if the serialize context data is not null. + */ + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Invoker invoker = (Invoker) allArguments[0]; + Invocation invocation = (Invocation) allArguments[1]; + + RpcServiceContext serviceContext = RpcContext.getServiceContext(); + boolean isConsumer; + URL url = serviceContext.getUrl(); + if (url == null) { + url = serviceContext.getConsumerUrl(); + isConsumer = url != null; + } else { + isConsumer = serviceContext.isConsumerSide(); + } Review comment: Then please fix the format(unexpected code changes), I am good. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
