wu-sheng closed pull request #1218: Fix http_client plugin URL: https://github.com/apache/incubator-skywalking/pull/1218
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java index 9469385a6..3688e390d 100644 --- a/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/httpClient/v4/HttpClientExecuteInterceptor.java @@ -18,9 +18,6 @@ package org.apache.skywalking.apm.plugin.httpClient.v4; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; @@ -36,6 +33,9 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import java.lang.reflect.Method; +import java.net.URL; + public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, @@ -47,20 +47,16 @@ final HttpHost httpHost = (HttpHost)allArguments[0]; HttpRequest httpRequest = (HttpRequest)allArguments[1]; final ContextCarrier contextCarrier = new ContextCarrier(); - AbstractSpan span = null; String remotePeer = httpHost.getHostName() + ":" + (httpHost.getPort() > 0 ? httpHost.getPort() : "https".equals(httpHost.getSchemeName().toLowerCase()) ? 443 : 80); - try { - URL url = new URL(httpRequest.getRequestLine().getUri()); - span = ContextManager.createExitSpan(url.getPath(), contextCarrier, remotePeer); - } catch (MalformedURLException e) { - throw e; - } + String uri = httpRequest.getRequestLine().getUri(); + String operationName = uri.startsWith("http") ? new URL(uri).getPath() : uri; + AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, remotePeer); span.setComponent(ComponentsDefine.HTTPCLIENT); - Tags.URL.set(span, httpRequest.getRequestLine().getUri()); + Tags.URL.set(span, uri); Tags.HTTP.METHOD.set(span, httpRequest.getRequestLine().getMethod()); SpanLayer.asHttp(span); ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services