vinodkumar21 commented on issue #2709: Http JDK plugin
URL: https://github.com/apache/skywalking/issues/2709#issuecomment-493444052
 
 
   I developed same using custom plugin but its not working.below is my 
code,can you where i am wrong.
   
   /*
    * 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.feign.http.v9.define;
   
   
   import 
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
   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.match.ClassMatch;
   import 
org.apache.skywalking.apm.dependencies.net.bytebuddy.description.method.MethodDescription;
   import 
org.apache.skywalking.apm.dependencies.net.bytebuddy.matcher.ElementMatcher;
   import 
org.apache.skywalking.apm.dependencies.net.bytebuddy.matcher.ElementMatchers;
   import 
org.apache.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor;
   
   
   import static 
org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
   
   /**
    * {@link DefaultHttpClientInstrumentation} presents that skywalking 
intercepts {@link
    * feign.Client.Default#execute(feign.Request, feign.Request.Options)} by 
using {@link DefaultHttpClientInterceptor}.
    * If feign did't run in default mode, the instrumentation depend on the 
http discovery implementation.
    * e.g. okhttp discovery implementation depend on okhttp-plugin.
    *
    * @author peng-yongsheng
    */
   public class DefaultHttpClientInstrumentation extends 
ClassInstanceMethodsEnhancePluginDefine {
   
       /**
        * Enhance class.
        */
       private static final String ENHANCE_CLASS = 
"sun.net.www.protocol.http.HttpURLConnection";
   
       /**
        * Intercept class.
        */
       private static final String INTERCEPT_CLASS = 
"org.apache.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor";
   
       @Override protected ClassMatch enhanceClass()
       {
         Log.getDebugLogs("http  method"+ENHANCE_CLASS);
         System.out.println("http  method"+ENHANCE_CLASS);
           return byName(ENHANCE_CLASS);
       }
   
       @Override protected ConstructorInterceptPoint[] 
getConstructorsInterceptPoints() {
           return new ConstructorInterceptPoint[0];
       }
   
       @Override protected InstanceMethodsInterceptPoint[] 
getInstanceMethodsInterceptPoints() {
           return new InstanceMethodsInterceptPoint[] {
               new InstanceMethodsInterceptPoint() {
                   @Override public ElementMatcher<MethodDescription> 
getMethodsMatcher() 
                   {
                         Log.getDebugLogs("execute  method"+ENHANCE_CLASS);
                         
System.out.println(".........................................execute  
method"+ENHANCE_CLASS);  
                       return ElementMatchers.named("connect");
                   }
   
                   @Override public String getMethodsInterceptor() {
                       return INTERCEPT_CLASS;
                   }
   
                   @Override public boolean isOverrideArgs() {
                       return false;
                   }
               }
           };
       }
   }
   
   package org.apache.skywalking.apm.plugin.feign.http.v9;
   
   
   
   import java.lang.reflect.Method;
   import java.net.HttpURLConnection;
   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;
   import org.apache.skywalking.apm.plugin.feign.http.v9.define.Log;
   public class DefaultHttpClientInterceptor
     implements InstanceMethodsAroundInterceptor
   {
     private static final String COMPONENT_NAME = "FeignDefaultHttp";
     @Override
     public void beforeMethod(EnhancedInstance objInst, Method method, Object[] 
allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result)
       throws Throwable
     {
         
          System.out.println("------------------before");
        
        /*HttpURLConnection request = (HttpURLConnection)allArguments[0];
       
       URL url = request.getURL();
       ContextCarrier contextCarrier = new ContextCarrier();
       int port = url.getPort() == -1 ? 80 : url.getPort();
       String remotePeer = url.getHost() + ":" + port;
       String operationName = url.getPath();
       if ((operationName == null) || (operationName.length() == 0)) {
         operationName = "/";
       }
       AbstractSpan span = ContextManager.createExitSpan(operationName, 
contextCarrier, remotePeer);
       span.setComponent(ComponentsDefine.FEIGN);
       Tags.HTTP.METHOD.set(span, request.getRequestMethod());
       Tags.URL.set(span, url.toString());
       SpanLayer.asHttp(span);*/
       
       /*Field headersField = Request.class.getDeclaredField("headers");*/
       /*Field modifiersField = Field.class.getDeclaredField("modifiers");
       modifiersField.setAccessible(true);
       modifiersField.setInt(headersField, headersField.getModifiers() & 
0xFFFFFFEF);*/
       
    //   headersField.setAccessible(true);
       /*Map<String, Collection<String>> headers = new LinkedHashMap();*/
       /*CarrierItem next = contextCarrier.items();
       while (next.hasNext())
       {
        next = next.next();
        request.setRequestProperty(next.getHeadKey(), next.getHeadValue());
       }*/
       
     }
     @Override
     public Object afterMethod(EnhancedInstance objInst, Method method, 
Object[] allArguments, Class<?>[] argumentsTypes, Object ret)
       throws Throwable
     {
          Log.getDebugLogs("-------------------------------------------after 
http defaul method"+allArguments[0]);
         /* HttpURLConnection  response = (HttpURLConnection)ret;
       if (response != null)
       {
         int statusCode = response.getResponseCode();
         
         AbstractSpan span = ContextManager.activeSpan();
         if (statusCode >= 400)
         {
           span.errorOccurred();
           Tags.STATUS_CODE.set(span, statusCode + "");
         }
       }
       ContextManager.stopSpan();*/
       
       return null;
     }
     
     public void handleMethodException(EnhancedInstance objInst, Method method, 
Object[] allArguments, Class<?>[] argumentsTypes, Throwable t)
     {
          Log.getDebugLogs("in errror debuger");
          t.printStackTrace();
       AbstractSpan activeSpan = ContextManager.activeSpan();
       activeSpan.log(t);
       activeSpan.errorOccurred();
     }
   }
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to