提交 e8456c0f 编写于 作者: X Xin,Zhang 提交者: wu-sheng

Fix operation name is empty issue (#1525)

上级 676e4ee9
...@@ -19,12 +19,21 @@ ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 : "/";
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册