You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2019/05/15 02:50:20 UTC

[GitHub] [skywalking] IanCao commented on a change in pull request #2644: Support Hessian 4.0.x.

IanCao commented on a change in pull request #2644: Support Hessian 4.0.x.
URL: https://github.com/apache/skywalking/pull/2644#discussion_r284069767
 
 

 ##########
 File path: apm-sniffer/apm-sdk-plugin/hessian-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hessian/v4/HessianAddHeaderInterceptor.java
 ##########
 @@ -0,0 +1,91 @@
+/*
+ * 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.hessian.v4;
+
+import com.caucho.hessian.client.HessianURLConnection;
+import java.lang.reflect.Method;
+import java.net.URL;
+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;
+
+/**
+ * intercept method {@link HessianURLConnection#addHeader}.
+ *
+ * @author Alan Lau
+ */
+public class HessianAddHeaderInterceptor implements InstanceMethodsAroundInterceptor {
+
+    @Override
+    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+        MethodInterceptResult result) throws Throwable {
+        URL url = (URL)objInst.getSkyWalkingDynamicField();
+        if (url == null) {
+            return;
+        }
+
+        if (allArguments.length < 0) {
+            return;
+        }
+
+        HessianURLConnection conn = conn = (HessianURLConnection)allArguments[0];
+
+        String operateName = url.getPath();
+        final ContextCarrier contextCarrier = new ContextCarrier();
+        AbstractSpan span = ContextManager.createExitSpan(operateName, contextCarrier, String.format(":", url.getHost(), url.getPort()));
+
+        span.setComponent(ComponentsDefine.HESSIAN);
+        span.start(System.currentTimeMillis());
+        span.setOperationName(url.getPath());
+
+        Tags.URL.set(span, url.getPath());
+        SpanLayer.asRPCFramework(span);
+
+        CarrierItem next = contextCarrier.items();
+        while (next.hasNext()) {
+            next = next.next();
+            conn.addHeader(next.getHeadKey(), next.getHeadValue());
+        }
+    }
+
+    @Override
+    public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+        Object ret) throws Throwable {
+        ContextManager.stopSpan();
 
 Review comment:
   The ExitSpan isn't been created all the time, but stopspan is always.
   Here maybe some logical problems

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services