Fix operation name is empty issue (#1525)
This commit is contained in:
parent
676e4ee930
commit
e8456c0f83
|
|
@ -19,12 +19,21 @@
|
||||||
package org.apache.skywalking.apm.plugin.httpClient.v4;
|
package org.apache.skywalking.apm.plugin.httpClient.v4;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import org.apache.http.*;
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.skywalking.apm.agent.core.context.*;
|
import org.apache.http.HttpRequest;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.StatusLine;
|
||||||
|
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.tag.Tags;
|
||||||
import org.apache.skywalking.apm.agent.core.context.trace.*;
|
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
|
||||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.*;
|
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.network.trace.component.ComponentsDefine;
|
||||||
|
|
||||||
public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterceptor {
|
public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterceptor {
|
||||||
|
|
@ -43,7 +52,8 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
|
||||||
"https".equals(httpHost.getSchemeName().toLowerCase()) ? 443 : 80);
|
"https".equals(httpHost.getSchemeName().toLowerCase()) ? 443 : 80);
|
||||||
|
|
||||||
String uri = httpRequest.getRequestLine().getUri();
|
String uri = httpRequest.getRequestLine().getUri();
|
||||||
String operationName = uri.startsWith("http") ? new URL(uri).getPath() : uri;
|
String requestURI = getRequestURI(uri);
|
||||||
|
String operationName = uri.startsWith("http") ? requestURI : uri;
|
||||||
AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, remotePeer);
|
AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, remotePeer);
|
||||||
|
|
||||||
span.setComponent(ComponentsDefine.HTTPCLIENT);
|
span.setComponent(ComponentsDefine.HTTPCLIENT);
|
||||||
|
|
@ -76,7 +86,7 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextManager.stopSpan();
|
ContextManager.stopSpan();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -87,4 +97,9 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc
|
||||||
activeSpan.errorOccurred();
|
activeSpan.errorOccurred();
|
||||||
activeSpan.log(t);
|
activeSpan.log(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getRequestURI(String uri) throws MalformedURLException {
|
||||||
|
String requestPath = new URL(uri).getPath();
|
||||||
|
return requestPath != null && requestPath.length() > 0 ? requestPath : "/";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue